diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 7a9dfa0..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "pwa-chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://localhost:8080", - "webRoot": "${workspaceFolder}" - } - ] -} \ No newline at end of file diff --git a/testsuite/k8s-conformance-test-suite.ps1 b/testsuite/k8s-conformance-test-suite.ps1 index cdce7f4..1148166 100644 --- a/testsuite/k8s-conformance-test-suite.ps1 +++ b/testsuite/k8s-conformance-test-suite.ps1 @@ -1,90 +1,90 @@ -# Set the following environment variables to run the test suite - -# Common Variables -# Some of the variables need to be populated from the service principal and storage account details provided to you by Microsoft -$connectedClustedId=-join (((48..57)+(65..90)+(97..122)) * 80 |Get-Random -Count 7 |%{[char]$_}) -$AZ_TENANT_ID="" # tenant field of the service principal, please add it within the quotes -$AZ_SUBSCRIPTION_ID="" # subscription id of the azure subscription (will be provided), please add it within the quotes -$AZ_CLIENT_ID="" # appid field of the service principal, please add it within the quotes -$AZ_CLIENT_SECRET="" # password field of the service principal, please add it within the quotes -$AZ_STORAGE_ACCOUNT="" # name of your storage account, please add it within the quotes (will be provided) -$AZ_STORAGE_ACCOUNT_SAS="`"`"" # sas token for your storage account, please replace with the actual value (will be provided) -$RESOURCE_GROUP="" # resource group name; set this to the resource group provided to you; please add it within the quotes (will be provided) -$OFFERING_NAME="" # name of the partner offering; use this variable to distinguish between the results tar for different offerings -$CLUSTERNAME="arc-partner-test"+$connectedClustedId # name of the arc connected cluster -$LOCATION="eastus" # location of the arc connected cluster - -# Platform Cleanup Plugin -$CLEANUP_TIMEOUT=1500 # time in seconds after which the platform cleanup plugin times out - -# In case your cluster is behind an outbound proxy, please add the following environment variables in the below command -# --plugin-env azure-arc-platform.HTTPS_PROXY="http://:" -# --plugin-env azure-arc-platform.HTTP_PROXY="http://:" -# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc," - -# In case your outbound proxy is setup with certificate authentication, follow the below steps: -# Create a Kubernetes generic secret with the name sonobuoy-proxy-cert with key proxycert in any namespace: -# kubectl create secret generic sonobuoy-proxy-cert --from-file=proxycert= -# By default we check for the secret in the default namespace. In case you have created the secret in some other namespace, please add the following variables in the sonobuoy run command: -# --plugin-env azure-arc-platform.PROXY_CERT_NAMESPACE="" -# --plugin-env azure-arc-agent-cleanup.PROXY_CERT_NAMESPACE="namespace of sonobuoy secret" - -az login --service-principal --username $AZ_CLIENT_ID --password $AZ_CLIENT_SECRET --tenant $AZ_TENANT_ID -az account set -s $AZ_SUBSCRIPTION_ID - - -$arc_platform_version = Get-Content -Path @("aak8sSupportPolicy.txt") - -foreach($version in $arc_platform_version) -{ - Write-Host "Running the test suite for Arc for Kubernetes version: ${version}" - - sonobuoy run --wait ` - --plugin arc-k8s-platform/platform.yaml ` - --plugin-env azure-arc-platform.TENANT_ID=$AZ_TENANT_ID ` - --plugin-env azure-arc-platform.SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID ` - --plugin-env azure-arc-platform.RESOURCE_GROUP=$RESOURCE_GROUP ` - --plugin-env azure-arc-platform.CLUSTER_NAME=$CLUSTERNAME ` - --plugin-env azure-arc-platform.LOCATION=$LOCATION ` - --plugin-env azure-arc-platform.CLIENT_ID=$AZ_CLIENT_ID ` - --plugin-env azure-arc-platform.CLIENT_SECRET=$AZ_CLIENT_SECRET ` - --plugin arc-k8s-platform/cleanup.yaml ` - --plugin-env azure-arc-platform.HELMREGISTRY=mcr.microsoft.com/azurearck8s/batch1/stable/azure-arc-k8sagents:$version ` - --plugin-env azure-arc-agent-cleanup.TENANT_ID=$AZ_TENANT_ID ` - --plugin-env azure-arc-agent-cleanup.SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID ` - --plugin-env azure-arc-agent-cleanup.RESOURCE_GROUP=$RESOURCE_GROUP ` - --plugin-env azure-arc-agent-cleanup.CLUSTER_NAME=$CLUSTERNAME ` - --plugin-env azure-arc-agent-cleanup.CLEANUP_TIMEOUT=$CLEANUP_TIMEOUT ` - --plugin-env azure-arc-agent-cleanup.CLIENT_ID=$AZ_CLIENT_ID ` - --plugin-env azure-arc-agent-cleanup.CLIENT_SECRET=$AZ_CLIENT_SECRET - - Write-Host "Test execution completed..Retrieving results" - - $sonobuoyResults=$(sonobuoy retrieve) - - sonobuoy results $sonobuoyResults - - New-Item -Path . -Name "results" -ItemType "directory" - Move-Item -Path $sonobuoyResults -Destination results\$sonobuoyResults - - Copy-Item .\partner-metadata.md -Destination results\partner-metadata.md - - tar -czvf conformance-results-$version.tar.gz results - - Remove-Item .\results -Recurse - - Write-Host "Publishing results.." - - $versionArry=$version.Split(".") - - $containerString="conformance-results-major-"+$versionArry[0]+"-minor-"+$versionArry[1]+"-patch-"+$versionArry[2] - - az storage container create -n $containerString --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS - az storage blob upload --file conformance-results-$version.tar.gz --name conformance-results-$OFFERING_NAME.tar.gz --container-name $containerString --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS - - Write-Host "Cleaning the cluster.." - sonobuoy delete --wait - - Write-Host "Buffer wait 5 minutes.." - Start-Sleep -s 300 -} +# Set the following environment variables to run the test suite + +# Common Variables +# Some of the variables need to be populated from the service principal and storage account details provided to you by Microsoft +$connectedClustedId=-join (((48..57)+(65..90)+(97..122)) * 80 |Get-Random -Count 7 |%{[char]$_}) +$AZ_TENANT_ID="" # tenant field of the service principal, please add it within the quotes +$AZ_SUBSCRIPTION_ID="" # subscription id of the azure subscription (will be provided), please add it within the quotes +$AZ_CLIENT_ID="" # appid field of the service principal, please add it within the quotes +$AZ_CLIENT_SECRET="" # password field of the service principal, please add it within the quotes +$AZ_STORAGE_ACCOUNT="" # name of your storage account, please add it within the quotes (will be provided) +$AZ_STORAGE_ACCOUNT_SAS="`"`"" # sas token for your storage account, please replace with the actual value (will be provided) +$RESOURCE_GROUP="" # resource group name; set this to the resource group provided to you; please add it within the quotes (will be provided) +$OFFERING_NAME="" # name of the partner offering; use this variable to distinguish between the results tar for different offerings +$CLUSTERNAME="arc-partner-test"+$connectedClustedId # name of the arc connected cluster +$LOCATION="eastus" # location of the arc connected cluster + +# Platform Cleanup Plugin +$CLEANUP_TIMEOUT=1500 # time in seconds after which the platform cleanup plugin times out + +# In case your cluster is behind an outbound proxy, please add the following environment variables in the below command +# --plugin-env azure-arc-platform.HTTPS_PROXY="http://:" +# --plugin-env azure-arc-platform.HTTP_PROXY="http://:" +# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc," + +# In case your outbound proxy is setup with certificate authentication, follow the below steps: +# Create a Kubernetes generic secret with the name sonobuoy-proxy-cert with key proxycert in any namespace: +# kubectl create secret generic sonobuoy-proxy-cert --from-file=proxycert= +# By default we check for the secret in the default namespace. In case you have created the secret in some other namespace, please add the following variables in the sonobuoy run command: +# --plugin-env azure-arc-platform.PROXY_CERT_NAMESPACE="" +# --plugin-env azure-arc-agent-cleanup.PROXY_CERT_NAMESPACE="namespace of sonobuoy secret" + +az login --service-principal --username $AZ_CLIENT_ID --password $AZ_CLIENT_SECRET --tenant $AZ_TENANT_ID +az account set -s $AZ_SUBSCRIPTION_ID + + +$arc_platform_version = Get-Content -Path @("aak8sSupportPolicy.txt") + +foreach($version in $arc_platform_version) +{ + Write-Host "Running the test suite for Arc for Kubernetes version: ${version}" + + sonobuoy run --wait ` + --plugin arc-k8s-platform/platform.yaml ` + --plugin-env azure-arc-platform.TENANT_ID=$AZ_TENANT_ID ` + --plugin-env azure-arc-platform.SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID ` + --plugin-env azure-arc-platform.RESOURCE_GROUP=$RESOURCE_GROUP ` + --plugin-env azure-arc-platform.CLUSTER_NAME=$CLUSTERNAME ` + --plugin-env azure-arc-platform.LOCATION=$LOCATION ` + --plugin-env azure-arc-platform.CLIENT_ID=$AZ_CLIENT_ID ` + --plugin-env azure-arc-platform.CLIENT_SECRET=$AZ_CLIENT_SECRET ` + --plugin arc-k8s-platform/cleanup.yaml ` + --plugin-env azure-arc-platform.HELMREGISTRY=mcr.microsoft.com/azurearck8s/batch1/stable/azure-arc-k8sagents:$version ` + --plugin-env azure-arc-agent-cleanup.TENANT_ID=$AZ_TENANT_ID ` + --plugin-env azure-arc-agent-cleanup.SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID ` + --plugin-env azure-arc-agent-cleanup.RESOURCE_GROUP=$RESOURCE_GROUP ` + --plugin-env azure-arc-agent-cleanup.CLUSTER_NAME=$CLUSTERNAME ` + --plugin-env azure-arc-agent-cleanup.CLEANUP_TIMEOUT=$CLEANUP_TIMEOUT ` + --plugin-env azure-arc-agent-cleanup.CLIENT_ID=$AZ_CLIENT_ID ` + --plugin-env azure-arc-agent-cleanup.CLIENT_SECRET=$AZ_CLIENT_SECRET + + Write-Host "Test execution completed..Retrieving results" + + $sonobuoyResults=$(sonobuoy retrieve) + + sonobuoy results $sonobuoyResults + + New-Item -Path . -Name "results" -ItemType "directory" + Move-Item -Path $sonobuoyResults -Destination results\$sonobuoyResults + + Copy-Item .\partner-metadata.md -Destination results\partner-metadata.md + + tar -czvf conformance-results-$version.tar.gz results + + Remove-Item .\results -Recurse + + Write-Host "Publishing results.." + + $versionArry=$version.Split(".") + + $containerString="conformance-results-major-"+$versionArry[0]+"-minor-"+$versionArry[1]+"-patch-"+$versionArry[2] + + az storage container create -n $containerString --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS + az storage blob upload --file conformance-results-$version.tar.gz --name conformance-results-$OFFERING_NAME.tar.gz --container-name $containerString --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS + + Write-Host "Cleaning the cluster.." + sonobuoy delete --wait + + Write-Host "Buffer wait 5 minutes.." + Start-Sleep -s 300 +} diff --git a/testsuite/k8s-conformance-test-suite.py b/testsuite/k8s-conformance-test-suite.py new file mode 100644 index 0000000..13c41ae --- /dev/null +++ b/testsuite/k8s-conformance-test-suite.py @@ -0,0 +1,126 @@ +# Set the following environment variables to run the test suite + +# Common Variables +# Some of the variables need to be populated from the service principal and storage account details provided to you by Microsoft + +import random +import string +import os +import subprocess +import shutil +import tarfile + +from azure.mgmt.resource import SubscriptionClient +from azure.identity import ClientSecretCredential +from azure.storage.blob import ContainerClient + +connectedClustedId = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 7)) + +AZ_TENANT_ID="" # tenant field of the service principal, please add it within the quotes +AZ_SUBSCRIPTION_ID="" # subscription id of the azure subscription (will be provided), please add it within the quotes +AZ_CLIENT_ID="" # appid field of the service principal, please add it within the quotes +AZ_CLIENT_SECRET="" # password field of the service principal, please add it within the quotes +AZ_STORAGE_ACCOUNT="" # name of your storage account, please add it within the quotes +AZ_STORAGE_ACCOUNT_SAS="" # sas token for your storage account, please replace with the actual value +RESOURCE_GROUP="" # resource group name; set this to the resource group provided to you; please add it within the quotes +OFFERING_NAME="" # name of the partner offering; use this variable to distinguish between the results tar for different offerings +CLUSTERNAME="arc-partner-test"+connectedClustedId # name of the arc connected cluster +LOCATION="eastus" # location of the arc connected cluster + +# Platform Cleanup Plugin +CLEANUP_TIMEOUT=1500 # time in seconds after which the platform cleanup plugin times out + +# In case your cluster is behind an outbound proxy, please add the following environment variables in the below command +# --plugin-env azure-arc-platform.HTTPS_PROXY="http://:" +# --plugin-env azure-arc-platform.HTTP_PROXY="http://:" +# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc," + +# In case your outbound proxy is setup with certificate authentication, follow the below steps: +# Create a Kubernetes generic secret with the name sonobuoy-proxy-cert with key proxycert in any namespace: +# kubectl create secret generic sonobuoy-proxy-cert --from-file=proxycert= +# By default we check for the secret in the default namespace. In case you have created the secret in some other namespace, please add the following variables in the sonobuoy run command: +# --plugin-env azure-arc-platform.PROXY_CERT_NAMESPACE="" +# --plugin-env azure-arc-agent-cleanup.PROXY_CERT_NAMESPACE="namespace of sonobuoy secret" + +credential = ClientSecretCredential(tenant_id=AZ_TENANT_ID, client_id=AZ_CLIENT_ID, client_secret=AZ_CLIENT_SECRET) + +subscription_client = SubscriptionClient(credential) + +subscription = next(subscription_client.subscriptions.list()) +print(subscription.subscription_id) + +def make_tarfile(output_filename, source_dir): + with tarfile.open(output_filename, "w:gz") as tar: + tar.add(source_dir, arcname=os.path.basename(source_dir)) + +optputFolderName = "results" +with open("testsuite/aak8sSupportPolicy.txt", "r") as f: + arc_platform_version = [line.rstrip() for line in f] + +print(arc_platform_version) + +for version in arc_platform_version: + print("Running the test suite for Arc for Kubernetes version:",version ) + + sonobuoyRunCommand = f'sonobuoy run --wait ' \ + '--plugin testsuite/arc-k8s-platform/platform.yaml ' \ + '--plugin-env azure-arc-platform.TENANT_ID={AZ_TENANT_ID} ' \ + '--plugin-env azure-arc-platform.SUBSCRIPTION_ID={AZ_SUBSCRIPTION_ID} ' \ + '--plugin-env azure-arc-platform.RESOURCE_GROUP={RESOURCE_GROUP} ' \ + '--plugin-env azure-arc-platform.CLUSTER_NAME={CLUSTERNAME} ' \ + '--plugin-env azure-arc-platform.LOCATION={LOCATION} ' \ + '--plugin-env azure-arc-platform.CLIENT_ID={AZ_CLIENT_ID} ' \ + '--plugin-env azure-arc-platform.CLIENT_SECRET={AZ_CLIENT_SECRET} ' \ + '--plugin-env azure-arc-platform.HELMREGISTRY=mcr.microsoft.com/azurearck8s/batch1/stable/azure-arc-k8sagents:{version} ' \ + '--plugin testsuite/arc-k8s-platform/cleanup.yaml ' \ + '--plugin-env azure-arc-agent-cleanup.TENANT_ID={AZ_TENANT_ID} ' \ + '--plugin-env azure-arc-agent-cleanup.SUBSCRIPTION_ID={AZ_SUBSCRIPTION_ID} ' \ + '--plugin-env azure-arc-agent-cleanup.RESOURCE_GROUP={RESOURCE_GROUP} ' \ + '--plugin-env azure-arc-agent-cleanup.CLUSTER_NAME={CLUSTERNAME} ' \ + '--plugin-env azure-arc-agent-cleanup.CLEANUP_TIMEOUT={CLEANUP_TIMEOUT} ' \ + '--plugin-env azure-arc-agent-cleanup.CLIENT_ID={AZ_CLIENT_ID} ' \ + '--plugin-env azure-arc-agent-cleanup.CLIENT_SECRET={AZ_CLIENT_SECRET}' + + print("Test execution completed..Retrieving results") + + sonobuoyRunCommandResult = subprocess.run(sonobuoyRunCommand,shell=True) + + sonobuoyretrieveCommand = "sonobuoy retrieve" + sonobuoyresultFile = subprocess.run(sonobuoyretrieveCommand,shell=True, capture_output=True, text=True).stdout.strip("\n") + + sonobuoyResultsCommand = f"sonobuoy results {sonobuoyresultFile}" + sonobuoyResultsCommandResult = subprocess.run(sonobuoyResultsCommand,shell=True) + + os.makedirs(optputFolderName) + shutil.move(sonobuoyresultFile, optputFolderName) + shutil.copy("testsuite/partner-metadata.md",optputFolderName) + tarFileName = f"conformance-results-{version}.tar.gz" + make_tarfile(tarFileName,optputFolderName) + shutil.rmtree(optputFolderName) + + print("Publishing results..") + versionArry = version.split('.') + + containerString = f"conformance-results-major-{versionArry[0]}-minor-{versionArry[1]}-patch-{versionArry[2]}" + + sas_url = f"https://{AZ_STORAGE_ACCOUNT}.blob.core.windows.net/{containerString}{AZ_STORAGE_ACCOUNT_SAS}" + container = ContainerClient.from_container_url(sas_url) + + if not container.exists(): + container.create_container() + + blobName = f"conformance-results-{OFFERING_NAME}.tar.gz" + + blob_client = container.get_blob_client(blobName) + # Upload the created file + with open(tarFileName, "rb") as data: + blob_client.upload_blob(data,blob_type="BlockBlob") + + print("Cleaning the cluster..") + + subprocess.run("sonobuoy delete --wait",shell=True) + + + + + \ No newline at end of file diff --git a/testsuite/running-tests.md b/testsuite/running-tests.md index db9e49c..47f7fd3 100644 --- a/testsuite/running-tests.md +++ b/testsuite/running-tests.md @@ -10,6 +10,7 @@ This document will enumerate everything you need to do run the sonobuoy based co 3. Address the [network requirements](https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster#meet-network-requirements) on your cluster for the Arc agents to communicate with Azure. 4. Download and install [git](https://git-scm.com/downloads). 5. Download and install [az cli](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). +6. Download and install [python](https://www.python.org/downloads/) and [pip](https://packaging.python.org/tutorials/installing-packages/#use-pip-for-installing). ### Additional Prerequisites for Arc enabled Data Services @@ -30,6 +31,9 @@ This document will enumerate everything you need to do run the sonobuoy based co *The above script is **bash only**. Please use the [`k8s-conformance-test-suite.ps1`](k8s-conformance-test-suite.ps1) script for windows hosts. + +**Please use the [`k8s-conformance-test-suite.py`](k8s-conformance-test-suite.py) script for both windows and linux hosts.To execute the script create a virtual environment under project root directory and install the following dependent packages using pip [azure-identity](https://pypi.org/project/azure-identity/), [azure-mgmt-resource](https://pypi.org/project/azure-mgmt-resource/) and [azure-storage-blob](https://pypi.org/project/azure-storage-blob/). + ### Arc enabled Data Services 1. Edit the [`ds-conformance-test-suite.sh`](ds-conformance-test-suite.sh) file and set the values for the required environment variables. 2. If your cluster is behind an outbound proxy, please edit the above file according to the instruction provided as comments for proxy configuration.