Skip to content
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

Python script file added #31

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

180 changes: 90 additions & 90 deletions testsuite/k8s-conformance-test-suite.ps1
Original file line number Diff line number Diff line change
@@ -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="`"<your-sas-token-here>`"" # sas token for your storage account, please replace <your-sas-token-here> 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://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.HTTP_PROXY="http://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc,<ip CIDR etc>"
# 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=<path-to-cert-file>
# 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="<namespace of sonobuoy secret>"
# --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="`"<your-sas-token-here>`"" # sas token for your storage account, please replace <your-sas-token-here> 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://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.HTTP_PROXY="http://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc,<ip CIDR etc>"

# 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=<path-to-cert-file>
# 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="<namespace of sonobuoy secret>"
# --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
}
126 changes: 126 additions & 0 deletions testsuite/k8s-conformance-test-suite.py
Original file line number Diff line number Diff line change
@@ -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 <your-sas-token-here> 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://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.HTTP_PROXY="http://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-platform.NO_PROXY="kubernetes.default.svc,<ip CIDR etc>"

# 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=<path-to-cert-file>
# 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="<namespace of sonobuoy secret>"
# --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)





4 changes: 4 additions & 0 deletions testsuite/running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down