Skip to content
Merged
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
27 changes: 21 additions & 6 deletions src/aks-preview/azcli_aks_live_test/clone_repo.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
[[ -z "${CLI_REPO}" ]] && (echo "CLI_REPO is empty"; exit 1)
[[ -z "${CLI_BRANCH}" ]] && (echo "CLI_BRANCH is empty"; exit 1)
[[ -z "${EXT_REPO}" ]] && (echo "EXT_REPO is empty"; exit 1)
[[ -z "${EXT_BRANCH}" ]] && (echo "EXT_BRANCH is empty"; exit 1)
[[ -z "${MANUAL_EXT}" ]] && (echo "MANUAL_EXT is empty"; exit 1)

# dir
pwd
ls -alh

# clone azure-cli (default is the official repo)
# git clone https://github.com/Azure/azure-cli.git
git clone $CLI_REPO
git clone ${CLI_REPO}

# ckeckout to a specific azure-cli branch (default is the dev branch)
pushd azure-cli/
git branch -a
git checkout $CLI_BRANCH
git checkout ${CLI_BRANCH}
popd

# clone azure-cli-extensions when manually specify the extension repo
if [[ $MANUAL_EXT == true && -n $EXT_REPO && -n $EXT_BRANCH ]]; then
if [[ ${MANUAL_EXT} == true ]]; then
echo "Manually specify the extension repo, delete the current 'azure-cli-extensions' directory!"
rm -rf azure-cli-extensions/
git clone $EXT_REPO
git clone ${EXT_REPO}
pushd azure-cli-extensions/
git checkout $EXT_BRANCH
git branch -a
git checkout ${EXT_BRANCH}
popd
fi

Expand Down
20 changes: 16 additions & 4 deletions src/aks-preview/azcli_aks_live_test/prepare_image.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
[[ -z "${IMAGE_PREFIX}" ]] && (echo "IMAGE_PREFIX is empty"; exit 1)
[[ -z "${IMAGE_NAME}" ]] && (echo "IMAGE_NAME is empty"; exit 1)
[[ -z "${IMAGE_TAG}" ]] && (echo "IMAGE_TAG is empty"; exit 1)

# dir
pwd
ls -alh

