Skip to content

Commit db20058

Browse files
committed
Merge pull request #110 from huangpf/clu
Clu
2 parents c6b9546 + 44b46cb commit db20058

File tree

643 files changed

+8914
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

643 files changed

+8914
-456
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
drop/clurun/osx.10.10-x64
3+
drop/clurun/win7-x64
4+
drop/CommandRepo
5+
setup/*
6+
src/artifacts
7+
src/Common
8+
src/ResourceManager
9+
src/ServiceManagement

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM graemef/docker-ubuntu-mono
2+
3+
ENV DNX_VERSION 1.0.0-rc1-final
4+
ENV DNX_USER_HOME /opt/dnx
5+
6+
# Install DNX prerequisites
7+
RUN apt-get update && \
8+
apt-get -qqy install \
9+
libunwind8 \
10+
gettext \
11+
libssl-dev \
12+
libcurl4-gnutls-dev \
13+
zlib1g \
14+
libicu-dev \
15+
uuid-dev \
16+
curl \
17+
unzip \
18+
jq
19+
20+
RUN curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_USER_HOME=$DNX_USER_HOME DNX_BRANCH=v$DNX_VERSION sh
21+
22+
RUN bash -c "source $DNX_USER_HOME/dnvm/dnvm.sh \
23+
&& dnvm install $DNX_VERSION -r coreclr -alias default \
24+
&& dnvm alias default | xargs -i ln -s $DNX_USER_HOME/runtimes/{} $DNX_USER_HOME/runtimes/default"
25+
26+
ENV PATH $PATH:$DNX_USER_HOME/runtimes/default/bin
27+
28+
ADD drop/clurun/ubuntu.14.04-x64 ubuntu.14.04-x64
29+
ADD src/CLU test/clu
30+
ADD tools tools
31+
ADD examples examples
32+
33+
WORKDIR /test/clu
34+
35+
RUN bash -c "source $DNX_USER_HOME/dnvm/dnvm.sh \
36+
&& nuget source enable -Name https://www.nuget.org/api/v2/ \
37+
&& dnu restore \
38+
|| dnvm use $DNX_VERSION -r coreclr"
39+
40+
ENV PATH /ubuntu.14.04-x64:$PATH
41+
42+
WORKDIR /test/clu/Commands.Common.ScenarioTest

clu-getstart.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Work on CLU cmdlets
22

3-
### Prerequsites
3+
## Prerequsites
44

55
* Visual Studio 2015 RTM with ASP.NET. For details, check out the [installation doc](http://docs.asp.net/en/latest/getting-started/installing-on-windows.html).
66

77
Note, after done, run `dnvm list` command to check the 'coreclr' runtime is installed with right version of `1.0.0-rc1-final`. If not, run `dnvm install 1.0.0-rc1-final -r coreclr -a x64 -p`. Remember always use `-p` flag, so the selection can persist.
88

99
* Get the latest dotnet from "https://azureclu.blob.core.windows.net/tools/dotnet-win-x64.latest.zip", unzip, then add its bin folder to the PATH
1010

11-
### Project Artifacts
11+
## Project Artifacts
1212

1313
CLUPackages require some additional files to direct generation of indexing, and to provide shortcuts when files are installed. These files can be copied from the Profile project and updated for each package.
1414

@@ -47,7 +47,7 @@ CLUPackages require some additional files to direct generation of indexing, and
4747
}
4848
```
4949

50-
### Package Creation and Testing
50+
## Package Creation and Testing
5151
Two options
5252
1. Run `<repo-root>\tools\CLU\BuildAndInstallClu.bat` which build and generate all cmdlet packages and deploy to under `<repo root>\drop\clurun` folder, with 3 flavors `win7-x64`, `osx.10.10-x64` and `ubuntu.14.04-x64`. When you have a clean environment or just pull from upstream, you should clean temporary bits such as `git clean -xdf`, and run this command.
5353
2. Run `<repo-root>\tools\CLU\BuildCmdlet <package name like Microsoft.Azure.Commands.Profile>` <name like: Microsoft.Azure.Commands.Profile>", this will build and refresh an individual cmdlet package.
@@ -62,7 +62,7 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flav
6262

6363
(All of those are subject to change, contact yugangw or adxsdkdev for any questions)
6464

65-
### Quick introductions on cmdlets
65+
## Quick introductions on cmdlets
6666
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env get` maps to the cmdlet `Get-AzureRmEnvironment`
6767
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `az subscription get –-SubscriptionName “name of subscription"`
6868
* To log in, 3 options
@@ -82,19 +82,19 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flav
8282

8383
```set AzureProfile=1010 ```
8484

85-
### Testing Cmdlets
85+
## Testing Cmdlets
8686

87-
#### Environment setup (Windows)
87+
### Environment setup (Windows)
8888
- Install latest version of [Git for Windows](https://git-scm.com/download/win) that has `bash 4.x` available.
8989
- Install `jq` using chocolatey `choco install jq` (chocolatey can be installed from [here](https://chocolatey.org/)).
9090

91-
#### Test Infrastructure
91+
### Test Infrastructure
9292
Testing will consist of scenario tests and unit tests. Scenario tests should be written in a form of an example and be available in `.ps1` and `.sh` formats.
9393

94-
#### Scenario Tests
94+
### Scenario Tests
9595
- Scenario tests should be saved under `./examples` directory with one directory per package. Each scenario tests should (eventually) consist of both `.ps1` and `.sh` files and should cover "P0" scenarios.
9696

97-
##### Environment Variables for Authentication
97+
#### Environment Variables for Authentication
9898
Please set the environment variables for either Username/Password (no 2FA) or ServicePrincipal authentication:
9999

100100
**Username/Password (without 2-factor auth):**
@@ -114,7 +114,7 @@ Please set the environment variables for either Username/Password (no 2FA) or Se
114114
| tenant | The tenant guid to authenticate against |
115115
| spnSubscription | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
116116

117-
##### XUnit Automation For Bash Scenario Tests
117+
#### XUnit Automation For Bash Scenario Tests
118118
- The ```Commands.Common.ScenarioTest``` project contains classes that enable executing bash scenario tests in Visual Studio, or cross-platform using dnx.
119119

120120
- To implement an xunit bash scenario test you must
@@ -161,24 +161,68 @@ runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
161161
| ExamplesDirectory | The path to the 'examples' directory ($pshome/examples) |
162162
| TestDirectory | The path to the directory where logs will be written |
163163

164-
##### Running Bash Tests using Bash shell
164+
#### Running Tests in Docker
165+
##### Docker Setup
166+
**Option 1 - VirtualBox:**
167+
Install ToolBox from this link - https://docs.docker.com/engine/installation/windows/
168+
169+
**Option 2 - Hyper-V:**
170+
171+
1. Install ToolBox from this link - https://docs.docker.com/engine/installation/windows/ (uninstall VirtualBox afterwards)
172+
2. http://sa.muel.be/2015/run-docker-on-hyper-v-with-docker-machine/
173+
* Increase VHD to 100GB (--hyperv-disk-size 100000)
174+
* List of other switches for create command - https://docs.docker.com/machine/drivers/hyper-v/
175+
176+
##### Workflow
177+
1. Build packages (see [instructions](#package-creation-and-testing))
178+
2. From command line with admin priveleges navigate to azure-powershell root folder and run ```docker build .```
179+
3. Copy image id from the output. For example in the output below the image id is *26f067684da3*:
180+
181+
```
182+
Successfully built 26f067684da3
183+
```
184+
4. Run ```docker run -it [IMAGEID]``` to SSH into the Docker image
185+
5. In the SSH window run:
186+
187+
```bash
188+
export azureUser=<[email protected]>
189+
export password=<your_password>
190+
export userSubscription=<subscription>
191+
export spn=<spn-guid>
192+
export secret=<spn-secret>
193+
export tenant=<spn-tenant>
194+
export spnSubscription=<subscription>
195+
export azureUser=<[email protected]>
196+
export password=<your_password>
197+
dnx test
198+
```
199+
200+
201+
#### Running Bash Tests using Bash shell
165202
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
166203
- To manually run the tests; please set [environment variables](#Environment_Variables_for_Authentication) for authentication as well as update PATH and run `./examples/lib/testrunner.sh`
167204

168205
```bash
169206
export azureUser=<[email protected]>
170207
export password=<your_password>
208+
export userSubscription=<subscription>
209+
export spn=<spn-guid>
210+
export secret=<spn-secret>
211+
export tenant=<spn-tenant>
212+
export spnSubscription=<subscription>
213+
export azureUser=<[email protected]>
214+
export password=<your_password>
171215
export PATH=/<path-to-drop>/clurun/win7-x64/:$PATH
172216
```
173217
- All the parameters to the cmdlets should be passed in as environment variables
174218
- The current test runners will provide a unique resource group name via `$groupName` but may not remove it at the end if the test fails.
175219
- The location for ARM will be provided via variable `$location`.
176220
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.
177221

178-
##### PowerShell Tests
222+
#### PowerShell Tests
179223
TODO: Add section on PowerShell testing
180224

181-
#### Unit Tests
225+
### Unit Tests
182226
TODO: Add section on unit testing
183227

184228

examples/compute-management/02-VirtualMachineCreation.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33
printf "\n=== Managing Virtual Machine Creation in Azure Compute ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create -n "$groupName" --location "$location"
6+
az resource group create -n "$groupName" --location "$location"
77

88
printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
99
az storage account create--resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
@@ -19,7 +19,7 @@ subnetId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Ne
1919

2020
printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnetId='$subnetId'.\n" "$subId"
2121
export MSYS_NO_PATHCONV=1
22-
az networkinterface create--name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
22+
az vnet create--name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
2323
export MSYS_NO_PATHCONV=
2424

2525
nicId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/networkInterfaces/test"
@@ -33,4 +33,4 @@ printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='%s'\r\nvmStr='
3333
az vm create--resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
3434

3535
printf "\n6. Removing resource group: %s.\n" "$groupName"
36-
az resourcemanager group rm -n "$groupName" -f
36+
az resource group rm -n "$groupName" -f

examples/resource-management/01-ResourceGroups.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ set -e
33
printf "\n=== Managing Resource Groups in Azure ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create -n "$groupName" --location "$location"
6+
az resource group create -n "$groupName" --location "$location"
77

88
printf "\n2. Updating the group %s with tags.\n" "$groupName"
9-
az resourcemanager group set -n "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
9+
az resource group set -n "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
1010

1111
printf "\n3. Get information about resource group : %s.\n" "$groupName"
12-
resourceGroupInfo=`az resourcemanager group ls -n $groupName`
12+
resourceGroupInfo=`az resource group ls -n $groupName`
1313

1414
printf "\nValidating resource group name is: %s\n" "$groupName"
1515
[ $(echo $resourceGroupInfo | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
1616

1717
printf "\n4. Listing all resource groups in the subscription.\n"
18-
az resourcemanager group ls
18+
az resource group ls
1919

2020
printf "\n5. Removing resource group: %s.\n" "$groupName"
21-
az resourcemanager group rm -n "$groupName" -f
21+
az resource group rm -n "$groupName" -f

examples/resource-management/02-Resource.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@ set -e
33
printf "\n=== Managing Resources in Azure ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create --name "$groupName" --location "$location"
6+
az resource group create --name "$groupName" --location "$location"
77
destinationGroupName=$groupName"Destination"
88

99
printf "\n2. Registering Resource Provider Namespace.\n"
1010
providerNamespace="Providers.Test"
11-
az resourcemanager resource provider register --ProviderNamespace $providerNamespace --Force
11+
az resource provider register --ProviderNamespace $providerNamespace --Force
1212

1313
printf "\n3. Creating a new Resource: %s.\n" "$resourceName"
1414
resourceType="$providerNamespace/statefulResources"
1515
tags='[{"Name": "testtag", "Value": "testvalue"}]'
1616
properties='{"administratorLogin": "adminuser", "administratorLoginPassword": "P@ssword1"}'
1717
apiversion="2014-04-01"
18-
az resourcemanager resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force
18+
az resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force
1919

2020
printf "\n4. Get information about Resource : %s.\n" "$resourceName"
21-
resourceInfo=$(az resourcemanager resource ls -n $resourceName)
21+
resourceInfo=$(az resource ls -n $resourceName)
2222
printf "\nValidating Resource name is: %s\n" "$resourceName"
2323
[ $(echo $resourceInfo | jq '.Name' --raw-output) == "$resourceName" ]
2424

2525
printf "\n5. Find Resource with name '%s' and type '%s'.\n" "$resourceName" "$resourceType"
26-
foundResource=$(az resourcemanager resource find -n "$resourceName" -t $resourceType)
26+
foundResource=$(az resource find -n "$resourceName" -t $resourceType)
2727
printf "\nValidating Resource name is: %s.\n" "$resourceName"
2828
[ $(echo $foundResource | jq '.Name' --raw-output) == "$resourceName" ]
2929

3030
printf "\n6. Update Resource.\n"
3131
tagsUpdate='[{"Name": "testtagUpdated", "Value": "testvalueUpdated"}]'
32-
az resourcemanager resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f
32+
az resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f
3333

3434
printf "\n7. Move Resource to resource group: %s.\n" "$destinationGroupName"
35-
az resourcemanager group create --name "$destinationGroupName" --location "$location"
35+
az resource group create --name "$destinationGroupName" --location "$location"
3636
resourceId=$(echo $resourceInfo | jq '.ResourceId')
3737
arrayId="[$resourceId]"
38-
az resourcemanager resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f
38+
az resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f
3939

4040
printf "\n8. Removing resource: %s.\n" "$resourceName"
41-
foundResource=$(az resourcemanager resource find -n "$resourceName" -t $resourceType)
41+
foundResource=$(az resource find -n "$resourceName" -t $resourceType)
4242
resourceId=$(echo $foundResource | jq '.ResourceId' --raw-output)
4343
echo $resourceId
4444
export MSYS_NO_PATHCONV=1
45-
az resourcemanager resource rm --Id "$resourceId" -f
45+
az resource rm --Id "$resourceId" -f
4646
export MSYS_NO_PATHCONV=

examples/resource-management/03-Deployments.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ set -e
33
printf "\n=== Provisioning Deployments in Azure ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create --name "$groupName" --location "$location"
6+
az resource group create --name "$groupName" --location "$location"
77

88
printf "\n2. Test template with dynamic parameters\n"
9-
az resourcemanager group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --siteName "$resourceName" --hostingPlanName "$resourceName" --siteLocation "$location" --workerSize "0"
9+
az resource group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --siteName "$resourceName" --hostingPlanName "$resourceName" --siteLocation "$location" --workerSize "0"
1010

1111
printf "\n3. Test template with JSON parameter object\n"
12-
az resourcemanager group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$resourceName\",\"hostingPlanName\":\"$resourceName\",\"siteLocation\":\"$location\",\"workerSize\": 0 }"
12+
az resource group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$resourceName\",\"hostingPlanName\":\"$resourceName\",\"siteLocation\":\"$location\",\"workerSize\": 0 }"
1313

1414
printf "\n4. Provisioning Deployment\n"
15-
deploymentInfo=`az resourcemanager group deployment create --Name "$resourceName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/sampleTemplate.json --TemplateParameterFile $BASEDIR/sampleTemplateParams.json`
15+
deploymentInfo=`az resource group deployment create --Name "$resourceName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/sampleTemplate.json --TemplateParameterFile $BASEDIR/sampleTemplateParams.json`
1616
echo $deploymentInfo

examples/resource-management/04-RoleAssignments.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ set -e
33
printf "\n=== Managing Role Assignments in Azure ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create --name "$groupName" --location "$location"
6+
az resource group create --name "$groupName" --location "$location"
77

88
printf "\n2. Creating a new Role Assignment.\n"
99
export MSYS_NO_PATHCONV=1
10-
users=$(az activedirectory users ls)
10+
users=$(az ad users ls)
1111
userId=$(echo $users | cat | jq '.[0].Id' -s --raw-output)
1212
echo "UserID: $userId"
13-
roleDefinitions=$(az networksecurityrole definition ls)
13+
roleDefinitions=$(az resource role definition ls)
1414
roleDefinitionId=$(echo $roleDefinitions | cat | jq '.[0].Id' -s --raw-output)
1515
echo "RoleDefinitionId: $roleDefinitionId"
1616
subsciptions=$(az subscription ls)
1717
subscriptionId=$(echo $subsciptions | cat | jq '.[0].SubscriptionId' -s --raw-output)
1818
scope="/subscriptions/$subscriptionId/resourceGroups/$groupName"
1919
echo "Scope: $scope"
20-
az networksecurityrole assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefinitionId" --Scope "$scope"
20+
az resource role assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefinitionId" --Scope "$scope"
2121

2222
printf "\n3. Delete last created Role Assignment.\n"
23-
assignments=$(az networksecurityrole assignment ls)
23+
assignments=$(az resource role assignment ls)
2424
assignmentId=$(echo $assignments | cat | jq '.[-1:][0].ObjectId' -s --raw-output)
2525
echo "Deleting assignment: $assignmentId"
26-
az networksecurityrole assignment rm --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
26+
az resource role assignment rm --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
2727
export MSYS_NO_PATHCONV=

examples/resource-management/05-RoleDefinitions.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ set -e
33
printf "\n=== Managing Role Definitions in Azure ===\n"
44

55
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6-
az resourcemanager group create --name "$groupName" --location "$location"
6+
az resource group create --name "$groupName" --location "$location"
77

88
printf "\n2. Creating a new Role Definition.\n"
9-
roleDefinition=$(az networksecurityrole definition create --inputfile $BASEDIR/roleDefinition.json)
9+
roleDefinition=$(az resource role definition create --inputfile $BASEDIR/roleDefinition.json)
1010

1111
printf "\n3. Get information about Role Definitions.\n"
1212
roleDefinitionName=$(echo $roleDefinition | jq '.Name' --raw-output)
13-
az networksecurityrole definition ls -n $roleDefinitionName
13+
az resource role definition ls -n $roleDefinitionName
1414

1515
printf "\n4. Update Role Definition.\n"
1616
export MSYS_NO_PATHCONV=1
1717
updatedRoleDefinition=$(echo $roleDefinition | jq '.Actions |= .+ ["Microsoft.Authorization/*/write"]')
18-
az networksecurityrole definition set --Role "$updatedRoleDefinition"
18+
az resource role definition set --Role "$updatedRoleDefinition"
1919

2020
printf "\n5. Delete Role Definition.\n"
2121
roleDefinitionId=$(echo $roleDefinition | jq '.Id' --raw-output)
22-
az networksecurityrole definition rm --Id $roleDefinitionId --PassThru -f
22+
az resource role definition rm --Id $roleDefinitionId --PassThru -f
2323
export MSYS_NO_PATHCONV=

0 commit comments

Comments
 (0)