Skip to content
Merged

Clu #282

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
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=
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
14 changes: 8 additions & 6 deletions src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public class ExampleScriptRunner
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 storageAccountNameKey = "storageAccountName";
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 @@ -106,11 +107,12 @@ public string RunScript(string testName)
DeployTemplate(deploymentTemplatePath, _resourceGroupName);
}

process.EnvironmentVariables[BaseDir] = testDirectory;
process.EnvironmentVariables[SessionKey] = _sessionId;
process.EnvironmentVariables[ResourceGroupNameKey] = _resourceGroupName;
process.EnvironmentVariables[locationKey] = DefaultLocation;
process.EnvironmentVariables[storageAccountTypeKey] = DefaultStorageAccountType;
process.EnvironmentVariables[storageAccountNameKey] = _storageAccountName;
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
4 changes: 2 additions & 2 deletions src/CLU/Commands.Common.ScenarioTest/SampleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ 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("01-VirtualHardDisks");
Expand Down
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 @@ -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
8 changes: 4 additions & 4 deletions tools/CLU/BuildAndInstallClu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\osx.10.10-x64
copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\osx.10.10-x64

REM: copy over the pre-cooked azure.sh and ensure correct line endings
copy /Y %~dp0\azure.sh %root%\drop\clurun\osx.10.10-x64
set azuresh=%root%\drop\clurun\osx.10.10-x64\azure.sh
copy /Y %~dp0\azure.sh %root%\drop\clurun\osx.10.10-x64\azure
set azuresh=%root%\drop\clurun\osx.10.10-x64\azure
echo Get-ChildItem %azuresh% ^| ForEach-Object { > %temp%\fixLineEndings.ps1
echo $contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n" >> %temp%\fixLineEndings.ps1
echo [IO.File]::WriteAllText($_, $contents) >> %temp%\fixLineEndings.ps1
Expand All @@ -53,7 +53,7 @@ echo } >> %temp%\fixLineEndings.ps1
xcopy %root%\drop\clurun\win7-x64\pkgs %root%\drop\clurun\ubuntu.14.04-x64\pkgs /S /Q /I /Y
copy /Y %root%\drop\clurun\win7-x64\azure.lx %root%\drop\clurun\ubuntu.14.04-x64
copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\ubuntu.14.04-x64
copy /Y %azuresh% %root%\drop\clurun\ubuntu.14.04-x64
copy /Y %azuresh% %root%\drop\clurun\ubuntu.14.04-x64\azure

REM, windows version also needs it for bash based testing
copy /Y %azuresh% %root%\drop\clurun\win7-x64\azure
copy /Y %~dp0\azure.win.sh %root%\drop\clurun\win7-x64\azure
8 changes: 8 additions & 0 deletions tools/CLU/azure.win.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -z ${CmdletSessionID} ]
then
export CmdletSessionID=$PPID
fi
SCRIPTPATH=$(dirname "$0")
WSCRIPTPATH=$({ cd $SCRIPTPATH && pwd -W; } | sed 's|/|\\|g')
$WSCRIPTPATH/clurun -s azure -r $WSCRIPTPATH/azure.lx "$@"