Skip to content

Commit c6b9546

Browse files
committed
Merge pull request #107 from huangpf/clu
Clu
2 parents cdf84cb + e43c6d5 commit c6b9546

File tree

615 files changed

+155694
-48618
lines changed

Some content is hidden

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

615 files changed

+155694
-48618
lines changed

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
DependsOnTargets="Build;Test" >
186186
<Exec Command="$(LibraryToolsFolder)\CLU\BuildAndInstallClu.bat" />
187187
<!--do a simple verification-->
188-
<Exec Command="$(LibraryRoot)drop\clurun\win7-x64\azure.bat help" />
188+
<Exec Command="$(LibraryRoot)drop\clurun\win7-x64\az.bat help" />
189189
</Target>
190190

191191
<Target Name="BuildMsBuildTask" DependsOnTargets="RestoreNugetPackages">

clu-getstart.md

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
### Prerequsites
44

5-
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).
5+
* 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

9+
* 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
10+
911
### Project Artifacts
1012

1113
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.
@@ -23,7 +25,7 @@ CLUPackages require some additional files to direct generation of indexing, and
2325
| ------------- |:-------------:|
2426
| CommandAssemblies | File name of cmdlets assembly(ies) |
2527
| NounPrefix | ‘AzureRm’ The part of the cmdlet noun to remove in clu commands|
26-
| NounFirst | if true, the verb comes at the end of the command (e.g. azure resource get)|
28+
| NounFirst | if true, the verb comes at the end of the command (e.g. az resource get)|
2729

2830
* \<modulename\>.nuspec.template, which contains nuspec format metadata about the package – the base temaplate is in tools\clu\Microsoft.Azure.Commands.nuspec.template. Here are the special fields defined in this template:
2931
* %PackageId% - replace with the module name (Microsoft.Azure.Commands.\<rp-name\>)
@@ -50,35 +52,35 @@ CLUPackages require some additional files to direct generation of indexing, and
5052
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.
5153
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.
5254

53-
After #1 above is finished, you can run `drop\clurun\<platform>\azure.bat help` to explore.
55+
After #1 above is finished, you can run `drop\clurun\<platform>\az.bat help` to explore.
5456

5557
To debug, set environment variable of `DebugCLU` to "1". Then on running any command, you will be prompted to attach a debugger.
5658

57-
There is also `<repo-root>\tools\CLU\SetupEnv.bat` which is a windows batch wrapping around the `BuildAndInstallClu.bat`, plus set the `DebugCLU` for you, and add the `drop\clurun\win7-x64\azure.bat` to the PATH environment variable.
59+
There is also `<repo-root>\tools\CLU\SetupEnv.bat` which is a windows batch wrapping around the `BuildAndInstallClu.bat`, plus set the `DebugCLU` for you, and add the `drop\clurun\win7-x64\az.bat` to the PATH environment variable.
5860

59-
To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flavor folder to your target machine, and run the "azure.sh" inside. Make sure set execution permission using `chmod +x azure.sh clurun`
61+
To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flavor folder to your target machine, and run the "az.sh" inside. Make sure set execution permission using `chmod +x az.sh clurun`
6062

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