# prepare docker image
echo "Pulling test image from '$IMAGE_PREFIX/$IMAGE_NAME:$IMAGE_TAG'..."
docker pull $IMAGE_PREFIX/$IMAGE_NAME:$IMAGE_TAG
docker tag $IMAGE_PREFIX/$IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:$IMAGE_TAG
echo "Pulling test image from '${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}'..."
docker pull ${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}
docker tag ${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:${IMAGE_TAG}
22 changes: 15 additions & 7 deletions src/aks-preview/azcli_aks_live_test/setup_venv.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
PYTHON_VERSION=${PYTHON_VERSION:-"3.8"}

# dir
pwd
ls -alh

# delete existing venv
rm -rf azEnv || true

# install python packages
python$PYTHON_VERSION -m venv azEnv
python${PYTHON_VERSION} -m venv azEnv
source azEnv/bin/activate
python -m pip install -U pip
# fixed azdev version to avoid call failure in az_aks_tool
# install azdev, used later to install azcli and extension
pip install azdev==0.1.32
# install pytest plugins
pip install pytest-json-report pytest-rerunfailures --upgrade
Expand All @@ -25,11 +34,10 @@ which az || az version || az extension list || true
# install az from cloned repos with azdev
azdev setup -c azure-cli/ -r azure-cli-extensions/
deactivate
source azEnv/bin/activate

# post-install: check installation result
which az
az version
# post-install: reactivate venv to check installation result
source azEnv/bin/activate
which az && az version

# mkdir to store reports
mkdir -p reports/
Expand Down
28 changes: 20 additions & 8 deletions src/aks-preview/azcli_aks_live_test/start_container.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
#!/usr/bin/env bash

set -eux
pwd

# transcribe environment variables into file 'env.list'
source ./transcribe_env.sh
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
# take the first arg as container name
container_name=${1:-"azcli-aks-live-test-container"}
[[ -z "${MAPPED_AZCLI_ALT_CLIENT_SECRET}" ]] && (echo "MAPPED_AZCLI_ALT_CLIENT_SECRET is empty"; exit 1)
[[ -z "${MAPPED_AZCLI_ALT_CLIENT_SECRET}" ]] && (echo "MAPPED_AZCLI_ALT_CLIENT_SECRET is empty"; exit 1)
[[ -z "${IMAGE_NAME}" ]] && (echo "IMAGE_NAME is empty"; exit 1)
[[ -z "${IMAGE_TAG}" ]] && (echo "IMAGE_TAG is empty"; exit 1)

# dir
pwd
ls -alh

# transcribe environment variables into file 'env.list'
./transcribe_env.sh

# start container in backgroud with tty
# mount current directory ($(Agent.BuildDirectory)/s) to /opt in container
# set working directory as /opt in container
# pass secrects as environment variables directly (instead of storing in env.list)
# pass other environment variables with env.list
docker run -t -d -v $PWD:/opt -w /opt \
-e AZCLI_ALT_CLIENT_SECRET=$MAPPED_AZCLI_ALT_CLIENT_SECRET \
-e AZURE_CLI_TEST_DEV_SP_PASSWORD=$MAPPED_AZCLI_ALT_CLIENT_SECRET \
-e AZCLI_ALT_CLIENT_SECRET=${MAPPED_AZCLI_ALT_CLIENT_SECRET} \
-e AZURE_CLI_TEST_DEV_SP_PASSWORD=${MAPPED_AZCLI_ALT_CLIENT_SECRET} \
--env-file ./env.list \
--name $container_name $IMAGE_NAME:$IMAGE_TAG
--name ${container_name} ${IMAGE_NAME}:${IMAGE_TAG}

# remove env.list
rm ./env.list
29 changes: 22 additions & 7 deletions src/aks-preview/azcli_aks_live_test/test_cli_live.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
[[ -z "${TENANT_ID}" ]] && (echo "TENANT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_SUBSCRIPTION_ID}" ]] && (echo "AZCLI_ALT_SUBSCRIPTION_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_ID}" ]] && (echo "AZCLI_ALT_CLIENT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_SECRET}" ]] && (echo "AZCLI_ALT_CLIENT_SECRET is empty"; exit 1)
[[ -z "${TEST_MODE}" ]] && (echo "TEST_MODE is empty"; exit 1)
[[ -z "${PARALLELISM}" ]] && (echo "PARALLELISM is empty"; exit 1)

# dir
pwd
ls -alh

# activate virtualenv
source azEnv/bin/activate
Expand All @@ -14,17 +29,17 @@ if az extension remove --name aks-preview || azdev extension remove aks-preview;
fi

# test cli
if [[ $TEST_MODE == "record" || $TEST_MODE == "all" ]]; then
if [[ ${TEST_MODE} == "record" || ${TEST_MODE} == "all" ]]; then
echo "Test in record mode!"
azdev test acs --no-exitfirst --xml-path cli_result.xml --discover -a "-n $PARALLELISM --json-report --json-report-file=cli_report.json --reruns 3 --capture=sys"
azdev test acs --no-exitfirst --xml-path cli_result.xml --discover -a "-n ${PARALLELISM} --json-report --json-report-file=cli_report.json --reruns 3 --capture=sys"
cp *cli_report.json *cli_result.xml reports/
fi

