Skip to content

Commit

Permalink
Overhaul the A01 test droid image and build process (Azure#5599)
Browse files Browse the repository at this point in the history
The change intends to bring the CLI's test image to the standard which
eventually will be shared across different product.The change intends to
bring the CLI's test image to the standard which eventually will be
shared across different product.

1. Use the new droid engine (written in Go)
2. Overhaul the docker image.
3. Add prepare pod and after test scripts
  • Loading branch information
troydai authored Feb 16, 2018
1 parent 1591695 commit a0661eb
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 204 deletions.
22 changes: 13 additions & 9 deletions scripts/ci/a01/Dockerfile.py36
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ FROM python:3.6-jessie

LABEL a01.product="azurecli"
LABEL a01.index.schema="v2"
LABEL a01.env.A01_SP_USERNAME="secret:sp.username"
LABEL a01.env.A01_SP_PASSWORD="secret:sp.password"
LABEL a01.env.A01_SP_TENANT="secret:sp.tenant"
LABEL a01.env.AZURE_TEST_RUN_LIVE="arg-live:True"
LABEL a01.setting.storage="True"

RUN rm /usr/bin/python && ln /usr/local/bin/python3.6 /usr/bin/python
RUN rm /usr/bin/python && ln /usr/local/bin/python3.6 /usr/bin/python && \
apt-get update && apt-get install jq

COPY build /tmp/build
COPY docker_app /app
RUN find /tmp/build -name '*.whl' | xargs pip install && \
rm -rf /tmp/build

RUN pip install -r /app/requirements.txt && \
find /tmp/build -name '*.whl' | xargs pip install && \
rm -rf /tmp/build && \
python /app/collect_tests.py > /app/test_index && \
rm /app/collect_tests.py && \
rm /app/requirements.txt && \
rm -rf ~/.cache/pip
COPY docker_app /app
RUN python /app/collect_tests.py > /app/test_index && \
rm /app/collect_tests.py

CMD /app/a01droid
21 changes: 21 additions & 0 deletions scripts/ci/a01/docker_app/after_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

mount_path=$1
task=$2

recording_path=$(echo $task | jq -r ".settings.execution.recording")
if [ "$recording_path" == "null" ]; then
echo "Skip copying recording file. Code 1."
exit 0
fi

if [ -z "$recording_path" ]; then
echo "Skip copying recording file. Code 2."
exit 0
fi

run_id=$(echo $task | jq -r ".run_id")
task_id=$(echo $task | jq -r ".id")

mkdir -p $mount_path/$run_id
cp $recording_path $mount_path/$run_id/recording_$task_id.yaml
38 changes: 29 additions & 9 deletions scripts/ci/a01/docker_app/collect_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=import-error, protected-access
# Justification:
# * The azure.cli packages are not visible while the script is scaned but they are guaranteed
# existence on the droid image
# * The test method names and other properties are protected for unit test framework.

import os.path
from pkgutil import iter_modules
from unittest import TestLoader
from importlib import import_module
from json import dumps as json_dumps

import azure.cli # pylint: disable=import-error
from azure.cli.testsdk import ScenarioTest, LiveScenarioTest # pylint: disable=import-error
import azure.cli
from azure.cli.testsdk import ScenarioTest, LiveScenarioTest

RECORDS = []

Expand All @@ -25,6 +31,13 @@ def get_test_type(test_case):
return 'Unit'


def find_recording_file(test_path):
module_path, _, test_method = test_path.rsplit('.', 2)
test_folder = os.path.dirname(import_module(module_path).__file__)
recording_file = os.path.join(test_folder, 'recordings', test_method + '.yaml')
return recording_file if os.path.exists(recording_file) else None


def search(path, prefix=''):
loader = TestLoader()
for _, name, is_pkg in iter_modules(path):
Expand All @@ -37,13 +50,20 @@ def search(path, prefix=''):
if not is_pkg and name.startswith('test'):
test_module = import_module(full_name)
for suite in loader.loadTestsFromModule(test_module):
for test in suite._tests: # pylint: disable=protected-access
RECORDS.append({
'module': full_name,
'class': test.__class__.__name__,
'method': test._testMethodName, # pylint: disable=protected-access
'type': get_test_type(test),
'path': '{}.{}.{}'.format(full_name, test.__class__.__name__, test._testMethodName)}) # pylint: disable=protected-access
for test in suite._tests:
path = '{}.{}.{}'.format(full_name, test.__class__.__name__, test._testMethodName)
rec = {
'ver': '1.0',
'execution': {
'command': 'python -m unittest {}'.format(path),
'recording': find_recording_file(path)
},
'classifier': {
'identifier': path,
'type': get_test_type(test),
}
}
RECORDS.append(rec)


search(azure.cli.__path__, 'azure.cli')
Expand Down
185 changes: 0 additions & 185 deletions scripts/ci/a01/docker_app/job.py

This file was deleted.

25 changes: 25 additions & 0 deletions scripts/ci/a01/docker_app/prepare_pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ "$AZURE_TEST_RUN_LIVE" != "True" ]; then
echo "Environment variable AZURE_TEST_RUN_LIVE is NOT True."
exit 0
fi

echo "Environment variable AZURE_TEST_RUN_LIVE is True. Login azure with service principal."

if [ -z "$A01_SP_USERNAME" ]; then
echo "Missing service principal username." >&2
exit 1
fi

if [ -z "$A01_SP_PASSWORD" ]; then
echo "Missing service principal password." >&2
exit 1
fi

if [ -z "$A01_SP_TENANT" ]; then
echo "Missing service principal tenant." >&2
exit 1
fi

az login --service-principal -u $A01_SP_USERNAME -p $A01_SP_PASSWORD -t $A01_SP_TENANT
1 change: 0 additions & 1 deletion scripts/ci/a01/docker_app/requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/ci/build_droid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ cp $dp0/a01/Dockerfile.py36 artifacts/
#############################################
# Move other scripts for docker
cp -R $dp0/a01/* artifacts/
curl -sL https://a01tools.blob.core.windows.net/droid/linux/a01droid -o artifacts/docker_app/a01droid
chmod +x artifacts/docker_app/a01droid

#############################################
# for travis repo slug, remove the suffix to reveal the owner
Expand Down

0 comments on commit a0661eb

Please sign in to comment.