6365
### Quick introductions on cmdlets
64-
* Run commands using the ‘azure’ prefix, cmdlet nouns, and cmdlet verbs, for example, `azure environment get` maps to the cmdlet `Get-AzureRmEnvironment`
65-
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `azure subscription get –-SubscriptionName “name of subscription"`
66+
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env get` maps to the cmdlet `Get-AzureRmEnvironment`
67+
* 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"`
6668
* To log in, 3 options
67-
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `azure account add`
68-
* login with user and password, this works on org-id w/o 2fa enforced, example: `azure account add --Username [email protected] --Password password1`
69-
* login as service principal. Example: `azure account add --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
69+
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az account add`
70+
* login with user and password, this works on org-id w/o 2fa enforced, example: `az account add --Username [email protected] --Password password1`
71+
* login as service principal. Example: `az account add --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
7072
* Piping between cmdlets should work the same way that Powerhell piping works
71-
```azure subscription get --SubscriptionName | azure context set```
73+
```az subscription get --SubscriptionName | az context set```
7274
* You can capture piped output using redirection to a file - the result will be the json serialization of the output object.
73-
```azure subscription get > subscriptions.json```
74-
* You can use file input tu aparameter using '@' notation:
75-
```azure command --param1 @file1.json```
75+
```az subscription get > subscriptions.json```
76+
* You can use file input to a parameter using '@' notation:
77+
```az command --param1 @file1.json```
7678
Reads input from file1.json and attempts to deserialize the .net object that is the Parameter type for ```param1```
77-
```azure command --param1 @@file1.json```
79+
```az command --param1 @@file1.json```
7880
Does the same thing, but treats the input from ```file1.json``` as if it come from the pipeline, so that multiple objects will result in multiple invocations of ```ProcessRecord()``` for the target cmdlet.
7981
* There are some known issues with the current approach to sessions, which can cause session variables to not be propagated when running cmdlets in a pipeline, to work around this, set the 'CmdletSessionId' environment variable to a numeric value - all cmdlets running from the shell will use that session id, and sessions will work with pipelining
8082

81-
```set CmdletSessionId=1010 ```
83+
```set AzureProfile=1010 ```
8284

8385
### Testing Cmdlets
8486

@@ -92,12 +94,33 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
9294
#### Scenario Tests
9395
- 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.
9496

97+
##### Environment Variables for Authentication
98+
Please set the environment variables for either Username/Password (no 2FA) or ServicePrincipal authentication:
99+
100+
**Username/Password (without 2-factor auth):**
101+
102+
| Field (case sensitive) | Description |
103+
| ------------- |:-------------|
104+
| azureUser | an OrgId user name |
105+
| password | a service principal name |
106+
| userSubscription | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
107+
108+
**Service Principal:**
109+
110+
| Field (case sensitive) | Description |
111+
| ------------- |:-------------|
112+
| spn | The tenant guid to authenticate against |
113+
| secret | the password or application secret to sue for authentication |
114+
| tenant | The tenant guid to authenticate against |
115+
| spnSubscription | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
116+
95117
##### XUnit Automation For Bash Scenario Tests
96118
- The ```Commands.Common.ScenarioTest``` project contains classes that enable executing bash scenario tests in Visual Studio, or cross-platform using dnx.
97119

98120
- To implement an xunit bash scenario test you must
99121
- Add a ```[Collection("SampleCollection")]``` attribute to your test class
100-
- Add a field to your class of type ```ScenarioTestFixture``` and add a constructor that initializes it
122+
- Add a field to your class of type ```ScenarioTestFixture``` and add a constructor that initializes it.
123+
101124
```C#
102125
[Collection("SampleCollection")]
103126
public class SampleTestClass
@@ -116,20 +139,22 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
116139
_fixture.GetRunner("resource-management").RunScript("01-ResourceGroups");
117140
}
118141
```
119-
- Set the environment variable 'TestCredentials' to a connection string providing the credentials to use during test execution. Possible fields include:
120-
121-
| Field (case sensitive) | Description |
122-
| ------------- |:-------------|
123-
| Username | an OrgId user name |
124-
| ServicePrincipal | a service principal name |
125-
| Password | the password or application secret to sue for authentication |
126-
| TenantId | (required for Service authentication) The tenant guid to authenticate against |
127-
| SubscriptionId | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
128-
- The infrastructure automatically generates a resource group name and assigns the value to the bash variable ```"$resourceGroupName"```. If your scripts require additional variables, you can add these to your environment before running tests, or you can generate values using the ScriptRunner (for the tests using that runner).
142+
- Set the [environment variables](#Environment_Variables_for_Authentication) for either Username/Password (no 2FA) or ServicePrincipal authentication
143+
- Update PATH to include location of CLU bin drop.
144+
```bash
145+
export PATH=/<path-to-drop>/clurun/win7-x64/:$PATH
146+
```
147+
- The infrastructure automatically generates the following environment variables:
148+
- `BASEDIR` - directory path where test script is located
149+
- `location` - default "WestUS" location
150+
- `groupName` - randomly generated resource group name (note: the test guarantees that this resource group is deleted at the end of a test run; any other resource groups generated as part of the test run need to be deleted by the test)
151+
- `storageAccountType` - default "Standard_GRS" storage account type
152+
- `storageAccountName` - randomly generated storage account name
153+
- If the script require additional variables, you can add these to your environment before running tests, or you can generate values using the ScriptRunner (for the tests using that runner).
129154
```C#
130-
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
155+
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
131156
```
132-
- Tests can be executed in vs, or by runnign ```dnx test project.json```. If you execute dnx test from the project directory, it will work without modification and a log file for each script will be written to the test results directory ```..\TestResults```. If you execute dnx test from a different directory, you must set the following environment variables to provide the path to the examples directory and where to write log files:
157+
- Tests can be executed in Visual Studio, or by running ```dnx test project.json```. If you execute dnx test from the project directory, it will work without modification and a log file for each script will be written to the test results directory ```..\TestResults```. If you execute dnx test from a different directory, you must set the following environment variables to provide the path to the examples directory and where to write log files:
133158

134159
| Environment Variable | Description |
135160
| ------------- |:-------------|
@@ -138,14 +163,14 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
138163

139164
##### Running Bash Tests using Bash shell
140165
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
141-
- To manually run the tests; please set the following envt. variables for authentication and run `./examples/lib/testrunner.sh`
166+
- 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`
167+
142168
```bash
143-
export azureuser=<[email protected]>
144-
export azurepassword=<your_password>
145-
export PATH=$PATH:/<path-to-drop>/clurun/win7-x64/
146-
. /examples/lib/testrunner.sh
169+
export azureUser=<[email protected]>
170+
export password=<your_password>
171+
export PATH=/<path-to-drop>/clurun/win7-x64/:$PATH
147172
```
148-
- All the parameters to the cmdlets should be passed in as envt. variables
173+
- All the parameters to the cmdlets should be passed in as environment variables
149174
- 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.
150175
- The location for ARM will be provided via variable `$location`.
151176
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1-
#!/bin/bash
1+
#!/bin/env/bash
22
set -e
33
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"
44

