Skip to content

Clu #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Dec 30, 2015
Merged

Clu #103

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clu-getstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ Testing will consist of scenario tests and unit tests. Scenario tests should be
```
- Set the environment variable 'TestCredentials' to a connection string providing the credentials to use during test execution. Possible fields include:

| Field | Description |
| Field (case sensitive) | Description |
| ------------- |:-------------|
| Username | an OrgId user name |
| ServicePrincipal | a service principal name |
| Password | the password or application secret to sue for authentication |
| TenantId | (required for Service authentication) The tenant guid to authenticate against |
| SubscriptionID | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
| SubscriptionId | (optional) Selects a particular subscription by id. If not provided, the first listed subscription will be selected |
- 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).
```C#
runner.EnvironmentVariables.Add("myVariableName", runner.GenerateName("myres"));
Expand Down
34 changes: 34 additions & 0 deletions examples/compute-management/01-VirtualMachineSizes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -e
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"

printf "\nShowing VM size results in location: %s.\n" "$location"
azure vmsize get --location "$location"

printf "\nChecking VM size results in location: %s.\n" "$location"
vmSizeResult=`azure vmsize get --location "$location"`

if [ "$vmSizeResult" = "" ]; then
echo "Failure: No VM sizes!" 1>&2
exit 1
else
printf "\nSuccess: Non-empty Results.\n"
fi

queryString=Standard_A0
result=`echo "$vmSizeResult" | grep -q "$queryString"`
if [ "$vmSizeResult" = "" ] ; then
printf "\nFailure: VM Size Not Found: '%s'.\n" "$queryString"
exit 1
else
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
fi

queryString=Standard_G1
result=`echo "$vmSizeResult" | grep -q "$queryString"`
if [ "$vmSizeResult" = "" ] ; then
printf "\nFailure: VM Size Not Found: '%s'.\n" "$queryString"
exit 1
else
printf "\nSuccess: VM Size Found in Results: '%s'.\n" "$queryString"
fi
17 changes: 0 additions & 17 deletions examples/lib/setup.sh

This file was deleted.

16 changes: 11 additions & 5 deletions examples/lib/testrunner.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/bin/bash
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $BASEDIR/assert.sh
. $BASEDIR/helper.sh
. $BASEDIR/setup.sh
export groupName=`randomName testrg`
export location="westus"
export CmdletSessionID=1010
export MSYS_NO_PATHCONV=1

login
echo "Logging in as user"
. $BASEDIR/loginUser.sh

