Skip to content

Commit

Permalink
Add templates to testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Nov 9, 2021
1 parent d507bf2 commit 2970374
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 133 deletions.
6 changes: 5 additions & 1 deletion testing/Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ if ($ParallelCI) {
throw "One or more tests failed"
}
} elseif ($CI) {
if ($Path) {
$testFilePath = "$PSScriptRoot/$Path"
}
Write-Host "Invoking Pester to run tests from '$testFilePath'..."
$testResult = Invoke-Pester $testFilePath -Passthru -Output Detailed
$testResult | Export-JUnitReport -Path "$testFileDirectory/TestResults.xml"
$testName = Split-Path $testFilePath –leaf
$testResult | Export-JUnitReport -Path "$testFileDirectory/$testName.xml"
} else {
if ($Path) {
Write-Host "Invoking Pester to run tests from '$PSScriptRoot/$Path'"
Expand Down
156 changes: 24 additions & 132 deletions testing/pipeline/k8s-custom-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,138 +24,30 @@ stages:
EXTENSION_NAME: "k8s-extension"
EXTENSION_FILE_NAME: "k8s_extension"
jobs:
- job: K8sExtensionTestSuite
displayName: "Run the Test Suite"
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- bash: |
echo "Installing helm3"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh --version v3.6.3
echo "Installing kubectl"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
displayName: "Setup the VM with helm3 and kubectl"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
- bash: |
K8S_EXTENSION_VERSION=$(ls ${EXTENSION_FILE_NAME}* | cut -d "-" -f2)
echo "##vso[task.setvariable variable=K8S_EXTENSION_VERSION]$K8S_EXTENSION_VERSION"
cp * $(TEST_PATH)/bin
workingDirectory: $(CLI_REPO_PATH)/dist
displayName: "Copy the Built .whl to Extension Test Path"
- bash: |
RAND_STR=$RANDOM
AKS_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-aks"
ARC_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-arc"
JSON_STRING=$(jq -n \
--arg SUB_ID "$SUBSCRIPTION_ID" \
--arg RG "$RESOURCE_GROUP" \
--arg AKS_CLUSTER_NAME "$AKS_CLUSTER_NAME" \
--arg ARC_CLUSTER_NAME "$ARC_CLUSTER_NAME" \
--arg K8S_EXTENSION_VERSION "$K8S_EXTENSION_VERSION" \
'{subscriptionId: $SUB_ID, resourceGroup: $RG, aksClusterName: $AKS_CLUSTER_NAME, arcClusterName: $ARC_CLUSTER_NAME, extensionVersion: {"k8s-extension": $K8S_EXTENSION_VERSION, connectedk8s: "1.0.0"}}')
echo $JSON_STRING > settings.json
cat settings.json
workingDirectory: $(TEST_PATH)
displayName: "Generate a settings.json file"
- bash : |
echo "Downloading the kind script"
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
./kind create cluster
displayName: "Create and Start the Kind cluster"
- bash: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
displayName: "Upgrade az to latest version"
- task: AzureCLI@2
displayName: Bootstrap
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Bootstrap.ps1 -CI
workingDirectory: $(TEST_PATH)

- task: AzureCLI@2
displayName: Run the Test Suite Public Extensions Only
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -OnlyPublicTests -Type k8s-extension
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))

- task: AzureCLI@2
displayName: Run the Test Suite on Private + Public Extensions
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -Type k8s-extension
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'True'))

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/testing/test/results/*.xml'
failTaskOnFailedTests: true
condition: succeededOrFailed()

- task: AzureCLI@2
displayName: Cleanup
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Cleanup.ps1 -CI
workingDirectory: $(TEST_PATH)
condition: succeededOrFailed()

- template: ./templates/run-test.yml
parameters:
jobName: AzureDefender
path: ./test/extensions/public/AzureDefender.Tests.ps1
- template: ./templates/run-test.yml
parameters:
jobName: AzureMLKubernetes
path: ./test/extensions/public/AzureMLKubernetes.Tests.ps1
- template: ./templates/run-test.yml
parameters:
jobName: AzureMonitor
path: ./test/extensions/public/AzureMonitor.Tests.ps1
- template: ./templates/run-test.yml
parameters:
jobName: AzurePolicy
path: ./test/extensions/public/AzurePolicy.Tests.ps1
- template: ./templates/run-test.yml
parameters:
jobName: Cassandra
path: ./test/extensions/public/Cassandra.Tests.ps1
- template: ./templates/run-test.yml
parameters:
jobName: OpenServiceMesh
path: ./test/extensions/public/OpenServiceMesh.Tests.ps1
- job: BuildPublishExtension
pool:
vmImage: 'ubuntu-latest'
Expand Down
122 changes: 122 additions & 0 deletions testing/pipeline/templates/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
parameters:
jobName: ''
path: ''

jobs:
- job: ${{ parameters.jobName}}
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
echo "Installing helm3"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh --version v3.6.3
echo "Installing kubectl"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
displayName: "Setup the VM with helm3 and kubectl"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
- bash: |
K8S_EXTENSION_VERSION=$(ls ${EXTENSION_FILE_NAME}* | cut -d "-" -f2)
echo "##vso[task.setvariable variable=K8S_EXTENSION_VERSION]$K8S_EXTENSION_VERSION"
cp * $(TEST_PATH)/bin
workingDirectory: $(CLI_REPO_PATH)/dist
displayName: "Copy the Built .whl to Extension Test Path"
- bash: |
RAND_STR=$RANDOM
AKS_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-aks"
ARC_CLUSTER_NAME="${BASE_CLUSTER_NAME}-${RAND_STR}-arc"
JSON_STRING=$(jq -n \
--arg SUB_ID "$SUBSCRIPTION_ID" \
--arg RG "$RESOURCE_GROUP" \
--arg AKS_CLUSTER_NAME "$AKS_CLUSTER_NAME" \
--arg ARC_CLUSTER_NAME "$ARC_CLUSTER_NAME" \
--arg K8S_EXTENSION_VERSION "$K8S_EXTENSION_VERSION" \
'{subscriptionId: $SUB_ID, resourceGroup: $RG, aksClusterName: $AKS_CLUSTER_NAME, arcClusterName: $ARC_CLUSTER_NAME, extensionVersion: {"k8s-extension": $K8S_EXTENSION_VERSION, connectedk8s: "1.0.0"}}')
echo $JSON_STRING > settings.json
cat settings.json
workingDirectory: $(TEST_PATH)
displayName: "Generate a settings.json file"
- bash : |
echo "Downloading the kind script"
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
./kind create cluster
displayName: "Create and Start the Kind cluster"
- bash: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
displayName: "Upgrade az to latest version"
- task: AzureCLI@2
displayName: Bootstrap
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Bootstrap.ps1 -CI
workingDirectory: $(TEST_PATH)

- task: AzureCLI@2
displayName: Run the Test Suite for ${{ parameters.path }}
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -Path ${{ parameters.path }} -Type k8s-extension
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/testing/results/*.xml'
failTaskOnFailedTests: true
condition: succeededOrFailed()

- task: AzureCLI@2
displayName: Cleanup
inputs:
azureSubscription: AzureResourceConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Cleanup.ps1 -CI
workingDirectory: $(TEST_PATH)
condition: succeededOrFailed()

0 comments on commit 2970374

Please sign in to comment.