5-
printf "\nShowing VM size results in location: %s.\n" "$location"
6-
azure vmsize get --location "$location"
5+
printf "\n1. Showing VM size results in location: %s.\n" "$location"
6+
az vm size ls --location "$location"
77

8-
printf "\nChecking VM size results in location: %s.\n" "$location"
9-
vmSizeResult=`azure vmsize get --location "$location"`
8+
printf "\n2. Checking VM size results in location: %s.\n" "$location"
9+
vmSizeResult=`az vm size ls --location "$location"`
1010

11-
if [ "$vmSizeResult" = "" ]; then
11+
if [[ $vmSizeResult == "" ]]; then
1212
echo "Failure: No VM sizes!" 1>&2
1313
exit 1
1414
else
15-
printf "\nSuccess: Non-empty Results.\n"
15+
echo "Success: Non-empty Results."
1616
fi
1717

18-
queryString=Standard_A0
19-
result=`echo "$vmSizeResult" | grep -q "$queryString"`
20-
if [ "$vmSizeResult" = "" ] ; then
21-
printf "\nFailure: VM Size Not Found: '%s'.\n" "$queryString"
18+
filterResult=`az vm size ls --location "$location" | cat | jq 'select(.name | contains("Standard_A0"))' --raw-output`
19+
if [[ "$filterResult" == "" ]]; then
20+
echo "Failure: Standard_A0 vm size not found." 1>&2
2221
exit 1
2322
else
24-
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
23+
echo "Success: Standard_A0 vm size found."
2524
fi
2625

