Skip to content

Commit cdf84cb

Browse files
committed
Merge pull request #103 from huangpf/clu
Clu
2 parents 66c0928 + e056251 commit cdf84cb

25 files changed

+169
-72
lines changed

clu-getstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
118118
```
119119
- Set the environment variable 'TestCredentials' to a connection string providing the credentials to use during test execution. Possible fields include:
120120

121-
| Field | Description |
121+
| Field (case sensitive) | Description |
122122
| ------------- |:-------------|
123123
| Username | an OrgId user name |
124124
| ServicePrincipal | a service principal name |
125125
| Password | the password or application secret to sue for authentication |
126126
| 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 |
127+
| SubscriptionId | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
128128
- 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).
129129
```C#
130130
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"
4+
5+
printf "\nShowing VM size results in location: %s.\n" "$location"
6+
azure vmsize get --location "$location"
7+
8+
printf "\nChecking 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+
printf "\nSuccess: Non-empty Results.\n"
16+
fi
17+
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"
22+
exit 1
23+
else
24+
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
25+
fi
26+
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"
31+
exit 1
32+
else
33+
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
34+
fi

examples/lib/setup.sh

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

examples/lib/testrunner.sh

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

9-
login
9+
echo "Logging in as user"
10+
. $BASEDIR/loginUser.sh
1011

