Skip to content

Clu #309

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 13 commits into from
Jan 8, 2016
Merged

Clu #309

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
2 changes: 1 addition & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
DependsOnTargets="Build;Test" >
<Exec Command="$(LibraryToolsFolder)\CLU\BuildAndInstallClu.bat" />
<!--do a simple verification-->
<Exec Command="$(LibraryRoot)drop\clurun\win7-x64\azure.bat help" />
<Exec Command="$(LibraryRoot)drop\clurun\win7-x64\az.bat help" />
</Target>

<Target Name="BuildMsBuildTask" DependsOnTargets="RestoreNugetPackages">
Expand Down
10 changes: 5 additions & 5 deletions examples/compute-management/01-VirtualMachineSizes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ set -e
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"

printf "\n1. Showing VM size results in location: %s.\n" "$location"
azure vmsize get --location "$location"
az vmsize get --location "$location"

printf "\n2. Checking VM size results in location: %s.\n" "$location"
vmSizeResult=`azure vmsize get --location "$location"`
vmSizeResult=`az vmsize get --location "$location"`

if [[ $vmSizeResult == "" ]]; then
echo "Failure: No VM sizes!" 1>&2
Expand All @@ -15,23 +15,23 @@ else
echo "Success: Non-empty Results."
fi

filterResult=`azure vmsize get --location "$location" | cat | jq 'select(.name | contains("Standard_A0"))' --raw-output`
filterResult=`az vmsize get --location "$location" | cat | jq 'select(.name | contains("Standard_A0"))' --raw-output`
if [[ "$filterResult" == "" ]]; then
echo "Failure: Standard_A0 vm size not found." 1>&2
exit 1
else
echo "Success: Standard_A0 vm size found."
fi

filterResult=`azure vmsize get --location "$location" | cat | jq 'select(.name | contains("Standard_G1"))' --raw-output`
filterResult=`az vmsize get --location "$location" | cat | jq 'select(.name | contains("Standard_G1"))' --raw-output`
if [[ "$filterResult" == "" ]]; then
echo "Failure: Standard_G1 vm size not found." 1>&2
exit 1
else
echo "Success: Standard_G1 vm size found."
fi

filterResult=`azure vmsize get --location "$location" | cat | jq 'select(.name | contains("NonStandard_A1"))' --raw-output`
filterResult=`az vmsize get --location "$location" | cat | jq 'select(.name | contains("NonStandard_A1"))' --raw-output`
if [[ "$filterResult" == "" ]]; then
echo "Success: NonStandard_A1 vm size not found."
else
Expand Down
14 changes: 7 additions & 7 deletions examples/compute-management/02-VirtualMachineCreation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ set -e
printf "\n=== Managing Virtual Machine Creation in Azure Compute ===\n"

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

printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
azure storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
az storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"

printf "\n3. Create virtual network.\n"
result=`azure virtual network new --resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`
result=`az virtual network new --resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`

contextResult=`azure context get`
contextResult=`az context get`

subId=`echo $contextResult | jq '.Subscription.SubscriptionId' --raw-output`

subnetId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/virtualNetworks/test/subnets/test"

printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnetId='$subnetId'.\n" "$subId"
export MSYS_NO_PATHCONV=1
azure network interface new --name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
az network interface new --name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
export MSYS_NO_PATHCONV=

nicId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/networkInterfaces/test"
Expand All @@ -30,7 +30,7 @@ vmStr="{\"Name\":\"test\",\"HardwareProfile\":{\"VmSize\":\"Standard_A1\"},\"Net

printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='%s'\r\nvmStr='%s'\n" "$nicId" "$vhdUri" "$vmStr"

azure vm new --resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
az vm new --resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"