27-
queryString=Standard_G1
28-
result=`echo "$vmSizeResult" | grep -q "$queryString"`
29-
if [ "$vmSizeResult" = "" ] ; then
30-
printf "\nFailure: VM Size Not Found: '%s'.\n" "$queryString"
26+
filterResult=`az vm size ls --location "$location" | cat | jq 'select(.name | contains("Standard_G1"))' --raw-output`
27+
if [[ "$filterResult" == "" ]]; then
28+
echo "Failure: Standard_G1 vm size not found." 1>&2
3129
exit 1
3230
else
33-
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
31+
echo "Success: Standard_G1 vm size found."
3432
fi
33+
34+
filterResult=`az vm size ls --location "$location" | cat | jq 'select(.name | contains("NonStandard_A1"))' --raw-output`
35+
if [[ "$filterResult" == "" ]]; then
36+
echo "Success: NonStandard_A1 vm size not found."
37+
else
38+
echo "Failure: NonStandard_A1 vm size found." 1>&2
39+
exit 1
40+
fi
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Param(
2+
[string]$resourceGroupName,
3+
[string]$resourceGroupLocation
4+
)
5+
6+
Write-Host "Skip"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/env/bash
2+
set -e
3+
printf "\n=== Managing Virtual Machine Creation in Azure Compute ===\n"
4+
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
az resourcemanager group create -n "$groupName" --location "$location"
7+
8+
printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
9+
az storage account create--resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
10+
11+
printf "\n3. Create virtual network.\n"
12+
result=`az vnet create--resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`
13+
14+
contextResult=`az context ls`
15+
16+
subId=`echo $contextResult | jq '.Subscription.SubscriptionId' --raw-output`
17+
18+
subnetId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/virtualNetworks/test/subnets/test"
19+
20+
printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnetId='$subnetId'.\n" "$subId"
21+
export MSYS_NO_PATHCONV=1
22+
az networkinterface create--name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
23+
export MSYS_NO_PATHCONV=
24+
25+
nicId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/networkInterfaces/test"
26+
27+
vhdUri="https://$storageAccountName.blob.core.windows.net/$storageAccountName/$storageAccountName.vhd"
28+
29+
vmStr="{\"Name\":\"test\",\"HardwareProfile\":{\"VmSize\":\"Standard_A1\"},\"NetworkProfile\":{\"NetworkInterfaces\":[{\"Id\":\"$nicId\"}]},\"OSProfile\":{\"ComputerName\":\"test\",\"AdminPassword\":\"BaR@1234\",\"AdminUsername\":\"Foo12\"},\"StorageProfile\":{\"ImageReference\":{\"Offer\":\"WindowsServer\",\"Publisher\":\"MicrosoftWindowsServer\",\"Sku\":\"2008-R2-SP1\",\"Version\":\"latest\"},\"OSDisk\":{\"Caching\":\"ReadWrite\",\"CreateOption\":\"FromImage\",\"Name\":\"osDisk\",\"Vhd\":{\"Uri\":\"$vhdUri\"}}}}"
30+
31+
printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='%s'\r\nvmStr='%s'\n" "$nicId" "$vhdUri" "$vmStr"
32+
33+
az vm create--resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
34+
35+
printf "\n6. Removing resource group: %s.\n" "$groupName"
36+
az resourcemanager group rm -n "$groupName" -f

examples/lib/helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/env/bash
22

33
randomName() {
44
echo "$1$RANDOM"

examples/lib/loginService.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/bin/bash
2-
azure account add --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$subscription"
1+
#!/bin/env/bash
2+
az login --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$spnSubscription"

examples/lib/loginUser.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/bin/bash
2-
azure account add -u "$azureUser" -p "$password" -s "$subscription"
1+
#!/bin/env/bash
2+
az login -u "$azureUser" -p "$password" -s "$userSubscription"

examples/lib/testrunner.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
#!/bin/bash
2-
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3-
. $BASEDIR/helper.sh
1+
#!/bin/env/bash
2+
export TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3+
. $TESTDIR/helper.sh
44
export groupName=`randomName testrg`
55
export location="westus"
6-
export CmdletSessionID=1010
76
export MSYS_NO_PATHCONV=1
87

98
echo "Logging in as user"
10-
. $BASEDIR/loginUser.sh
9+
. $TESTDIR/loginUser.sh
1110

12-
for d in $( ls $BASEDIR/.. --ignore=lib ); do
13-
for f in $( ls $BASEDIR/../$d/*.sh ); do
11+
for d in $( ls $TESTDIR/.. --ignore=lib ); do
12+
for f in $( ls $TESTDIR/../$d/*.sh ); do
1413
echo "running: $f"
14+
BASEDIR=$(cd "$(dirname "$f")" && pwd)
1515
. $f
1616
set +e
1717
printf "\nCleanup: removing resource group: %s\n" $groupName
18-
azure group remove --name "$groupName" --force
18+
az resourcemanager group rm --name "$groupName" --force
1919
set -e
2020
echo "success: $f"
2121
done

0 commit comments

Comments
 (0)