Switch Jenkinsfile over to xdist

This commit is contained in:
Michael Youngstrom
2018-07-25 16:05:47 -04:00
committed by Michael Youngstrom
parent 9ad0f2b838
commit b4fcbbd363
9 changed files with 304 additions and 318 deletions

View File

@@ -29,8 +29,6 @@ set -e
#
###############################################################################
PAVER_ARGS="-v"
PARALLEL="--processes=-1"
export SKIP_NPM_INSTALL="True"
# Skip re-installation of Python prerequisites inside a tox execution.
@@ -38,6 +36,20 @@ if [[ -n "$TOXENV" ]]; then
export NO_PREREQ_INSTALL="True"
fi
if [[ -n "$XDIST_NUM_TASKS" ]]; then
bash scripts/xdist/prepare_xdist_nodes.sh
PAVER_ARGS="-v --xdist_ip_addresses="$(<pytest_task_ips.txt)""
export SHARD="all"
if [[ -n "$XDIST_REMOTE_NUM_PROCESSES" ]]; then
PARALLEL="--processes=$XDIST_REMOTE_NUM_PROCESSES"
else
PARALLEL="--processes=1"
fi
else
PAVER_ARGS="-v"
PARALLEL="--processes=-1"
fi
case "${TEST_SUITE}" in
"lms-unit")
@@ -65,7 +77,7 @@ case "${TEST_SUITE}" in
"cms-unit")
case "$SHARD" in
"all")
paver test_system -s cms --disable_capture ${PAVER_ARGS} 2> cms-tests.log
paver test_system -s cms --disable_capture ${PAVER_ARGS} ${PARALLEL} 2> cms-tests.log
;;
1)
paver test_system -s cms --disable_capture --eval-attr="shard==$SHARD" ${PAVER_ARGS} 2> cms-tests.${SHARD}.log
@@ -87,7 +99,7 @@ case "${TEST_SUITE}" in
"commonlib-unit")
case "$SHARD" in
"all")
paver test_lib --disable_capture ${PAVER_ARGS} 2> common-tests.log
paver test_lib --disable_capture ${PAVER_ARGS} ${PARALLEL} 2> common-tests.log
;;
[1-2])
paver test_lib -l common/lib/xmodule --disable_capture --eval-attr="shard==$SHARD" ${PAVER_ARGS} 2> common-tests.${SHARD}.log

View File

@@ -1,16 +1,16 @@
#!/bin/bash
set -e
echo "Spinning up xdist containers with pytest_container_manager.py"
python scripts/xdist/pytest_container_manager.py -a up -n ${XDIST_NUM_TASKS} \
-t ${XDIST_CONTAINER_TASK_NAME} \
-s ${XDIST_CONTAINER_SUBNET} \
-sg ${XDIST_CONTAINER_SECURITY_GROUP}
ip_list=$(<pytest_task_ips.txt)
for ip in $ip_list
for ip in $(echo $ip_list | sed "s/,/ /g")
do
container_reqs_cmd="ssh ubuntu@$ip 'cd /edx/app/edxapp/edx-platform;
container_reqs_cmd="ssh -o StrictHostKeyChecking=no ubuntu@$ip 'cd /edx/app/edxapp/edx-platform;
git pull -q; git checkout -q ${XDIST_GIT_BRANCH};
source /edx/app/edxapp/edxapp_env; pip install -qr requirements/edx/testing.txt' & "

View File

@@ -104,13 +104,13 @@ class PytestContainerManager():
logger.info("Successfully booted up {} tasks.".format(number_of_tasks))
# Generate .txt files containing IP addresses and task arns
ip_list_string = " ".join(ip_addresses)
ip_list_string = ",".join(ip_addresses)
logger.info("Task IP list: {}".format(ip_list_string))
ip_list_file = open("pytest_task_ips.txt", "w")
ip_list_file.write(ip_list_string)
ip_list_file.close()
task_arn_list_string = " ".join(task_arns)
task_arn_list_string = ",".join(task_arns)
logger.info("Task arn list: {}".format(task_arn_list_string))
task_arn_file = open("pytest_task_arns.txt", "w")
task_arn_file.write(task_arn_list_string)
@@ -120,7 +120,7 @@ class PytestContainerManager():
"""
Terminates tasks based on a list of task_arns.
"""
for task_arn in task_arns:
for task_arn in task_arns.split(','):
response = self.ecs.stop_task(
cluster=self.cluster_name,
task=task_arn,
@@ -134,23 +134,26 @@ if __name__ == "__main__":
description="PytestContainerManager, manages ECS tasks in an AWS cluster."
)
parser.add_argument('--region', '-g', default='us-east-1',
help="AWS region where ECS infrastructure lives. Defaults to us-east-1")
parser.add_argument('--action', '-a', choices=['up', 'down'], default=None,
help="Action for PytestContainerManager to perform. "
"Either up for spinning up AWS ECS tasks or down for stopping them")
parser.add_argument('--cluster', '-c', default="jenkins-worker-containers",
help="AWS Cluster name where the tasks run. Defaults to"
"the testeng cluster: jenkins-worker-containers")
parser.add_argument('--action', '-a', choices=['up', 'down'], default=None,
help="Action for PytestContainerManager to perform. "
"Either up for spinning up AWS ECS tasks or down for stopping them")
parser.add_argument('--region', '-g', default='us-east-1',
help="AWS region where ECS infrastructure lives. Defaults to us-east-1")
# Spinning up tasks
parser.add_argument('--launch_type', default='FARGATE', choices=['EC2', 'FARGATE'],
help="ECS launch type for tasks. Defaults to FARGATE")
parser.add_argument('--num_tasks', '-n', type=int, default=None,
help="Number of ECS tasks to spin up")
parser.add_argument('--task_name', '-t', default=None,
help="Name of the task definition")
parser.add_argument('--public_ip', choices=['ENABLED', 'DISABLED'],
default='DISABLED', help="Whether the tasks should have a public IP")
parser.add_argument('--subnets', '-s', nargs='+', default=None,
help="List of subnets for the tasks to exist in")
@@ -158,19 +161,16 @@ if __name__ == "__main__":
parser.add_argument('--security_groups', '-sg', nargs='+', default=None,
help="List of security groups to apply to the tasks")
parser.add_argument('--public_ip', choices=['ENABLED', 'DISABLED'],
default='DISABLED', help="Whether the tasks should have a public IP")
parser.add_argument('--launch_type', default='FARGATE', choices=['EC2', 'FARGATE'],
help="ECS launch type for tasks. Defaults to FARGATE")
parser.add_argument('--task_name', '-t', default=None,
help="Name of the task definition")
# Terminating tasks
parser.add_argument('--task_arns', '-arns', nargs='+', default=None,
help="Task arns to terminate")
parser.add_argument('--reason', '-r', default="Finished executing tests",
help="Reason for terminating tasks")
parser.add_argument('--task_arns', '-arns', default=None,
help="Task arns to terminate")
args = parser.parse_args()
containerManager = PytestContainerManager(args.region, args.cluster)

View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -e
if [ -f pytest_task_arns.txt ]; then
echo "Terminating xdist containers with pytest_container_manager.py"
xdist_task_arns=$(<pytest_task_arns.txt)
python scripts/xdist/pytest_container_manager.py -a down --task_arns ${xdist_task_arns}
else
echo "File: pytest_task_arns.txt not found"
fi