if [[ $TEST_MODE == "live" || $TEST_MODE == "all" ]]; then
if [[ ${TEST_MODE} == "live" || ${TEST_MODE} == "all" ]]; then
echo "Test in live mode!"
az login --service-principal -u $AZCLI_ALT_CLIENT_ID -p $AZCLI_ALT_CLIENT_SECRET -t $TENANT_ID
az account set -s $AZCLI_ALT_SUBSCRIPTION_ID
az login --service-principal -u ${AZCLI_ALT_CLIENT_ID} -p ${AZCLI_ALT_CLIENT_SECRET} -t ${TENANT_ID}
az account set -s ${AZCLI_ALT_SUBSCRIPTION_ID}
az account show
azdev test acs --live --no-exitfirst --xml-path cli_live_result.xml --discover -a "-n $PARALLELISM --json-report --json-report-file=cli_live_report.json --reruns 3 --capture=sys"
azdev test acs --live --no-exitfirst --xml-path cli_live_result.xml --discover -a "-n ${PARALLELISM} --json-report --json-report-file=cli_live_report.json --reruns 3 --capture=sys"
cp *cli_live_report.json *cli_live_result.xml reports/
fi
9 changes: 8 additions & 1 deletion src/aks-preview/azcli_aks_live_test/test_cli_unit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# dir
pwd
ls -alh

# activate virtualenv
source azEnv/bin/activate
Expand Down
64 changes: 35 additions & 29 deletions src/aks-preview/azcli_aks_live_test/test_ext_live.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
[[ -z "${TENANT_ID}" ]] && (echo "TENANT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_SUBSCRIPTION_ID}" ]] && (echo "AZCLI_ALT_SUBSCRIPTION_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_ID}" ]] && (echo "AZCLI_ALT_CLIENT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_SECRET}" ]] && (echo "AZCLI_ALT_CLIENT_SECRET is empty"; exit 1)
[[ -z "${TEST_MODE}" ]] && (echo "TEST_MODE is empty"; exit 1)
[[ -z "${PARALLELISM}" ]] && (echo "PARALLELISM is empty"; exit 1)
[[ -z "${TEST_CASES}" ]] && (echo "TEST_CASES is empty")
[[ -z "${EXT_TEST_FILTER}" ]] && (echo "EXT_TEST_FILTER is empty")
[[ -z "${EXT_TEST_COVERAGE}" ]] && (echo "EXT_TEST_COVERAGE is empty")

# dir
pwd
ls -alh

# activate virtualenv
source azEnv/bin/activate
Expand All @@ -21,60 +39,48 @@ azdev extension list | grep "aks-preview" -C 5
deactivate
source azEnv/bin/activate

# Ensure that the command index is updated by calling a specific command in aks-preview, so that all the commands defined in aks-preview are loaded correctly
# Otherwise, cold boot execution of azdev test may use the api version adopted by the acs command group in azure-cli (which may diverge from the api version used in current aks-preview)
retry_count=0
while ! az aks maintenanceconfiguration show --help && [[ $retry_count < 3 ]]
do
retry_count=`expr $retry_count + 1`
echo $retry_count"th retry to install aks-preview..."
azdev extension add aks-preview --debug
az extension list --debug
azdev extension list --debug | grep "aks-preview" -C 5
deactivate
source azEnv/bin/activate
done
# use a fake command to force trigger the command index update of azure-cli, in order to load aks-preview commands
# otherwise, cold boot execution of azdev test / pytest would only use commands in the acs module
az aks fake-command --debug || true

# prepare run flags
run_flags="-e -em ext_matrix_default.json --no-exitfirst --report-path ./ --reruns 3 --capture=sys"
run_flags="-e -em ext_matrix_default.json --no-exitfirst --report-path ./reports --reruns 3 --capture=sys"
# parallel
if [ $PARALLELISM -ge 2 ]; then
run_flags+=" -j $PARALLELISM"
if [ ${PARALLELISM} -ge 2 ]; then
run_flags+=" -j ${PARALLELISM}"
else
run_flags+=" -s"
fi
# test cases
if [[ -n $TEST_CASES ]]; then
run_flags+=" -t $TEST_CASES"
if [[ -n ${TEST_CASES} ]]; then
run_flags+=" -t ${TEST_CASES}"
fi
# ext extra filter
if [[ -n $EXT_TEST_FILTER ]]; then
run_flags+=" -ef $EXT_TEST_FILTER"
if [[ -n ${EXT_TEST_FILTER} ]]; then
run_flags+=" -ef ${EXT_TEST_FILTER}"
fi
# ext extra coverage
if [[ -n $EXT_TEST_COVERAGE ]]; then
run_flags+=" -ec $EXT_TEST_COVERAGE"
if [[ -n ${EXT_TEST_COVERAGE} ]]; then
run_flags+=" -ec ${EXT_TEST_COVERAGE}"
fi

