forked from Azure/iotedge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate Vm Creation for Nested E2E (Azure#4299)
Automate Vm Creation for Nested E2E: - Create Azure VM with Ubuntu image - Install E2E dependencies - Enroll itself on test agent pool
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
function Create-Azure-VM-For-E2E-Test | ||
{ | ||
[CmdletBinding()] | ||
param ( | ||
<# VM Name #> | ||
[Parameter(Mandatory)] | ||
[string] | ||
$VmName, | ||
|
||
<# Azure VM Location. The supported locations are 'eastus, eastus2, westus, centralus, northcentralus, | ||
southcentralus, northeurope, westeurope, eastasia, southeastasia, japaneast, japanwest, australiaeast, | ||
australiasoutheast, australiacentral, brazilsouth, southindia, centralindia, westindia, canadacentral, | ||
canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, | ||
southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast' #> | ||
[Parameter(Mandatory)] | ||
[string] | ||
$VmRegion, | ||
|
||
<# Azure Resource Group #> | ||
[Parameter(Mandatory)] | ||
[string] | ||
$ResourceGroup, | ||
|
||
<# VSTS Personal Access Token to be used in the test agent enrollment #> | ||
[Parameter(Mandatory)] | ||
[string] | ||
$VstsToken | ||
) | ||
|
||
# Future Iteration: | ||
# A complete version to do the VM creation is to do the following | ||
# 1. Query VSTS to see what's the current index for the test agent there is | ||
# 2. Name the test agent after that prefix + however many to be created | ||
# 3. Download the nestedEdge RootCA cert | ||
# 4. Create the VM using the same RootCA cert | ||
# 4.1 If fail, move over to the next region from the region list | ||
# 5. Download the dependency script | ||
# 6. Run the dependency script | ||
# 7. Download the VSTS agent | ||
# 8. Have user go in an install the VSTS agent | ||
# 9. Can we automate (8)? | ||
|
||
# Current version: | ||
# For this miniature version, we can do | ||
# A. Take the VmName | ||
# B. Download the cert somewhere | ||
# C. Call AzCli to create the VM with cert | ||
# D. Install dependencies for E2E | ||
# E. Install software for VSTS test agent. | ||
|
||
# Pre-requ: Install the Azure CLI & azure login | ||
#Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet' | ||
#az login | ||
|
||
$AdminUsername="iotedgeuser"; | ||
# Fetch default subscription | ||
$AzSubscriptionName=$(az account show --query 'name' -o tsv) | ||
echo "Azure Subscription: $AzSubscriptionName `n" | ||
|
||
$VmName=$($VmName -replace '[\W_]', ''); | ||
|
||
# The public key was generated from private key using : ssh-keygen -f <Path/To/PrivateKey> -y | ||
$VmPubKey=$(az keyvault secret show --vault-name nestededgeVMkeys --name nestededgePubkey --query value); | ||
# Get ride of the " at the begging and " at the end along with an extra \n | ||
$VmPubKey = $VmPubKey.substring(1, $VmPubKey.length-4); | ||
|
||
# Ref: https://docs.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az_vm_create | ||
# For more --image : az vm image list --output table | ||
az vm create ` | ||
--name "$VmName" ` | ||
--resource-group "$ResourceGroup" ` | ||
--subscription "$AzSubscriptionName" ` | ||
--accelerated-networking false ` | ||
--authentication-type ssh ` | ||
--admin-username "$AdminUsername" ` | ||
--ssh-key-values "$VmPubKey" ` | ||
--image 'Canonical:UbuntuServer:18.04-LTS:latest' ` | ||
--size 'Standard_D4s_v3' ` | ||
--location "$VmRegion" | ||
|
||
# Install necessary E2E dependency | ||
az vm extension set ` | ||
--resource-group "$ResourceGroup" ` | ||
--vm-name "$VmName" ` | ||
--name customScript ` | ||
--publisher Microsoft.Azure.Extensions ` | ||
--protected-settings '{""fileUris"": [""https://iotedgeforiiot.blob.core.windows.net/edge-config-scripts/e2eOneTimeDependencySetup.sh""],""commandToExecute"": ""./e2eOneTimeDependencySetup.sh;""}' ` | ||
--output none | ||
|
||
# Other setup command | ||
# - Set AdminUsername to docker group | ||
# - Download the VSTS test agent zip to be used. | ||
# - Extract the VSTS test agent | ||
$AdditionalSetupCommand="sudo usermod -aG docker $AdminUsername;" | ||
$AdditionalSetupCommand+="sudo usermod -aG users iotedge;" | ||
$AdditionalSetupCommand+="sudo usermod -aG root iotedge;" | ||
$AdditionalSetupCommand+="cd /home/$AdminUsername;" | ||
$AdditionalSetupCommand+="mkdir myagent && cd myagent;" | ||
$AdditionalSetupCommand+="wget https://vstsagentpackage.azureedge.net/agent/2.174.2/vsts-agent-linux-x64-2.174.2.tar.gz;" | ||
$AdditionalSetupCommand+="tar zxvf ./vsts-agent-linux-x64-2.174.2.tar.gz;" | ||
$AdditionalSetupCommand+="sudo chown -R $AdminUsername . ;" | ||
|
||
# Enroll the test VM into the pool | ||
$SubCommand="sudo -u $AdminUsername ./config.sh --unattended --url https://dev.azure.com/msazure --auth pat --token $VstsToken --pool Azure-IoT-Edge-Core --agent $VmName" | ||
$AdditionalSetupCommand+="bash -c '$SubCommand';" | ||
$AdditionalSetupCommand+="./svc.sh install;" | ||
$AdditionalSetupCommand+="./svc.sh start;" | ||
|
||
az vm run-command invoke ` | ||
-g $ResourceGroup ` | ||
-n $VmName ` | ||
--command-id RunShellScript ` | ||
--scripts "$AdditionalSetupCommand" ` | ||
--output none | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
# This uses to setup the VM with prerequisite softwares to run E2E tests. | ||
mkdir ~/setup | ||
cd ~/setup | ||
|
||
# Install dotnet3.1 core runtime ( https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu ) | ||
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb | ||
sudo dpkg -i packages-microsoft-prod.deb | ||
|
||
sudo apt-get update; \ | ||
sudo apt-get install -y moby-engine moby-cli | ||
|
||
sudo apt-get update; \ | ||
sudo apt-get install -y apt-transport-https && \ | ||
sudo apt-get update && \ | ||
sudo apt-get install -y dotnet-sdk-3.1 | ||
|
||
sudo apt-get update; \ | ||
sudo apt-get install -y apt-transport-https && \ | ||
sudo apt-get update && \ | ||
sudo apt-get install -y aspnetcore-runtime-3.1 | ||
|
||
# Install Powershell ( https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7 ) | ||
sudo apt-get update; \ | ||
sudo add-apt-repository universe && \ | ||
sudo apt-get install -y powershell | ||
|
||
# Install Azure CLI ( https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest ) | ||
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash | ||
az extension add --name azure-iot |