printf "\n6. Removing resource group: %s.\n" "$groupName"
azure group remove -n "$groupName" -f
az group remove -n "$groupName" -f
2 changes: 1 addition & 1 deletion examples/lib/loginService.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
azure account add --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$spnSubscription"
az account add --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$spnSubscription"
2 changes: 1 addition & 1 deletion examples/lib/loginUser.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
azure account add -u "$azureUser" -p "$password" -s "$userSubscription"
az account add -u "$azureUser" -p "$password" -s "$userSubscription"
2 changes: 1 addition & 1 deletion examples/lib/testrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for d in $( ls $TESTDIR/.. --ignore=lib ); do
. $f
set +e
printf "\nCleanup: removing resource group: %s\n" $groupName
azure group remove --name "$groupName" --force
az group remove --name "$groupName" --force
set -e
echo "success: $f"
done
Expand Down
10 changes: 5 additions & 5 deletions examples/resource-management/01-ResourceGroups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ set -e
printf "\n=== Managing Resource Groups in Azure ===\n"

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

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

printf "\n3. Get information about resource group : %s.\n" "$groupName"
resourceGroupInfo=`azure group get -n $groupName`
resourceGroupInfo=`az group get -n $groupName`

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 group get
az group get

printf "\n5. Removing resource group: %s.\n" "$groupName"
azure group remove -n "$groupName" -f
az group remove -n "$groupName" -f
20 changes: 10 additions & 10 deletions examples/resource-management/02-Resource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ set -e
printf "\n=== Managing Resources in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"
az group create --name "$groupName" --location "$location"
destinationGroupName=$groupName"Destination"

printf "\n2. Registering Resource Provider Namespace.\n"
providerNamespace="Providers.Test"
azure resource provider register --ProviderNamespace $providerNamespace --Force
az resource provider register --ProviderNamespace $providerNamespace --Force

printf "\n3. Creating a new Resource: %s.\n" "$resourceName"
resourceType="$providerNamespace/statefulResources"
tags='[{"Name": "testtag", "Value": "testvalue"}]'
properties='{"administratorLogin": "adminuser", "administratorLoginPassword": "P@ssword1"}'
apiversion="2014-04-01"
azure resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force
az resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force

printf "\n4. Get information about Resource : %s.\n" "$resourceName"
resourceInfo=$(azure resource get -n $resourceName)
resourceInfo=$(az resource get -n $resourceName)
printf "\nValidating Resource name is: %s\n" "$resourceName"
[ $(echo $resourceInfo | jq '.Name' --raw-output) == "$resourceName" ]

printf "\n5. Find Resource with name '%s' and type '%s'.\n" "$resourceName" "$resourceType"
foundResource=$(azure resource find -n "$resourceName" -t $resourceType)
foundResource=$(az resource find -n "$resourceName" -t $resourceType)
printf "\nValidating Resource name is: %s.\n" "$resourceName"
[ $(echo $foundResource | jq '.Name' --raw-output) == "$resourceName" ]

printf "\n6. Update Resource.\n"
tagsUpdate='[{"Name": "testtagUpdated", "Value": "testvalueUpdated"}]'
azure resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f
az resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f

printf "\n7. Move Resource to resource group: %s.\n" "$destinationGroupName"
azure group create --name "$destinationGroupName" --location "$location"
az group create --name "$destinationGroupName" --location "$location"
resourceId=$(echo $resourceInfo | jq '.Id')
arrayId="[$resourceId]"
azure resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f
az resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f

printf "\n8. Removing resource: %s.\n" "$resourceName"
foundResource=$(azure resource find -n "$resourceName" -t $resourceType)
foundResource=$(az resource find -n "$resourceName" -t $resourceType)
resourceId=$(echo $foundResource | jq '.Id' --raw-output)
echo $resourceId
export MSYS_NO_PATHCONV=1
azure resource remove --Id "$resourceId" -f
az resource remove --Id "$resourceId" -f
export MSYS_NO_PATHCONV=
8 changes: 4 additions & 4 deletions examples/resource-management/03-Deployments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ set -e
printf "\n=== Provisioning Deployments in Azure ===\n"

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

