Skip to content

Commit 0c02835

Browse files
committed
Merge remote-tracking branch 'origin/clu' into provide-format-output-parameter
2 parents 91d0038 + b320357 commit 0c02835

File tree

585 files changed

+64394
-1747
lines changed

Some content is hidden

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

585 files changed

+64394
-1747
lines changed

clu-getstart.md

Lines changed: 86 additions & 16 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.
@@ -46,15 +48,17 @@ CLUPackages require some additional files to direct generation of indexing, and
4648
```
4749

4850
### Package Creation and Testing
49-
2 options
50-
* Run `<repo-root>\tools\CLU\SetupEnv.bat` which build and generate all cmdlet packages and deploy to under `<repo root>\drop` folder. When you have a clean environment, you should always do this first.
51-
* Run `<repo-root>\tools\CLU\BuildCmdlet` <name like: Microsoft.Azure.Commands.Profile>", this will build and refresh an individual cmdlet package.
51+
Two options
52+
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.
53+
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.
54+
55+
After #1 above is finished, you can run `drop\clurun\<platform>\azure.bat help` to explore.
5256

53-
Once you are done with #1, in the same command window, you can type "azure help" to explore and run cmdlets.
57+
To debug, set environment variable of `DebugCLU` to "1". Then on running any command, you will be prompted to attach a debugger.
5458

55-
To debug, set environment variable of `DebugCLU` to "1"(#1 should set it up already). When you run any command, you will see a prompt telling you to attach debugger.
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\azure.bat` to the PATH environment variable.
5660

57-
To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, you should see subfolders for "osx" and "ubuntu", copy the 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 "azure.sh" inside. Make sure set execution permission using `chmod +x azure.sh clurun`
5862

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

@@ -88,18 +92,84 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, you should se
8892
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.
8993