# recording test
if [[ $TEST_MODE == "record" || $TEST_MODE == "all" ]]; then
if [[ ${TEST_MODE} == "record" || ${TEST_MODE} == "all" ]]; then
echo "Test in record mode!"
run_flags+=" --json-report-file=ext_report.json"
run_flags+=" --xml-file=ext_result.xml"
echo "run flags: ${run_flags}"
echo ${run_flags} | xargs python -u az_aks_tool/main.py
cp *ext_report.json *ext_result.xml reports/
fi

# live test
if [[ $TEST_MODE == "live" || $TEST_MODE == "all" ]]; then
if [[ ${TEST_MODE} == "live" || ${TEST_MODE} == "all" ]]; then
echo "Test in live mode!"
az login --service-principal -u $AZCLI_ALT_CLIENT_ID -p $AZCLI_ALT_CLIENT_SECRET -t $TENANT_ID
az account set -s $AZCLI_ALT_SUBSCRIPTION_ID
az login --service-principal -u ${AZCLI_ALT_CLIENT_ID} -p ${AZCLI_ALT_CLIENT_SECRET} -t ${TENANT_ID}
az account set -s ${AZCLI_ALT_SUBSCRIPTION_ID}
az account show
run_flags+=" -l --json-report-file=ext_live_report.json"
run_flags+=" --xml-file=ext_live_result.xml"
echo "run flags: ${run_flags}"
echo ${run_flags} | xargs python -u az_aks_tool/main.py
cp *ext_live_report.json *ext_live_result.xml reports/
fi
27 changes: 12 additions & 15 deletions src/aks-preview/azcli_aks_live_test/test_ext_unit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash

set -eux
# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# dir
pwd
ls -alh

# activate virtualenv
source azEnv/bin/activate
Expand All @@ -21,19 +28,9 @@ azdev extension list | grep "aks-preview" -C 5
deactivate
source azEnv/bin/activate

# Ensure that the command index is updated by calling a specific command in aks-preview, so that all the commands defined in aks-preview are loaded correctly
# Otherwise, cold boot execution of azdev test may use the api version adopted by the acs command group in azure-cli (which may diverge from the api version used in current aks-preview)
retry_count=0
while ! az aks command invoke --help && [[ $retry_count < 3 ]]
do
retry_count=`expr $retry_count + 1`
echo $retry_count"th retry to install aks-preview..."
azdev extension add aks-preview --debug
az extension list --debug
azdev extension list --debug | grep "aks-preview" -C 5
deactivate
source azEnv/bin/activate
done
# use a fake command to force trigger the command index update of azure-cli, in order to load aks-preview commands
# otherwise, cold boot execution of azdev test / pytest would only use commands in the acs module
az aks fake-command --debug || true

# unit test & coverage report
# az_aks_tool
Expand Down Expand Up @@ -65,7 +62,7 @@ coverage report -m
popd
cp azure-cli-extensions/src/aks-preview/azext_aks_preview/coverage_azext_aks_preview.json reports/

if [[ $az_aks_tool_unit_test_result == "error" || $azext_aks_preview_unit_test_result == "error" ]]; then
if [[ ${az_aks_tool_unit_test_result} == "error" || ${azext_aks_preview_unit_test_result} == "error" ]]; then
echo "Unit test failed!"
exit 1
fi
Loading