printf "\n2. Test template with dynamic parameters\n"
azure group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --siteName "$resourceName" --hostingPlanName "$resourceName" --siteLocation "$location" --workerSize "0"
az group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --siteName "$resourceName" --hostingPlanName "$resourceName" --siteLocation "$location" --workerSize "0"

printf "\n3. Test template with JSON parameter object\n"
azure group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$resourceName\",\"hostingPlanName\":\"$resourceName\",\"siteLocation\":\"$location\",\"workerSize\": 0 }"
az group deployment test -g "$groupName" --templatefile $BASEDIR/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$resourceName\",\"hostingPlanName\":\"$resourceName\",\"siteLocation\":\"$location\",\"workerSize\": 0 }"

printf "\n4. Provisioning Deployment\n"
deploymentInfo=`azure group deployment create --Name "$resourceName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/sampleTemplate.json --TemplateParameterFile $BASEDIR/sampleTemplateParams.json`
deploymentInfo=`az group deployment create --Name "$resourceName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/sampleTemplate.json --TemplateParameterFile $BASEDIR/sampleTemplateParams.json`
echo $deploymentInfo
17 changes: 9 additions & 8 deletions examples/resource-management/04-RoleAssignments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ set -e
printf "\n=== Managing Role Assignments in Azure ===\n"

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

printf "\n2. Creating a new Role Assignment.\n"
export MSYS_NO_PATHCONV=1
users=$(azure ad users get)
users=$(az ad users get)
userId=$(echo $users | cat | jq '.[0].Id' -s --raw-output)
echo "UserID: $userId"
roleDefinitions=$(azure role definition get)
roleDefinitions=$(az role definition get)
roleDefinitionId=$(echo $roleDefinitions | cat | jq '.[0].Id' -s --raw-output)
echo "RoleDefinitionId: $roleDefinitionId"
subsciptions=$(azure subscription get)
subsciptions=$(az subscription get)
subscriptionId=$(echo $subsciptions | cat | jq '.[0].SubscriptionId' -s --raw-output)
scope="/subscriptions/$subscriptionId/resourceGroups/$groupName"
echo "Scope: $scope"
azure role assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefinitionId" --Scope "$scope"
az role assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefinitionId" --Scope "$scope"

printf "\n3. Delete last created Role Assignment.\n"
assignments=$(azure role assignment get)
assignmentId=$(echo $assignments | cat | jq '.[-1].ObjectId' -s --raw-output)
azure role assignment remove --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
assignments=$(az role assignment get)
assignmentId=$(echo $assignments | cat | jq '.[-1:][0].ObjectId' -s --raw-output)
echo "Deleting assignment: $assignmentId"
az role assignment remove --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
export MSYS_NO_PATHCONV=
10 changes: 5 additions & 5 deletions examples/resource-management/05-RoleDefinitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ set -e
printf "\n=== Managing Role Definitions in Azure ===\n"

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

printf "\n2. Creating a new Role Definition.\n"
roleDefinition=$(azure role definition create --inputfile $BASEDIR/roleDefinition.json)
roleDefinition=$(az role definition create --inputfile $BASEDIR/roleDefinition.json)

printf "\n3. Get information about Role Definitions.\n"
roleDefinitionName=$(echo $roleDefinition | jq '.Name' --raw-output)
azure role definition get -n $roleDefinitionName
az role definition get -n $roleDefinitionName

printf "\n4. Update Role Definition.\n"
export MSYS_NO_PATHCONV=1
updatedRoleDefinition=$(echo $roleDefinition | jq '.Actions |= .+ ["Microsoft.Authorization/*/write"]')
azure role definition set --Role "$updatedRoleDefinition"
az role definition set --Role "$updatedRoleDefinition"

printf "\n5. Delete Role Definition.\n"
roleDefinitionId=$(echo $roleDefinition | jq '.Id' --raw-output)
azure role definition remove --Id $roleDefinitionId --PassThru -f
az role definition remove --Id $roleDefinitionId --PassThru -f
export MSYS_NO_PATHCONV=
10 changes: 5 additions & 5 deletions examples/virtual-hard-disk/01-VirtualHardDisks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ set -e
printf "\n=== Managing Virtual Hard Disks in Azure Compute ===\n"

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

printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
azure storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
az storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"

printf "\n3. Uploading a virtual hard disk to: %s.\n" "$storageAccountName"
azure vhd add -o --resourcegroupname "$groupName" --destination https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath $BASEDIR/test.vhd
az vhd add -o --resourcegroupname "$groupName" --destination https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath $BASEDIR/test.vhd

printf "\n4. Downloading a virtual hard disk"
azure vhd save -o --resourcegroupname "$groupName" --sourceuri https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath ./test_downloaded_by_clu.vhd
az vhd save -o --resourcegroupname "$groupName" --sourceuri https://"$storageAccountName".blob.core.windows.net/test/test.vhd --localfilepath ./test_downloaded_by_clu.vhd

printf "\n5. Validating the downloaded file is the same.\n"
diffResult=`diff ./test_downloaded_by_clu.vhd $BASEDIR/test_uploaded_byps.vhd`
Expand All @@ -25,4 +25,4 @@ else
fi

printf "\n6. Removing resource group: %s.\n" "$groupName"
azure group remove -n "$groupName" -f
az group remove -n "$groupName" -f
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ComputeTests(ScenarioTestFixture fixture)
_collectionState = fixture;
}

[Fact]
[Fact (Skip = "TODO: Re-enable once fixed in Azure Storage CoreCLR package.")]
public void VirtualHardDisksTest()
{
var helper = _collectionState.GetRunner("virtual-hard-disk");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Xunit;

namespace Microsoft.Azure.Commands.Common.ScenarioTest
{
[Collection("SampleCollection")]
public class WebsitesTests
{
ScenarioTestFixture _collectionState;
public WebsitesTests(ScenarioTestFixture fixture)
{
_collectionState = fixture;
}

[Fact (Skip = "TODO: Work in progress")]
public void AppServicePlanTest()
{
var helper = _collectionState.GetRunner("webapp-management");
helper.RunScript("01-AppServicePlan");
}

[Fact(Skip = "TODO: Work in progress")]
public void WebAppSlotTest()
{
var helper = _collectionState.GetRunner("webapp-management");
helper.RunScript("02-WebAppSlot");
}

[Fact]
public void WebAppTest()
{
var helper = _collectionState.GetRunner("webapp-management");
helper.RunScript("03-WebApp");
}
}
}
5 changes: 3 additions & 2 deletions src/CLU/Microsoft.CLU.Run/PackageManagementMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ private static void GenerateScript(string cfgPath)
{
var scriptPath = GetScriptPath(cfgPath);
var scriptName = Path.GetFileNameWithoutExtension(scriptPath);
var ScriptBaseName = "az";

if (File.Exists(scriptPath))
return;
Expand All @@ -544,7 +545,7 @@ private static void GenerateScript(string cfgPath)
{
"#!/bin/bash",
"SCRIPTPATH=$(dirname \"$0\")",
$"$SCRIPTPATH/clurun -s {scriptName} -r $SCRIPTPATH/{Path.GetFileName(cfgPath)} \"$@\""
$"$SCRIPTPATH/clurun -s {ScriptBaseName} -r $SCRIPTPATH/{Path.GetFileName(cfgPath)} \"$@\""
});
System.Diagnostics.Process.Start("chmod", $"777 {scriptPath}");
}
Expand All @@ -553,7 +554,7 @@ private static void GenerateScript(string cfgPath)
File.WriteAllLines(scriptPath, new string[]
{
"@echo off",
$@"%~dp0\clurun.exe -s {scriptName} -r %~dp0\{Path.GetFileName(cfgPath)} %*"
$@"%~dp0\clurun.exe -s {ScriptBaseName} -r %~dp0\{Path.GetFileName(cfgPath)} %*"
});
}
}
Expand Down
Loading