1112
for d in $( ls $BASEDIR/.. --ignore=lib ); do
1213
for f in $( ls $BASEDIR/../$d/*.sh ); do
1314
echo "running: $f"
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: 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Virtual Hard Disks 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. Uploading a virtual hard disk to: %s.\n" "$storageAccountName"
12+
azure vhd add -o --resourcegroupname "$groupName" --destination https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath $BASEDIR/test.vhd
13+
14+
printf "\n4. Downloading a virtual hard disk"
15+
azure vhd save -o --resourcegroupname "$groupName" --sourceuri https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath ./test_downloaded_by_clu.vhd
16+
17+
printf "\n5. Validating the downloaded file is the same.\n"
18+
diffResult=`diff ./test_downloaded_by_clu.vhd $BASEDIR/test_uploaded_byps.vhd`
19+
printf "Difference Result = '%s'.\n" "$diffResult"
20+
if [ "$diffResult" = "" ]; then
21+
echo "Checked"
22+
else
23+
echo "Different!" 1>&2
24+
exit 1
25+
fi
26+
27+
printf "\n6. Removing resource group: %s.\n" "$groupName"
28+
azure group remove -n "$groupName" -f

examples/virtual-hard-disk/02-VirtualHardDisks.sh

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

src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ protected virtual IDictionary<string, string> GetSettings(string key)
4545
var environmentValue = Environment.GetEnvironmentVariable(key);
4646
if (string.IsNullOrWhiteSpace(environmentValue))
4747
{
48-
throw new InvalidOperationException($"Unable to create credentials. " +
49-
"Please set environment ${key}");
48+
throw new InvalidOperationException($"Unable to create credentials. Please set environment variable `{key}`");
5049
}
5150
IDictionary<string, string> settings = new Dictionary<string, string>();
5251
foreach (

src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ public class ExampleScriptRunner
3333
string _sessionId;
3434
Random _generator;
3535
string _resourceGroupName;
36+
string _storageAccountName;
3637
IClientFactory _clientFactory = new ClientFactory();
3738
TestContext _context;
3839
ResourceManagementClient _client;
3940
const string DefaultLocation = "westus";
4041
const string ResourceGroupNameKey = "groupName";
41-
const string locationKey = "location";
42+
const string LocationKey = "location";
43+
const string BaseDir = "BASEDIR";
4244
const string SessionKey = "CmdletSessionID";
43-
const string storageAccountTypeKey = "storageAccountType";
45+
const string StorageAccountTypeKey = "storageAccountType";
46+
const string StorageAccountNameKey = "storageAccountName";
4447
const string DefaultStorageAccountType = "Standard_GRS";
4548

4649
public ExampleScriptRunner(string sessionId) : this(new Random(), sessionId)
@@ -98,16 +101,18 @@ public string RunScript(string testName)
98101
{
99102
Trace.Listeners.Add(listener);
100103
_resourceGroupName = CreateRandomName();
104+
_storageAccountName = CreateRandomName() + "sto";
101105
if (File.Exists(deploymentTemplatePath))
102106
{
103107
DeployTemplate(deploymentTemplatePath, _resourceGroupName);
104108
}
105109

110+
process.EnvironmentVariables[BaseDir] = testDirectory;
106111
process.EnvironmentVariables[SessionKey] = _sessionId;
107112
process.EnvironmentVariables[ResourceGroupNameKey] = _resourceGroupName;
108-
process.EnvironmentVariables[locationKey] = DefaultLocation;
109-
process.EnvironmentVariables[locationKey] = DefaultLocation;
110-
process.EnvironmentVariables[storageAccountTypeKey] = DefaultStorageAccountType;
113+
process.EnvironmentVariables[LocationKey] = DefaultLocation;
114+
process.EnvironmentVariables[StorageAccountTypeKey] = DefaultStorageAccountType;
115+
process.EnvironmentVariables[StorageAccountNameKey] = _storageAccountName;
111116
foreach (var helper in _context.EnvironmentHelpers)
112117
{
113118
helper.TrySetupScriptEnvironment(_context, _clientFactory, process.EnvironmentVariables);

src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,16 @@ private void SetEnvironmentVariables(ProcessStartInfo startInfo)
173173

174174
private void ProcessError(object sender, DataReceivedEventArgs e)
175175
{
176-
Logger.Instance.WriteError(e.Data);
176+
if (e.Data != null)
177+
{
178+
Logger.Instance.WriteError(e.Data);
179+
}
177180
}
178181

179182
private void ProcessOutput(object sender, DataReceivedEventArgs e)
180183
{
181-
Logger.Instance.WriteMessage(e.Data);
182184
_processOutput.Append(e.Data);
185+
Logger.Instance.WriteMessage(e.Data);
183186
}
184187

185188
private void EndProcess()

src/CLU/Commands.Common.ScenarioTest/SampleTest.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,24 @@ public SampleTest(ScenarioTestFixture fixture)
3333
}
3434

3535
[Fact]
36-
public void RunSampleTest()
36+
public void ResourceGroupsTest()
3737
{
3838
var helper = _collectionState.GetRunner("resource-management");
3939
helper.RunScript("01-ResourceGroups");
4040
}
4141

4242
[Fact]
43-
public void RunVirtualHardDiskTest()
43+
public void VirtualHardDisksTest()
4444
{
4545
var helper = _collectionState.GetRunner("virtual-hard-disk");
46-
helper.RunScript("02-VirtualHardDisks");
46+
helper.RunScript("01-VirtualHardDisks");
47+
}
48+
49+
[Fact]
50+
public void RunVirtualMachineSizeTest()
51+
{
52+
var helper = _collectionState.GetRunner("compute-management");
53+
helper.RunScript("01-VirtualMachineSizes");
4754
}
4855
}
4956
}

src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.Azure.Commands.Common.Authentication.Models;
1717
using Microsoft.Azure.Commands.Common.ScenarioTest;
1818
using Microsoft.Azure.Commands.Models;
19-
using Moq.Protected;
2019
using Newtonsoft.Json;
2120

2221
namespace Microsoft.Azure.Commands.Common.ScenarioTest
@@ -34,6 +33,10 @@ public ScenarioTestFixture()
3433
var helper = GetRunner("lib");
3534
var profileText = helper.RunScript(credentials.LoginScriptName);
3635
var profile = JsonConvert.DeserializeObject<PSAzureProfile>(profileText);
36+
if (profile == null)
37+
{
38+
throw new ArgumentOutOfRangeException(nameof(profile), $"Deserialized profile is null: `{profileText}`");
39+
}
3740
AzureContext = (AzureContext) (profile.Context);
3841
}
3942

src/CLU/Commands.Common.ScenarioTest/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"Commands.Common": "",
2121
"Commands.Common.Authentication": "",
2222
"Commands.ResourceManager.Common": "",
23-
"Commands.ScenarioTests.ResourceManager.Common": "",
2423
"Microsoft.Azure.Commands.Profile": "",
2524
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
2625
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",

src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdDownloadContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Compute.Models
1919
{
2020
public class VhdDownloadContext
2121
{
22-
public FileInfo LocalFilePath { get; set; }
23-
public Uri Source { get; set; }
22+
public string LocalFilePath { get; set; }
23+
public string Source { get; set; }
2424
}
2525
}

src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdDownloaderModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public static VhdDownloadContext Download(DownloaderParameters downloadParameter
3232

3333
return new VhdDownloadContext
3434
{
35-
LocalFilePath = new FileInfo(downloadParameters.LocalFilePath),
36-
Source = downloadParameters.BlobUri.Uri
35+
LocalFilePath = downloadParameters.LocalFilePath,
36+
Source = downloadParameters.BlobUri.Uri.ToString()
3737
};
3838
}
3939
}

src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdUploadContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Compute.Models
1919
{
2020
public class VhdUploadContext
2121
{
22-
public FileInfo LocalFilePath { get; set; }
23-
public Uri DestinationUri { get; set; }
22+
public string LocalFilePath { get; set; }
23+
public string DestinationUri { get; set; }
2424
}
2525
}

src/CLU/Microsoft.Azure.Commands.Compute/Models/VhdUploaderModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static VhdUploadContext Upload(UploadParameters uploadParameters)
3838
var synchronizer = new BlobSynchronizer(uploadContext, uploadParameters.NumberOfUploaderThreads);
3939
if (synchronizer.Synchronize())
4040
{
41-
return new VhdUploadContext { LocalFilePath = uploadParameters.LocalFilePath, DestinationUri = uploadParameters.DestinationUri.Uri };
41+
return new VhdUploadContext { LocalFilePath = uploadParameters.LocalFilePath.ToString(), DestinationUri = uploadParameters.DestinationUri.Uri.ToString() };
4242
}
4343
return null;
4444
}

src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void WriteProgress(long sourceId, ProgressRecord record)
6363
{
6464
if (record == null)
6565
{
66-
Console.CursorVisible = true;
6766
throw new ArgumentNullException("record");
6867
}
6968

@@ -80,14 +79,12 @@ public void WriteProgress(long sourceId, ProgressRecord record)
8079
_console.Write(" ");
8180
}
8281
_console.WriteLine();
83-
Console.CursorVisible = true;
8482
}
8583
else
8684
{
87-
Console.CursorVisible = false;
8885
var statusLine = string.Format(Strings.ConsoleDataStream_WriteProgress_StatusLineInProgress, record.Activity, record.StatusDescription, record.CurrentOperation, record.SecondsRemaining);
8986
// Subtract what's already known to be needed:
90-
width -= statusLine.Length + 3;
87+
width = Math.Max(1, width - (statusLine.Length + 3));
9188

9289
var chunkSize = (100 / width) + 1;
9390

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using System.Management.Automation;
7+
8+
namespace Microsoft.CLU.Test
9+
{
10+
11+
[Cmdlet(VerbsCommon.Show, "Progress")]
12+
public class ShowProgress: PSCmdlet
13+
{
14+
[Parameter()]
15+
public int Steps{ get; set; }
16+
17+
18+
protected override void ProcessRecord()
19+
{
20+
base.ProcessRecord();
21+
22+
var progRecord = new ProgressRecord(4711, "Testing progress", "Running");
23+
WriteProgress(progRecord);
24+
for (int step = 1; step <= Steps; ++step)
25+
{
26+
System.Threading.Thread.Sleep(100);
27+
progRecord.PercentComplete = step * 100 / Steps;
28+
WriteProgress(progRecord);
29+
}
30+
progRecord.RecordType = ProgressRecordType.Completed;
31+
WriteProgress(progRecord);
32+
}
33+
}
34+
}

src/CLU/Microsoft.ScenarioTests.CLU/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"dependencies": {
1111
"Microsoft.NETCore": "5.0.1-beta-23516",
1212
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
13-
"Microsoft.CSharp": "4.0.1-beta-23516"
13+
"Microsoft.CSharp": "4.0.1-beta-23516",
14+
15+
"System.Threading.Thread": "4.0.0-beta-23516"
1416
}
1517
}
1618
},

0 commit comments

Comments
 (0)