Skip to content

Clu #94

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 40 commits into from
Dec 17, 2015
Merged

Clu #94

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5e46d26
Add commandlet project + first test commandlet
johanste Dec 10, 2015
778d435
Propagate error code from command line execution
johanste Dec 11, 2015
845a20e
Merge branch 'clu-pipline-alias-binding'
johanste Dec 11, 2015
51facfa
Plumb error codes through.
johanste Dec 11, 2015
5c3bb2d
Remove empty resx file
johanste Dec 11, 2015
d2bb078
Change tool version in CLUCoreCLR.sln to avoid merge conflict
johanste Dec 11, 2015
cc8a880
Merge from azure-powershell/clu branch
johanste Dec 14, 2015
901ad2d
Xunit test infra for CLU
markcowl Dec 15, 2015
9f244ff
dependency and rename fixes
markcowl Dec 15, 2015
5068aa1
Merge branch 'clu' of github.com:Azure/azure-powershell into cluoutput
markcowl Dec 15, 2015
4d51229
[#109999746] Removed "AzureDirectoryName" from Authentication resources.
Dec 15, 2015
d9d36b4
[#110124884] Investigate PSObject removal from resource cmdlets.
Dec 15, 2015
dc34da6
Removed PSObject from Resource Lock cmdlets.
Dec 16, 2015
3e60283
Added documentation for bash testing and updated testrunner.sh
stankovski Dec 16, 2015
fded323
Merge branch 'clu' of https://github.com/Azure/azure-powershell into …
stankovski Dec 16, 2015
f851c3e
excluded microsoft.clu.test project
stankovski Dec 16, 2015
52edc55
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
stankovski Dec 16, 2015
707b4b7
Merge branch 'johanc' of https://github.com/stankovski/azure-powershe…
stankovski Dec 16, 2015
29d5dc0
Removed PSObject from PolicyAssignment, PolicyDefinition and Resource…
Dec 16, 2015
2db5c9e
Merge pull request #1499 from stankovski/johanc
stankovski Dec 16, 2015
fce7376
Updating output format for Profile cmdlets
markcowl Dec 16, 2015
8048231
Merging cmdlet rename changes from upstream
markcowl Dec 16, 2015
e6ca066
Added copy of azure bash script to win output and added example of as…
stankovski Dec 16, 2015
240c89e
Merge pull request #1501 from stankovski/clu
markcowl Dec 16, 2015
b311f0a
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
huangpf Dec 16, 2015
a30581d
Update Tests
huangpf Dec 16, 2015
8d0190f
Update project.json
huangpf Dec 16, 2015
cf66893
Update Test project.json
huangpf Dec 16, 2015
c86c954
Merge pull request #1500 from huangpf/clu
markcowl Dec 16, 2015
4492a39
Removed powershell test.
Dec 16, 2015
de09a71
Merge pull request #1498 from hovsepm/clu
Dec 16, 2015
30ff134
use recommenedd coreconsole from https://github.com/dotnet/cli
yugangw-msft Dec 16, 2015
2f307a9
merge with the latest clu
yugangw-msft Dec 16, 2015
f313688
Merge pull request #1502 from markcowl/cluoutput
Dec 16, 2015
5eac2fc
remove unused azure file, rathe the nix version azure.sh is fine to r…
yugangw-msft Dec 16, 2015
f39bc05
remove no longer used consolehost package
yugangw-msft Dec 16, 2015
3a15637
Merge pull request #1509 from yugangw-msft/corehost
Dec 16, 2015
053deb6
replace build with dnu restore to improve build perf
yugangw-msft Dec 16, 2015
a3d1ee9
Merge pull request #1510 from yugangw-msft/forCI
yugangw-msft Dec 16, 2015
e870491
Merge pull request #253 from Azure/clu
huangpf Dec 17, 2015
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
2 changes: 1 addition & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
<Message Importance="high" Text="Running check in tests..." />
<ItemGroup>
<!--Exclude 1 test projects still in progress with build failures-->
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json">
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json" Exclude="$(CLURootDir)\Microsoft.CLU.Test\project.json">
</_CLUTestProjects>
</ItemGroup>
<Exec Command="dnu build" WorkingDirectory="%(_CLUTestProjects.RootDir)%(_CLUTestProjects.Directory)" />
Expand Down
33 changes: 33 additions & 0 deletions clu-getstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,36 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, you should se

```set CmdletSessionId=1010 ```

### Testing Cmdlets

#### Environment setup (Windows)
- Install latest version of [Git for Windows](https://git-scm.com/download/win) that has `bash 4.x` available.
- Install `jq` using chocolatey `choco install jq` (chocolatey can be installed from [here](https://chocolatey.org/)).

#### Test Infrastructure
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.

#### Scenario Tests
- 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.

##### Bash Tests
- Bash tests should be runnable from bash shell in windows/linux/mac environments.
- To manually run the tests; please set the following envt. variables for authentication and run `./examples/lib/testrunner.sh`
```bash
export azureuser=<[email protected]>
export azurepassword=<your_password>
export PATH=$PATH:/<path-to-drop>/clurun/win7-x64/
. /examples/lib/testrunner.sh
```
- All the parameters to the cmdlets should be passed in as envt. variables
- 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.
- The location for ARM will be provided via variable `$location`.
- "jq" package and BASH assert (e.g. `[ "foo" == "bar" ]`) should be used to validate the responses.

##### PowerShell Tests
TODO: Add section on PowerShell testing

#### Unit Tests
TODO: Add section on unit testing


2 changes: 2 additions & 0 deletions examples/lib/helper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

randomName() {
echo "$1$RANDOM"
}
Expand Down
19 changes: 15 additions & 4 deletions examples/lib/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash

# Login
echo "Executing Login..."
export CmdletSessionId=1010
azure account add --username $azureuser --password $azurepassword
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
18 changes: 12 additions & 6 deletions examples/lib/testrunner.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash
. setup.sh
. helper.sh
export resourceGroupName=`randomName testrg`
export resourceGroupLocation="westus"
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $BASEDIR/assert.sh
. $BASEDIR/helper.sh
. $BASEDIR/setup.sh
export groupName=`randomName testrg`
export location="westus"

for d in $( ls .. --ignore=lib ); do
for f in $( ls ../$d/*.sh ); do
login

for d in $( ls $BASEDIR/.. --ignore=lib ); do
for f in $( ls $BASEDIR/../$d/*.sh ); do
echo "running: $f"
. $f
cleanup
echo "success: $f"
done
done
24 changes: 13 additions & 11 deletions examples/resource-management/01-ResourceGroups.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

set -e
printf "\n=== Managing Resource Groups in Azure ===\n"

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

printf "\n2. Updating the group %s with tags.\n" "$groupName"
azure group set --name "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"

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

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

printf "\n4. Listing all resource groups in the subscription.\n"
azure resource group get
azure group get

printf "\n5. Removing resource group: %s.\n" "$resourceGroupName"
azure resource group remove --name "$resourceGroupName" --force
printf "\n5. Removing resource group: %s.\n" "$groupName"
azure group remove --name "$groupName" --force
6 changes: 6 additions & 0 deletions src/CLU/CLUCoreCLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Run", "Micros
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.CLU\Microsoft.CLU.xproj", "{D0A59671-088D-463B-B060-2ADAFFB9C3F6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
ProjectSection(ProjectDependencies) = postProject
{99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778}
Expand Down Expand Up @@ -127,6 +129,10 @@ Global
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.Build.0 = Release|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using System;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using Microsoft.Rest;
using System;
using System.Runtime.InteropServices;
using Commands.Common.Authentication.Properties;
using Microsoft.Rest.Azure.Authentication;
using System.Management.Automation;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,11 +16,10 @@
using System;
using System.Linq;
using System.Management.Automation;
using System.Security;
using Commands.Common.Authentication.Properties;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Factories
{
Expand Down
3 changes: 1 addition & 2 deletions src/CLU/Commands.Common.Authentication/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Factories
{
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Authentication/JsonUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.Collections.Generic;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down Expand Up @@ -372,7 +372,7 @@ public static class AzureEnvironmentConstants

public const string USGovernmentSqlDatabaseDnsSuffix = ".database.usgovcloudapi.net";

public const string AzureActiveDirectoryEndpoint = "https://login.windows.net/";
public const string AzureActiveDirectoryEndpoint = "https://login.microsoftonline.com/";

public const string ChinaActiveDirectoryEndpoint = "https://login.chinacloudapi.cn/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Rest;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
<data name="AccountNeedsToBeSpecified" xml:space="preserve">
<value>Account needs to be specified</value>
</data>
<data name="AzureDirectoryName" xml:space="preserve">
<value>Windows Azure Powershell</value>
</data>
<data name="CertificateNotFoundInStore" xml:space="preserve">
<value>No certificate was found in the certificate store with thumbprint {0}</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Authentication/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.IO;
using System.Linq;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
12 changes: 3 additions & 9 deletions src/CLU/Commands.Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,11 @@ protected virtual void WriteExceptionError(Exception ex)
WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.CloseError, null));
}

protected PSObject ConstructPSObject(string typeName, params object[] args)
protected PSObject ConstructPSObject(params object[] args)
{
return PowerShellUtilities.ConstructPSObject(typeName, args);
return PowerShellUtilities.ConstructPSObject(args);
}

protected void SafeWriteOutputPSObject(string typeName, params object[] args)
{
PSObject customObject = this.ConstructPSObject(typeName, args);
WriteObject(customObject);
}


private void FlushDebugMessages(bool record = false)
{
if (record)
Expand Down
9 changes: 9 additions & 0 deletions src/CLU/Commands.Common/Models/PSAzureContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,14 @@ public static implicit operator AzureContext(PSAzureContext context)
public PSAzureTenant Tenant { get; set; }

public byte[] TokenCache { get; set; }

public override string ToString()
{
var account = Account != null ? Account.Id : string.Empty;
var subscription = Subscription != null ? Subscription.SubscriptionId : string.Empty;
var tenant = Tenant != null ? Tenant.TenantId : string.Empty;
var environment = Environment != null ? Environment.Name : EnvironmentName.AzureCloud;
return $"{{Account: {account}, Subscription: {subscription}, Tenant: {tenant}, Environment: {environment}}}";
}
}
}
5 changes: 5 additions & 0 deletions src/CLU/Commands.Common/Models/PSAzureProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public IDictionary<string, PSAzureEnvironment> Environments
get { return _env; }
}

public string EnvironmentNames
{
get { return _env == null? null : $"{string.Join(", ", _env.Keys.ToArray())}"; }
}

/// <summary>
/// The current credentials and metadata for connecting with the current Azure cloud instance.
/// </summary>
Expand Down
9 changes: 2 additions & 7 deletions src/CLU/Commands.Common/PowerShellUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ private static void ChangeForTargetEnvironment(Func<IEnumerable<string>, IEnumer
}
}

public static PSObject ConstructPSObject(string typeName, params object[] args)
public static PSObject ConstructPSObject(params object[] args)
{
Debug.Assert(args.Length % 2 == 0, "The parameter args length must be even number");

PSObject outputObject = new PSObject();

if (!string.IsNullOrEmpty(typeName))
{
outputObject.TypeNames.Add(typeName);
}


for (int i = 0, j = 0; i < args.Length / 2; i++, j += 2)
{
outputObject.Properties.Add(new PSNoteProperty(args[j].ToString(), args[j + 1]));
Expand Down
Loading