for d in $( ls $BASEDIR/.. --ignore=lib ); do
for f in $( ls $BASEDIR/../$d/*.sh ); do
echo "running: $f"
. $f
cleanup
set +e
printf "\nCleanup: removing resource group: %s\n" $groupName
azure group remove --name "$groupName" --force
set -e
echo "success: $f"
done
done
done

export MSYS_NO_PATHCONV=
6 changes: 6 additions & 0 deletions examples/virtual-hard-disk/01-VirtualHardDisks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Param(
[string]$resourceGroupName,
[string]$resourceGroupLocation
)

Write-Host "Skip"
28 changes: 28 additions & 0 deletions examples/virtual-hard-disk/01-VirtualHardDisks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -e
printf "\n=== Managing Virtual Hard Disks in Azure Compute ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create -n "$groupName" --location "$location"

printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
azure storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"

printf "\n3. Uploading a virtual hard disk to: %s.\n" "$storageAccountName"
azure vhd add -o --resourcegroupname "$groupName" --destination https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath $BASEDIR/test.vhd

printf "\n4. Downloading a virtual hard disk"
azure vhd save -o --resourcegroupname "$groupName" --sourceuri https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath ./test_downloaded_by_clu.vhd

printf "\n5. Validating the downloaded file is the same.\n"
diffResult=`diff ./test_downloaded_by_clu.vhd $BASEDIR/test_uploaded_byps.vhd`
printf "Difference Result = '%s'.\n" "$diffResult"
if [ "$diffResult" = "" ]; then
echo "Checked"
else
echo "Different!" 1>&2
exit 1
fi

printf "\n6. Removing resource group: %s.\n" "$groupName"
azure group remove -n "$groupName" -f
17 changes: 0 additions & 17 deletions examples/virtual-hard-disk/02-VirtualHardDisks.sh

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ protected virtual IDictionary<string, string> GetSettings(string key)
var environmentValue = Environment.GetEnvironmentVariable(key);
if (string.IsNullOrWhiteSpace(environmentValue))
{
throw new InvalidOperationException($"Unable to create credentials. " +
"Please set environment ${key}");
throw new InvalidOperationException($"Unable to create credentials. Please set environment variable `{key}`");
}
IDictionary<string, string> settings = new Dictionary<string, string>();
foreach (
Expand Down
15 changes: 10 additions & 5 deletions src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ public class ExampleScriptRunner
string _sessionId;
Random _generator;
string _resourceGroupName;
string _storageAccountName;
IClientFactory _clientFactory = new ClientFactory();
TestContext _context;
ResourceManagementClient _client;
const string DefaultLocation = "westus";
const string ResourceGroupNameKey = "groupName";
const string locationKey = "location";
const string LocationKey = "location";
const string BaseDir = "BASEDIR";
const string SessionKey = "CmdletSessionID";
const string storageAccountTypeKey = "storageAccountType";
const string StorageAccountTypeKey = "storageAccountType";
const string StorageAccountNameKey = "storageAccountName";
const string DefaultStorageAccountType = "Standard_GRS";

public ExampleScriptRunner(string sessionId) : this(new Random(), sessionId)
Expand Down Expand Up @@ -98,16 +101,18 @@ public string RunScript(string testName)
{
Trace.Listeners.Add(listener);
_resourceGroupName = CreateRandomName();
_storageAccountName = CreateRandomName() + "sto";
if (File.Exists(deploymentTemplatePath))
{
DeployTemplate(deploymentTemplatePath, _resourceGroupName);
}

process.EnvironmentVariables[BaseDir] = testDirectory;
process.EnvironmentVariables[SessionKey] = _sessionId;
process.EnvironmentVariables[ResourceGroupNameKey] = _resourceGroupName;
process.EnvironmentVariables[locationKey] = DefaultLocation;
process.EnvironmentVariables[locationKey] = DefaultLocation;
process.EnvironmentVariables[storageAccountTypeKey] = DefaultStorageAccountType;
process.EnvironmentVariables[LocationKey] = DefaultLocation;
process.EnvironmentVariables[StorageAccountTypeKey] = DefaultStorageAccountType;
process.EnvironmentVariables[StorageAccountNameKey] = _storageAccountName;
foreach (var helper in _context.EnvironmentHelpers)
{
helper.TrySetupScriptEnvironment(_context, _clientFactory, process.EnvironmentVariables);
Expand Down
7 changes: 5 additions & 2 deletions src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ private void SetEnvironmentVariables(ProcessStartInfo startInfo)

private void ProcessError(object sender, DataReceivedEventArgs e)
{
Logger.Instance.WriteError(e.Data);
if (e.Data != null)
{
Logger.Instance.WriteError(e.Data);
}
}

private void ProcessOutput(object sender, DataReceivedEventArgs e)
{
Logger.Instance.WriteMessage(e.Data);
_processOutput.Append(e.Data);
Logger.Instance.WriteMessage(e.Data);
}

private void EndProcess()
Expand Down
13 changes: 10 additions & 3 deletions src/CLU/Commands.Common.ScenarioTest/SampleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ public SampleTest(ScenarioTestFixture fixture)
}

[Fact]
public void RunSampleTest()
public void ResourceGroupsTest()
{
var helper = _collectionState.GetRunner("resource-management");
helper.RunScript("01-ResourceGroups");
}

[Fact]
public void RunVirtualHardDiskTest()
public void VirtualHardDisksTest()
{
var helper = _collectionState.GetRunner("virtual-hard-disk");
helper.RunScript("02-VirtualHardDisks");
helper.RunScript("01-VirtualHardDisks");
}

[Fact]
public void RunVirtualMachineSizeTest()
{
var helper = _collectionState.GetRunner("compute-management");
helper.RunScript("01-VirtualMachineSizes");
}
}
}
5 changes: 4 additions & 1 deletion src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.ScenarioTest;
using Microsoft.Azure.Commands.Models;
using Moq.Protected;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Common.ScenarioTest
Expand All @@ -34,6 +33,10 @@ public ScenarioTestFixture()
var helper = GetRunner("lib");
var profileText = helper.RunScript(credentials.LoginScriptName);
var profile = JsonConvert.DeserializeObject<PSAzureProfile>(profileText);
if (profile == null)
{
throw new ArgumentOutOfRangeException(nameof(profile), $"Deserialized profile is null: `{profileText}`");
}
AzureContext = (AzureContext) (profile.Context);
}

Expand Down
1 change: 0 additions & 1 deletion src/CLU/Commands.Common.ScenarioTest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Commands.ResourceManager.Common": "",
"Commands.ScenarioTests.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Compute.Models
{
public class VhdDownloadContext
{
public FileInfo LocalFilePath { get; set; }
public Uri Source { get; set; }
public string LocalFilePath { get; set; }
public string Source { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static VhdDownloadContext Download(DownloaderParameters downloadParameter

return new VhdDownloadContext
{
LocalFilePath = new FileInfo(downloadParameters.LocalFilePath),
Source = downloadParameters.BlobUri.Uri
LocalFilePath = downloadParameters.LocalFilePath,
Source = downloadParameters.BlobUri.Uri.ToString()
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Compute.Models
{
public class VhdUploadContext
{
public FileInfo LocalFilePath { get; set; }
public Uri DestinationUri { get; set; }
public string LocalFilePath { get; set; }
public string DestinationUri { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static VhdUploadContext Upload(UploadParameters uploadParameters)
var synchronizer = new BlobSynchronizer(uploadContext, uploadParameters.NumberOfUploaderThreads);
if (synchronizer.Synchronize())
{
return new VhdUploadContext { LocalFilePath = uploadParameters.LocalFilePath, DestinationUri = uploadParameters.DestinationUri.Uri };
return new VhdUploadContext { LocalFilePath = uploadParameters.LocalFilePath.ToString(), DestinationUri = uploadParameters.DestinationUri.Uri.ToString() };
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void WriteProgress(long sourceId, ProgressRecord record)
{
if (record == null)
{
Console.CursorVisible = true;
throw new ArgumentNullException("record");
}

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

var chunkSize = (100 / width) + 1;

Expand Down
34 changes: 34 additions & 0 deletions src/CLU/Microsoft.ScenarioTests.CLU/ProgressTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using System.Management.Automation;

namespace Microsoft.CLU.Test
{

[Cmdlet(VerbsCommon.Show, "Progress")]
public class ShowProgress: PSCmdlet
{
[Parameter()]
public int Steps{ get; set; }


protected override void ProcessRecord()
{
base.ProcessRecord();

var progRecord = new ProgressRecord(4711, "Testing progress", "Running");
WriteProgress(progRecord);
for (int step = 1; step <= Steps; ++step)
{
System.Threading.Thread.Sleep(100);
progRecord.PercentComplete = step * 100 / Steps;
WriteProgress(progRecord);
}
progRecord.RecordType = ProgressRecordType.Completed;
WriteProgress(progRecord);
}
}
}
4 changes: 3 additions & 1 deletion src/CLU/Microsoft.ScenarioTests.CLU/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"dependencies": {
"Microsoft.NETCore": "5.0.1-beta-23516",
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
"Microsoft.CSharp": "4.0.1-beta-23516"
"Microsoft.CSharp": "4.0.1-beta-23516",

"System.Threading.Thread": "4.0.0-beta-23516"
}
}
},
Expand Down
Loading