diff --git a/clu-getstart.md b/clu-getstart.md index 987a4b97f626..da0480ed03bd 100644 --- a/clu-getstart.md +++ b/clu-getstart.md @@ -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")); diff --git a/examples/lib/setup.sh b/examples/lib/setup.sh deleted file mode 100644 index 9de247fce2d5..000000000000 --- a/examples/lib/setup.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# Login -login() { - echo "Executing Login..." - export CmdletSessionId=1010 - azure account add --username $azureuser --password $azurepassword -} - -cleanup() { - set +e - printf "\nCleanup: removing resource group: %s\n" $groupName - azure group remove --name "$groupName" --force - set -e -} - -export -f login -export -f cleanup \ No newline at end of file diff --git a/examples/lib/testrunner.sh b/examples/lib/testrunner.sh index 0139799fb2fb..136c33eab0bc 100644 --- a/examples/lib/testrunner.sh +++ b/examples/lib/testrunner.sh @@ -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 \ No newline at end of file +done + +export MSYS_NO_PATHCONV= \ No newline at end of file diff --git a/src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs b/src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs index 66b685bbe1db..0d3f6c20e05d 100644 --- a/src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs +++ b/src/CLU/Commands.Common.ScenarioTest/EnvironmentCredentialsProvider.cs @@ -45,8 +45,7 @@ protected virtual IDictionary 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 settings = new Dictionary(); foreach ( diff --git a/src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs b/src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs index a10c0a239973..04f2e579bf79 100644 --- a/src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs +++ b/src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs @@ -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) @@ -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); diff --git a/src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs b/src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs index a45e88ab2b81..6295e15b1ef3 100644 --- a/src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs +++ b/src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs @@ -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() diff --git a/src/CLU/Commands.Common.ScenarioTest/SampleTest.cs b/src/CLU/Commands.Common.ScenarioTest/SampleTest.cs index c727dc7e97f6..a18540c53ba9 100644 --- a/src/CLU/Commands.Common.ScenarioTest/SampleTest.cs +++ b/src/CLU/Commands.Common.ScenarioTest/SampleTest.cs @@ -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"); diff --git a/src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs b/src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs index ba487dd7a344..f2b3a4deb4f4 100644 --- a/src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs +++ b/src/CLU/Commands.Common.ScenarioTest/ScenarioTestFixture.cs @@ -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 @@ -34,6 +33,10 @@ public ScenarioTestFixture() var helper = GetRunner("lib"); var profileText = helper.RunScript(credentials.LoginScriptName); var profile = JsonConvert.DeserializeObject(profileText); + if (profile == null) + { + throw new ArgumentOutOfRangeException(nameof(profile), $"Deserialized profile is null: `{profileText}`"); + } AzureContext = (AzureContext) (profile.Context); } diff --git a/src/CLU/Commands.Common.ScenarioTest/project.json b/src/CLU/Commands.Common.ScenarioTest/project.json index f7159ac5e4ea..137e55a142f2 100644 --- a/src/CLU/Commands.Common.ScenarioTest/project.json +++ b/src/CLU/Commands.Common.ScenarioTest/project.json @@ -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", diff --git a/src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs b/src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs index e7d341b4ecd8..cdadba3a21c6 100644 --- a/src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs +++ b/src/CLU/Microsoft.CLU/System.Management.Automation/Host/ConsoleDataStream.cs @@ -63,7 +63,6 @@ public void WriteProgress(long sourceId, ProgressRecord record) { if (record == null) { - Console.CursorVisible = true; throw new ArgumentNullException("record"); } @@ -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; diff --git a/src/CLU/Microsoft.ScenarioTests.CLU/ProgressTest.cs b/src/CLU/Microsoft.ScenarioTests.CLU/ProgressTest.cs new file mode 100644 index 000000000000..4a8cfe6fc12a --- /dev/null +++ b/src/CLU/Microsoft.ScenarioTests.CLU/ProgressTest.cs @@ -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); + } + } +} diff --git a/src/CLU/Microsoft.ScenarioTests.CLU/project.json b/src/CLU/Microsoft.ScenarioTests.CLU/project.json index 8a8dd5f0cb9b..4664773eabfb 100644 --- a/src/CLU/Microsoft.ScenarioTests.CLU/project.json +++ b/src/CLU/Microsoft.ScenarioTests.CLU/project.json @@ -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" } } }, diff --git a/tools/CLU/BuildAndInstallClu.bat b/tools/CLU/BuildAndInstallClu.bat index f2869fe143d8..8bbe50550bdb 100644 --- a/tools/CLU/BuildAndInstallClu.bat +++ b/tools/CLU/BuildAndInstallClu.bat @@ -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 @@ -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 diff --git a/tools/CLU/azure.win.sh b/tools/CLU/azure.win.sh new file mode 100644 index 000000000000..5889f49f4512 --- /dev/null +++ b/tools/CLU/azure.win.sh @@ -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 "$@"