From e8c5fc8439507a6397f952d715ba20feb2bd3b01 Mon Sep 17 00:00:00 2001 From: Johan Stenberg Date: Tue, 22 Dec 2015 14:05:07 -0800 Subject: [PATCH 1/7] Fix progress related bugs (divide by zero crash for certain window width/message length combinations, failure to show/hide cursor when stdout redirected) --- .../Host/ConsoleDataStream.cs | 5 +-- .../ProgressTest.cs | 34 +++++++++++++++++++ .../Microsoft.ScenarioTests.CLU/project.json | 4 ++- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/CLU/Microsoft.ScenarioTests.CLU/ProgressTest.cs 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 ae8d95805f33..00f1becbd7de 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" } } }, From c691484dac9ca1f319b1aeb13df58b66d6089b06 Mon Sep 17 00:00:00 2001 From: stankovski Date: Tue, 29 Dec 2015 16:42:02 -0800 Subject: [PATCH 2/7] Fixes the issue with POSIX path translation in MinGW bash --- examples/lib/testrunner.sh | 5 ++++- tools/CLU/BuildAndInstallClu.bat | 2 +- tools/CLU/azure.win.sh | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tools/CLU/azure.win.sh diff --git a/examples/lib/testrunner.sh b/examples/lib/testrunner.sh index 0139799fb2fb..3aa68fa31b4b 100644 --- a/examples/lib/testrunner.sh +++ b/examples/lib/testrunner.sh @@ -5,6 +5,7 @@ export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) . $BASEDIR/setup.sh export groupName=`randomName testrg` export location="westus" +export MSYS_NO_PATHCONV=1 login @@ -15,4 +16,6 @@ for d in $( ls $BASEDIR/.. --ignore=lib ); do cleanup 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/tools/CLU/BuildAndInstallClu.bat b/tools/CLU/BuildAndInstallClu.bat index f2869fe143d8..9b1c506c0c93 100644 --- a/tools/CLU/BuildAndInstallClu.bat +++ b/tools/CLU/BuildAndInstallClu.bat @@ -56,4 +56,4 @@ copy /Y %root%\drop\clurun\win7-x64\msclu.cfg %root%\drop\clurun\ubuntu.14.04-x6 copy /Y %azuresh% %root%\drop\clurun\ubuntu.14.04-x64 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 "$@" From 14fb36dd56ee4d97071348dcac418b0421ce98a7 Mon Sep 17 00:00:00 2001 From: stankovski Date: Wed, 30 Dec 2015 11:52:00 -0800 Subject: [PATCH 3/7] Refactored login --- examples/lib/loginUser.sh | 1 + examples/lib/setup.sh | 17 ----------------- examples/lib/testrunner.sh | 10 ++++++---- .../EnvironmentCredentialsProvider.cs | 3 +-- .../Commands.Common.ScenarioTest/SampleTest.cs | 4 ++-- 5 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 examples/lib/setup.sh diff --git a/examples/lib/loginUser.sh b/examples/lib/loginUser.sh index fd442b568070..84a8e6deb476 100644 --- a/examples/lib/loginUser.sh +++ b/examples/lib/loginUser.sh @@ -1,2 +1,3 @@ #!/bin/bash +echo "Logging in as user" azure account add -u "$azureUser" -p "$password" -s "$subscription" \ No newline at end of file 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 3aa68fa31b4b..5e2eaaea1241 100644 --- a/examples/lib/testrunner.sh +++ b/examples/lib/testrunner.sh @@ -1,19 +1,21 @@ #!/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 +. $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 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/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"); From 39b1a20d937a2ff8cf8db2d77bc611344e2f29fa Mon Sep 17 00:00:00 2001 From: Denis Stankovski Date: Wed, 30 Dec 2015 12:14:03 -0800 Subject: [PATCH 4/7] Update clu-getstart.md --- clu-getstart.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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")); From 904aeff17fdc100f50274e4d834d5f84f7308470 Mon Sep 17 00:00:00 2001 From: stankovski Date: Wed, 30 Dec 2015 13:04:17 -0800 Subject: [PATCH 5/7] Misc test fixes --- examples/lib/loginUser.sh | 1 - examples/lib/testrunner.sh | 1 + .../ExampleScriptRunner.cs | 14 ++++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/lib/loginUser.sh b/examples/lib/loginUser.sh index 84a8e6deb476..fd442b568070 100644 --- a/examples/lib/loginUser.sh +++ b/examples/lib/loginUser.sh @@ -1,3 +1,2 @@ #!/bin/bash -echo "Logging in as user" azure account add -u "$azureUser" -p "$password" -s "$subscription" \ No newline at end of file diff --git a/examples/lib/testrunner.sh b/examples/lib/testrunner.sh index 5e2eaaea1241..136c33eab0bc 100644 --- a/examples/lib/testrunner.sh +++ b/examples/lib/testrunner.sh @@ -6,6 +6,7 @@ export location="westus" export CmdletSessionID=1010 export MSYS_NO_PATHCONV=1 +echo "Logging in as user" . $BASEDIR/loginUser.sh for d in $( ls $BASEDIR/.. --ignore=lib ); do 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); From c9d5165d27aa14ac48b20fe58e2d91d4c4d450ca Mon Sep 17 00:00:00 2001 From: stankovski Date: Wed, 30 Dec 2015 14:19:43 -0800 Subject: [PATCH 6/7] Fixed test runner and removed dependency on ResourceManagement scenario tests --- src/CLU/Commands.Common.ScenarioTest/ProcessHelper.cs | 7 +++++-- .../Commands.Common.ScenarioTest/ScenarioTestFixture.cs | 5 ++++- src/CLU/Commands.Common.ScenarioTest/project.json | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) 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/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", From 624c83d44602c82ed57579bee6e56ae5538f1ed8 Mon Sep 17 00:00:00 2001 From: stankovski Date: Wed, 30 Dec 2015 14:46:09 -0800 Subject: [PATCH 7/7] Renamed azure.sh to azure on Ubuntu and Mac --- tools/CLU/BuildAndInstallClu.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/CLU/BuildAndInstallClu.bat b/tools/CLU/BuildAndInstallClu.bat index 9b1c506c0c93..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 %~dp0\azure.win.sh %root%\drop\clurun\win7-x64\azure