9094
#### Scenario Tests
91-
- Scenario tests should be saved under `./examples` directory and grouped by the package or service area. Each scenario tests should consist of both `.ps1` and `.sh` files and should cover "P0" scenarios.
92-
93-
##### Bash Tests
95+
- 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.
96+
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+
117+
##### XUnit Automation For Bash Scenario Tests
118+
- The ```Commands.Common.ScenarioTest``` project contains classes that enable executing bash scenario tests in Visual Studio, or cross-platform using dnx.
119+
120+
- To implement an xunit bash scenario test you must
121+
- Add a ```[Collection("SampleCollection")]``` attribute to your test class
122+
- Add a field to your class of type ```ScenarioTestFixture``` and add a constructor that initializes it
123+
```C#
124+
[Collection("SampleCollection")]
125+
public class SampleTestClass
126+
{
127+
ScenarioTestFixture _fixture;
128+
public SampleTestClass(ScenarioTestFixture fixture)
129+
{
130+
_fixture = fixture;
131+
}
132+
```
133+
- Use the fixture in your test method to create a script runner for your directory and to run your test script:
134+
```C#
135+
[Fact]
136+
public void RunSampleTest()
137+
{
138+
_fixture.GetRunner("resource-management").RunScript("01-ResourceGroups");
139+
}
140+
```
141+
- Set the [environment variables](#Environment_Variables_for_Authentication) for either Username/Password (no 2FA) or ServicePrincipal authentication
142+
- Update PATH to include location of CLU bin drop.
143+
```bash
144+
export PATH=/<path-to-drop>/clurun/win7-x64/:$PATH
145+
```
146+
- The infrastructure automatically generates the following environment variables:
147+
- `BASEDIR` - directory path where test script is located
148+
- `location` - default "WestUS" location
149+
- `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)
150+
- `storageAccountType` - default "Standard_GRS" storage account type
151+
- `storageAccountName` - randomly generated storage account name
152+
- 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).
153+
```C#
154+
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
155+
```
156+
- 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:
157+
158+
| Environment Variable | Description |
159+
| ------------- |:-------------|
160+
| ExamplesDirectory | The path to the 'examples' directory ($pshome/examples) |
161+
| TestDirectory | The path to the directory where logs will be written |
162+
163+
##### Running Bash Tests using Bash shell
94164
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
95-
- To manually run the tests; please set the following envt. variables for authentication and run `./examples/lib/testrunner.sh`
165+
- 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`
166+
96167
```bash
97-
export azureuser=<[email protected]>
98-
export azurepassword=<your_password>
99-
export PATH=$PATH:/<path-to-drop>/clurun/win7-x64/
100-
. /examples/lib/testrunner.sh
168+
export azureUser=<[email protected]>
169+
export password=<your_password>
170+
export PATH=/<path-to-drop>/clurun/win7-x64/:$PATH
101171
```
102-
- All the parameters to the cmdlets should be passed in as envt. variables
172+
- All the parameters to the cmdlets should be passed in as environment variables
103173
- 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.
104174
- The location for ARM will be provided via variable `$location`.
105175
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"
4+
5+
printf "\n1. Showing VM size results in location: %s.\n" "$location"
6+
azure vmsize get --location "$location"
7+
8+
printf "\n2. Checking VM size results in location: %s.\n" "$location"
9+
vmSizeResult=`azure vmsize get --location "$location"`
10+
11+
if [[ $vmSizeResult == "" ]]; then
12+
echo "Failure: No VM sizes!" 1>&2
13+
exit 1
14+
else
15+
echo "Success: Non-empty Results."
16+
fi
17+
18+
filterResult=`azure vmsize get --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
21+
exit 1
22+
else
23+
echo "Success: Standard_A0 vm size found."
24+
fi
25+
26+
filterResult=`azure vmsize get --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
29+
exit 1
30+
else
31+
echo "Success: Standard_G1 vm size found."
32+
fi
33+
34+
filterResult=`azure vmsize get --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/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+
azure group create -n "$groupName" --location "$location"
7+
8+
printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
9+
azure storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
10+
11+
printf "\n3. Create virtual network.\n"
12+
result=`azure virtual network new --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=`azure context get`
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+
azure network interface new --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+
azure vm new --resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
34+
35+
printf "\n6. Removing resource group: %s.\n" "$groupName"
36+
azure group remove -n "$groupName" -f

examples/lib/loginService.sh

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

examples/lib/loginUser.sh

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

examples/lib/setup.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/lib/testrunner.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
#!/bin/bash
2-
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3-
. $BASEDIR/assert.sh
4-
. $BASEDIR/helper.sh
5-
. $BASEDIR/setup.sh
2+
export TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3+
. $TESTDIR/helper.sh
64
export groupName=`randomName testrg`
75
export location="westus"
6+
export MSYS_NO_PATHCONV=1
87

9-
login
8+
echo "Logging in as user"
9+
. $TESTDIR/loginUser.sh
1010

11-
for d in $( ls $BASEDIR/.. --ignore=lib ); do
12-
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
1313
echo "running: $f"
14+
BASEDIR=$(cd "$(dirname "$f")" && pwd)
1415
. $f
15-
cleanup
16+
set +e
17+
printf "\nCleanup: removing resource group: %s\n" $groupName
18+
azure group remove --name "$groupName" --force
19+
set -e
1620
echo "success: $f"
1721
done
18-
done
22+
done
23+
24+
export MSYS_NO_PATHCONV=
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
Param(
2-
[string]$resourceGroupName,
3-
[string]$resourceGroupLocation
2+
[string]$groupName,
3+
[string]$location
44
)
55

66
Write-Host "=== Managing Resource Groups in Azure ==="
77

88
Write-Host "1. Create a new resource group"
9-
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation
9+
New-AzureRmResourceGroup -Name $groupName -Location $location
1010

1111
Write-Host "2. Update group tags"
12-
Set-AzureRmResourceGroup -Name $resourceGroupName -Tags @{Name = "testtag"; Value = "testval"}
12+
Set-AzureRmResourceGroup -Name $groupName -Tags @{Name = "testtag"; Value = "testval"}
1313

1414
Write-Host "3. Get information about resource group"
15-
$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName
15+
$resourceGroup = Get-AzureRmResourceGroup -Name $groupName
1616
Write-Host $resourceGroup
1717

1818
Write-Host "4. List all resource groups in the subscription"
1919
Get-AzureRmResourceGroup
2020

2121
Write-Host "5. Remove resource group"
22-
Remove-AzureRmResourceGroup -Name $resourceGroupName -Force
22+
Remove-AzureRmResourceGroup -Name $groupName -Force
2323

2424
Write-Host "6. Validations"
25-
Assert-AreEqual $resourceGroup.ResourceGroupName $resourceGroupName
25+
Assert-AreEqual $resourceGroup.ResourceGroupName $groupName

examples/resource-management/01-ResourceGroups.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ 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-
azure group create --name "$groupName" --location "$location"
6+
azure group create -n "$groupName" --location "$location"
77

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

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

1414
printf "\nValidating resource group name is: %s\n" "$groupName"
1515
[ $(echo $resourceGroupInfo | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
@@ -18,4 +18,4 @@ printf "\n4. Listing all resource groups in the subscription.\n"
1818
azure group get
1919

2020
printf "\n5. Removing resource group: %s.\n" "$groupName"
21-
azure group remove --name "$groupName" --force
21+
azure group remove -n "$groupName" -f
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Param(
2+
[string]$groupName,
3+
[string]$location,
4+
[string]$rName,
5+
)
6+
7+
Write-Host "=== Managing Resources in Azure ==="
8+
9+
Write-Host "1. Creating a new resource group"
10+
New-AzureRmResourceGroup -Name $groupName -Location $location
11+
$destinationGroupName = $groupName + "Destination"
12+
13+
Write-Host "2. Registering Resource Provider Namespace."
14+
$providerNamespace="Providers.Test"
15+
Register-AzureRmResourceProvider -ProviderNamespace $providerNamespace -Force
16+
17+
Write-Host "3. Creating a new Resource"
18+
$resourceType = $providerNamespace + "/statefulResources"
19+
$apiversion="2014-04-01"
20+
New-AzureRmResource -Name $rName -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $groupName -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion -Force
21+
22+
Write-Host "4. Get information about Resource"
23+
$resourceInfo = Get-AzureRmResource -ResourceGroupName $groupName
24+
Write-Host "Validating Resource name"
25+
Assert-AreEqual $rName $resourceInfo.Name
26+
27+
Write-Host "5. Find Resource with name"
28+
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
29+
Write-Host "Validating Resource name"
30+
Assert-AreEqual $rName $foundResource.Name
31+
32+
Write-Host "6. Update Resource"
33+
Set-AzureRmResource -ResourceGroupName $groupName -ResourceName $rName -ResourceType $resourceType -Tags @{Name = "testtagUpdated"; Value = "testvalueUpdated"} -Force
34+
35+
Write-Host "7. Move Resource to resource group"
36+
New-AzureRmResourceGroup -Name $destinationGroupName -Location $location
37+
Move-AzureRmResource -DestinationResourceGroupName $destinationGroupName -ResourceId $resourceInfo.ResourceId -Force
38+
39+
Write-Host "8. Removing resource"
40+
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
41+
Remove-AzureRmResource -ResourceId $foundResource.ResourceId -Force

0 commit comments

Comments
 (0)