Skip to content

Commit b311f0a

Browse files
committed
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
Conflicts: src/CLU/CLUCoreCLR.sln
2 parents b96778d + 240c89e commit b311f0a

29 files changed

+497
-119
lines changed

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
<Message Importance="high" Text="Running check in tests..." />
318318
<ItemGroup>
319319
<!--Exclude 1 test projects still in progress with build failures-->
320-
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json">
320+
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json" Exclude="$(CLURootDir)\Microsoft.CLU.Test\project.json">
321321
</_CLUTestProjects>
322322
</ItemGroup>
323323
<Exec Command="dnu build" WorkingDirectory="%(_CLUTestProjects.RootDir)%(_CLUTestProjects.Directory)" />

clu-getstart.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,36 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, you should se
7878

7979
```set CmdletSessionId=1010 ```
8080

81+
### Testing Cmdlets
82+
83+
#### Environment setup (Windows)
84+
- Install latest version of [Git for Windows](https://git-scm.com/download/win) that has `bash 4.x` available.
85+
- Install `jq` using chocolatey `choco install jq` (chocolatey can be installed from [here](https://chocolatey.org/)).
86+
87+
#### Test Infrastructure
88+
Testing will consist of scenario tests and unit tests. Scenario tests should be written in a form of an example and be available in `.ps1` and `.sh` formats.
89+
90+
#### Scenario Tests
91+
- Scenario tests should be saved under `./examples` directory and grouped by the package or service area. Each scenario tests should consist of both `.ps1` and `.sh` files and should cover "P0" scenarios.
92+
93+
##### Bash Tests
94+
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
95+
- To manually run the tests; please set the following envt. variables for authentication and run `./examples/lib/testrunner.sh`
96+
```bash
97+
export azureuser=<[email protected]>
98+
export azurepassword=<your_password>
99+
export PATH=$PATH:/<path-to-drop>/clurun/win7-x64/
100+
. /examples/lib/testrunner.sh
101+
```
102+
- All the parameters to the cmdlets should be passed in as envt. variables
103+
- The current test runners will provide a unique resource group name via `$groupName` but may not remove it at the end if the test fails.
104+
- The location for ARM will be provided via variable `$location`.
105+
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.
106+
107+
##### PowerShell Tests
108+
TODO: Add section on PowerShell testing
109+
110+
#### Unit Tests
111+
TODO: Add section on unit testing
112+
113+

examples/lib/helper.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
randomName() {
24
echo "$1$RANDOM"
35
}

examples/lib/setup.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/bin/bash
2-
32
# Login
4-
echo "Executing Login..."
5-
export CmdletSessionId=1010
6-
azure account add --username $azureuser --password $azurepassword
3+
login() {
4+
echo "Executing Login..."
5+
export CmdletSessionId=1010
6+
azure account add --username $azureuser --password $azurepassword
7+
}
8+
9+
cleanup() {
10+
set +e
11+
printf "\nCleanup: removing resource group: %s\n" $groupName
12+
azure group remove --name "$groupName" --force
13+
set -e
14+
}
15+
16+
export -f login
17+
export -f cleanup

examples/lib/testrunner.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
2-
. setup.sh
3-
. helper.sh
4-
export resourceGroupName=`randomName testrg`
5-
export resourceGroupLocation="westus"
2+
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3+
. $BASEDIR/assert.sh
4+
. $BASEDIR/helper.sh
5+
. $BASEDIR/setup.sh
6+
export groupName=`randomName testrg`
7+
export location="westus"
68

7-
for d in $( ls .. --ignore=lib ); do
8-
for f in $( ls ../$d/*.sh ); do
9+
login
10+
11+
for d in $( ls $BASEDIR/.. --ignore=lib ); do
12+
for f in $( ls $BASEDIR/../$d/*.sh ); do
913
echo "running: $f"
1014
. $f
15+
cleanup
16+
echo "success: $f"
1117
done
1218
done
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#!/bin/bash
2-
2+
set -e
33
printf "\n=== Managing Resource Groups in Azure ===\n"
44

5-
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$resourceGroupName" "$resourceGroupLocation"
6-
azure resource group new --name "$resourceGroupName" --location "$resourceGroupLocation"
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
azure group create --name "$groupName" --location "$location"
7+
8+
printf "\n2. Updating the group %s with tags.\n" "$groupName"
9+
azure group set --name "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
710

8-
printf "\n2. Updating the group %s with tags.\n" "$resourceGroupName"
9-
azure resource group set --name "$resourceGroupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
11+
printf "\n3. Get information about resource group : %s.\n" "$groupName"
12+
resourceGroupInfo=`azure group get --name $groupName`
1013

11-
printf "\n3. Get information about resource group : %s.\n" "$resourceGroupName"
12-
resourceGroupInfo=`azure resource group get --name $resourceGroupName`
13-
printf "\nThe resource group info is: \n %s\n" "$resourceGroupInfo"
14+
printf "\nValidating resource group name is: %s\n" "$groupName"
15+
[ $(echo $resourceGroupInfo | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
1416

1517
printf "\n4. Listing all resource groups in the subscription.\n"
16-
azure resource group get
18+
azure group get
1719

18-
printf "\n5. Removing resource group: %s.\n" "$resourceGroupName"
19-
azure resource group remove --name "$resourceGroupName" --force
20+
printf "\n5. Removing resource group: %s.\n" "$groupName"
21+
azure group remove --name "$groupName" --force

src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Run", "Micros
3737
EndProject
3838
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.CLU\Microsoft.CLU.xproj", "{D0A59671-088D-463B-B060-2ADAFFB9C3F6}"
3939
EndProject
40+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
41+
EndProject
4042
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
4143
ProjectSection(ProjectDependencies) = postProject
4244
{99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778}
@@ -127,6 +129,10 @@ Global
127129
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
128130
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
129131
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
130136
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131137
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
132138
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/CLU/Microsoft.CLU/CommandModel/ICommandModel.cs renamed to src/CLU/Microsoft.CLU.Common/ICommandModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
namespace Microsoft.CLU
22
{
3+
public enum CommandModelErrorCode
4+
{
5+
Success = 0,
6+
InternalFailure = -1,
7+
NonTerminatingError = 1,
8+
TerminatingError = 2,
9+
CommandNotFound = 3,
10+
11+
MissingParameters = 10,
12+
13+
PackageNotFound = 20
14+
}
15+
316
/// <summary>
417
/// The contract that different "Programming Model" model classes needs to implement.
518
/// </summary>
@@ -10,6 +23,6 @@ public interface ICommandModel
1023
/// </summary>
1124
/// <param name="commandConfiguration">Date from the command configuration file.</param>
1225
/// <param name="arguments">The command-line arguments array</param>
13-
void Run(ConfigurationDictionary commandConfiguration, string[] arguments);
26+
CommandModelErrorCode Run(ConfigurationDictionary commandConfiguration, string[] arguments);
1427
}
1528
}

src/CLU/Microsoft.CLU.Run/CommandExecMode.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public bool CanHandle(string[] arguments)
2727
/// IRunMode implementation for executing command.
2828
/// </summary>
2929
/// <param name="arguments">The arguments</param>
30-
public void Run(string[] arguments)
30+
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
3131
{
3232
if (arguments.Length < 2)
3333
{
3434
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingCommandConfigFileArgument);
35-
return;
35+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
3636
}
3737

3838
try
@@ -52,7 +52,7 @@ public void Run(string[] arguments)
5252
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
5353
{
5454
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingScriptName);
55-
return;
55+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
5656
}
5757

5858
CLUEnvironment.ScriptName = arguments[argsBase + 1];
@@ -65,7 +65,7 @@ public void Run(string[] arguments)
6565
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
6666
{
6767
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingScriptConfigFileName);
68-
return;
68+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
6969
}
7070

7171
commandConfiguration = CommandConfig.Load(arguments[argsBase + 1]);
@@ -77,7 +77,7 @@ public void Run(string[] arguments)
7777
}
7878
}
7979

80-
CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
80+
return CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
8181
}
8282
catch (TargetInvocationException tie)
8383
{
@@ -89,6 +89,8 @@ public void Run(string[] arguments)
8989
CLUEnvironment.Console.WriteErrorLine(exc.Message);
9090
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
9191
}
92+
93+
return CommandModelErrorCode.InternalFailure;
9294
}
9395

9496
#endregion

src/CLU/Microsoft.CLU.Run/CommandModel.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ internal class CommandModel
1919
/// </summary>
2020
/// <param name="commandConfiguration"></param>
2121
/// <param name="modelArguments"></param>
22-
public static void Run(CommandConfig commandConfiguration, string[] modelArguments)
22+
public static Microsoft.CLU.CommandModelErrorCode Run(CommandConfig commandConfiguration, string[] modelArguments)
2323
{
2424
CommandModel commandModel = new CommandModel()
2525
{
2626
_commandConfiguration = commandConfiguration,
2727
_modelArguments = modelArguments
2828
};
2929
commandModel.ResolveModel();
30-
commandModel.Run();
30+
return commandModel.Run();
3131
}
3232

3333
/// <summary>
@@ -62,19 +62,21 @@ private void ResolveModel()
6262
/// <summary>
6363
/// Runs the model
6464
/// </summary>
65-
private void Run()
65+
private CommandModelErrorCode Run()
6666
{
67+
object returnValue = null;
6768
if (_entryPoint.ClassType.GetInterfaces().Where(t => String.Equals(t.FullName, Common.Constants.CommandModelInterface, StringComparison.Ordinal)).FirstOrDefault() != null)
6869
{
6970
var model = Activator.CreateInstance(_entryPoint.ClassType);
7071
var configDict = ConfigurationDictionary.Create(_commandConfiguration.Items);
71-
_entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
72+
returnValue = _entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
7273
}
7374
else
7475
{
7576
ValidateCustomEntryPoint();
76-
_entryPoint.Method.Invoke(null, new object[] { _modelArguments });
77+
returnValue = _entryPoint.Method.Invoke(null, new object[] { _modelArguments });
7778
}
79+
return (CommandModelErrorCode) returnValue;
7880
}
7981

8082
/// <summary>

src/CLU/Microsoft.CLU.Run/IRunMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ internal interface IRunMode
1717
/// IRunMode implementation.
1818
/// </summary>
1919
/// <param name="arguments">The arguments</param>
20-
void Run(string[] arguments);
20+
Microsoft.CLU.CommandModelErrorCode Run(string[] arguments);
2121
}
2222
}

src/CLU/Microsoft.CLU.Run/PackageManagementMode.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public bool CanHandle(string[] arguments)
3333
/// IRunMode implementation for package managment.
3434
/// </summary>
3535
/// <param name="arguments">The arguments</param>
36-
public void Run(string[] arguments)
36+
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
3737
{
3838
_packagesRootPath = CLUEnvironment.GetPackagesRootPath();
3939
try
@@ -44,13 +44,13 @@ public void Run(string[] arguments)
4444
{
4545
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
4646
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
47-
return;
47+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
4848
}
4949
catch (Exception exc)
5050
{
5151
CLUEnvironment.Console.WriteErrorLine(exc.Message);
5252
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
53-
return;
53+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
5454
}
5555

5656
try
@@ -77,7 +77,7 @@ public void Run(string[] arguments)
7777
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
7878
{
7979
CLUEnvironment.Console.WriteLine(Strings.PackageManagementMode_Run_VersionIdMissing);
80-
return;
80+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
8181
}
8282
version = arguments[argsBase + 1];
8383
argsBase += 2;
@@ -145,12 +145,16 @@ public void Run(string[] arguments)
145145
{
146146
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
147147
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
148+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
148149
}
149150
catch (Exception exc)
150151
{
151152
CLUEnvironment.Console.WriteErrorLine(exc.Message);
152153
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
154+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
153155
}
156+
157+
return CommandModelErrorCode.Success;
154158
}
155159

156160
/// <summary>

src/CLU/Microsoft.CLU.Run/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace Microsoft.CLU.Run
1111
/// </summary>
1212
public class CLURun
1313
{
14+
public static void Main(string[] args) { }
15+
1416
/// <summary>
1517
/// Microsoft.CLU.Run (clurun.exe) main entry point.
1618
/// </summary>
1719
/// <param name="args">The commandline arguments</param>
18-
public static void Main(string[] args)
20+
public static Microsoft.CLU.CommandModelErrorCode Execute(string[] args)
1921
{
2022
CLUEnvironment.Console = new ConsoleInputOutput(args);
2123

@@ -24,28 +26,30 @@ public static void Main(string[] args)
2426
Stopwatch sw = Stopwatch.StartNew();
2527

2628
CLURun cluRun = new CLURun();
27-
cluRun.Parse(args);
29+
var result = cluRun.Parse(args);
2830

2931
sw.Stop();
3032
CLUEnvironment.Console.WriteDebugLine($"The command executed in {sw.ElapsedMilliseconds} ms");
33+
return result;
3134
}
3235
catch (Exception exc)
3336
{
3437
CLUEnvironment.Console.WriteErrorLine(exc.Message);
3538
CLUEnvironment.Console.WriteDebugLine(exc.StackTrace);
39+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
3640
}
3741
}
3842

3943
/// <summary>
4044
/// Parse the commandline argument and bootstrap the command execution.
4145
/// </summary>
4246
/// <param name="arguments">The commandline arguments</param>
43-
private void Parse(string [] arguments)
47+
private Microsoft.CLU.CommandModelErrorCode Parse(string [] arguments)
4448
{
4549
if (arguments.Count() == 0)
4650
{
4751
DisplayHelp();
48-
return;
52+
return CommandModelErrorCode.MissingParameters;
4953
}
5054

5155
var mode = GetMode(arguments);
@@ -55,7 +59,7 @@ private void Parse(string [] arguments)
5559
CLUEnvironment.SetRootPaths(rootPath);
5660

5761
// Run the command.
58-
mode.Run(arguments);
62+
return mode.Run(arguments);
5963
}
6064

6165

0 commit comments

Comments
 (0)