From 2d255d14f809d4e46bb1b67040c48cd376f088ec Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Thu, 11 Oct 2018 14:29:02 +0530 Subject: [PATCH] Add podman support to validate-tempest role * https://review.openstack.org/#/c/600517 introduces undercloud_container_cli to choose docker/podman container runtime. This changes introduces to use both docker/podman for running tempest tests. * Tempest user does not have permission to create tempest workspace let's create the tempest workspace and own it with the tempest user. * Introducing tempest_data directory to keep tempest related data which can be used by tempestconf and tempest run to tests * Cleaned up stuff which is not necessary for tempest container. Depends-On: https://review.openstack.org/#/c/614664/ Change-Id: I1b19b2580d1d4c9844e9221f18b23655b36b5a23 --- roles/validate-tempest/README.md | 1 + roles/validate-tempest/defaults/main.yml | 13 ++++- roles/validate-tempest/tasks/pre-tempest.yml | 5 ++ .../tasks/tempest-containers.yml | 4 +- .../templates/configure-tempest.sh.j2 | 15 +++-- .../templates/run-tempest.sh.j2 | 55 ++++++++----------- 6 files changed, 55 insertions(+), 38 deletions(-) diff --git a/roles/validate-tempest/README.md b/roles/validate-tempest/README.md index 82b8f9eb0..283181bf2 100644 --- a/roles/validate-tempest/README.md +++ b/roles/validate-tempest/README.md @@ -46,6 +46,7 @@ Role Variables * `tempest_container_namespace`: The name of tempest container image to use (default: centos-binary-tempest) * `tempest_container_tag`: The tag of the tempest container image to use (default: current-tripleo) * `tempest_dir`: The path to tempest workspace directory (default: /home/stack/tempest) +* `tempest_data`: The path to keep tempest related files used for running tempest (default: /home/stack) * `test_black_regex`: A set of tempest tests to skip (default: []) * `tempest_version_dict`: A dict with release name as key and tempest tag version for that release as value * `tempest_version`: The tempest version to use for running tempest diff --git a/roles/validate-tempest/defaults/main.yml b/roles/validate-tempest/defaults/main.yml index ae5d600ef..1d3be9675 100644 --- a/roles/validate-tempest/defaults/main.yml +++ b/roles/validate-tempest/defaults/main.yml @@ -36,7 +36,18 @@ tempest_container_tag: >- {%- else -%} {{ docker_image_tag }} {%- endif %} -tempest_dir: "{{ working_dir }}/tempest" +tempest_dir: >- + {% if tempest_format in ['container'] -%} + /var/lib/tempest/tempest + {%- else -%} + {{ working_dir }}/tempest + {%- endif %} +tempest_data: >- + {% if tempest_format in ['container'] -%} + /var/lib/tempest + {%- else -%} + {{ working_dir }} + {%- endif %} tempest_whitelist_file_src: "whitelist_file.j2" tempest_whitelist_file: "whitelist_file.conf" tempest_whitelist: [] diff --git a/roles/validate-tempest/tasks/pre-tempest.yml b/roles/validate-tempest/tasks/pre-tempest.yml index 73f2c688a..4a474a16f 100644 --- a/roles/validate-tempest/tasks/pre-tempest.yml +++ b/roles/validate-tempest/tasks/pre-tempest.yml @@ -8,6 +8,11 @@ set_fact: rc_file: "{{ working_dir }}/{% if tempest_undercloud %}stackrc{% else %}overcloudrc{% endif %}" +- name: Set rc file to be sourced to run tempest with in container + set_fact: + rc_file_container: "{{ tempest_data }}/{% if tempest_undercloud %}stackrc{% else %}overcloudrc{% endif %}" + when: tempest_format == 'container' + - name: Create overcloud tempest setup script template: src: tempest-setup.j2 diff --git a/roles/validate-tempest/tasks/tempest-containers.yml b/roles/validate-tempest/tasks/tempest-containers.yml index 01574ea8d..355f87859 100644 --- a/roles/validate-tempest/tasks/tempest-containers.yml +++ b/roles/validate-tempest/tasks/tempest-containers.yml @@ -1,8 +1,8 @@ --- - name: Set tempest init command set_fact: - tempest_init: "{% if release == 'newton' %}/usr/share/openstack-tempest-*/tools/configure-tempest-directory{% else %}tempest init {{ tempest_dir }}{% endif %}" + tempest_init: "tempest init {{ tempest_dir }}" - name: Set tempestconf call set_fact: - tempestconf: "{% if release == 'newton' %}{{ working_dir }}/tools/config_tempest.py{% else %}/usr/bin/discover-tempest-config{% endif %}" + tempestconf: "/usr/bin/discover-tempest-config" diff --git a/roles/validate-tempest/templates/configure-tempest.sh.j2 b/roles/validate-tempest/templates/configure-tempest.sh.j2 index a978f1661..bf40621c9 100644 --- a/roles/validate-tempest/templates/configure-tempest.sh.j2 +++ b/roles/validate-tempest/templates/configure-tempest.sh.j2 @@ -10,10 +10,10 @@ # to create tempest directory. # We are doing this as sudo because tempest in containers create the files as # root. +{% if tempest_format in ["venv", "packages"] %} sudo rm -rf {{ working_dir }}/.tempest sudo rm -rf {{ tempest_dir }} -# Remove tempest_data directory created before running tempest container -sudo rm -rf {{ working_dir }}/tempest_data +{% endif %} # Cloud Credentials @@ -75,12 +75,17 @@ set -e rpm -qa | grep tempest +# Remove the existing tempest workspace +if [ -d {{ tempest_dir }}/etc ]; then +tempest workspace remove --name {{ tempest_dir | basename }} --rmdir +fi {% endif %} ## Create Tempest Workspace ## ------------------------ ## :: + # Create Tempest directory mkdir {{ tempest_dir }} @@ -95,7 +100,9 @@ popd ## :: export TEMPESTCONF="{{ tempestconf }}" -{% if tempest_os_cloud == '' %} +{% if tempest_format == 'container' %} +source {{ rc_file_container }} +{% elif tempest_os_cloud == '' %} source {{ rc_file }} {% endif %} @@ -128,7 +135,7 @@ export OS_AUTH_URL="$OS_AUTH_URL/v2.0" cd {{ tempest_dir }} $TEMPESTCONF --out etc/tempest.conf \ {% if tempest_overcloud|bool %} - --deployer-input {{ working_dir }}/{{ tempest_deployer_input_file }} \ + --deployer-input {{ tempest_dir }}/{{ tempest_deployer_input_file }} \ --network-id $public_net_id \ {% endif %} {% if tempest_os_cloud != '' %} diff --git a/roles/validate-tempest/templates/run-tempest.sh.j2 b/roles/validate-tempest/templates/run-tempest.sh.j2 index 973bcde26..e99315082 100644 --- a/roles/validate-tempest/templates/run-tempest.sh.j2 +++ b/roles/validate-tempest/templates/run-tempest.sh.j2 @@ -10,6 +10,7 @@ export OSTESTR='{{ working_dir }}/tempest_git/tools/with_venv.sh ostestr' export OSTESTR='ostestr' export TEMPESTCLI='/usr/bin/tempest' {% endif %} +export TEMPESTDATA={{ tempest_data }} ## List tempest plugins @@ -26,9 +27,9 @@ $TEMPESTCLI cleanup --init-saved-state {% endif %} {% if release in ["newton", "ocata", "pike"] %} $OSTESTR {% else %} $TEMPESTCLI run {% endif %}{% if test_white_regex != '' %} --regex '({{ test_white_regex }})' {% endif %} -{% if tempest_whitelist|length > 0 %} --whitelist_file={{ working_dir }}/{{ tempest_whitelist_file }} {% endif %} -{% if release not in ["newton", "ocata", "pike"] %} {% if test_black_regex|length > 0 %} --black-regex='{{ test_black_regex|join('|') }}' {% endif %} {% endif %} -{% if skip_file_src != '' %} --blacklist_file={{ working_dir }}/{{ skip_file }} {% endif %} +{% if tempest_whitelist|length > 0 %} --whitelist_file=$TEMPESTDATA/{{ tempest_whitelist_file }} {% endif %} +{% if release not in ["newton", "ocata", "pike"] %} {% if test_black_regex|length > 0 %} --black-regex='{{ test_black_regex|join('|') }}'{% endif %} {% endif %} +{% if skip_file_src != '' %} --blacklist_file=$TEMPESTDATA/{{ skip_file }} {% endif %} {% if tempest_workers is defined %} --concurrency {{ tempest_workers }} {% endif %} {% if tempest_until_failure|bool %} --until-failure {% endif %} @@ -44,9 +45,14 @@ $TEMPESTCLI cleanup --dry-run EOF chmod +x {{ working_dir }}/tempest_container.sh # Copy all the required files in a temprory directory -mkdir {{ working_dir }}/tempest_data +export TEMPEST_HOST_DATA='/var/lib/tempestdata' -cp $RCFILE \ +if [ ! -d $TEMPEST_HOST_DATA ] +then + mkdir -p $TEMPEST_HOST_DATA +fi + +sudo cp $RCFILE \ {% if skip_file_src != '' %} {{ working_dir }}/{{ skip_file }} \ {% endif %} @@ -57,46 +63,33 @@ cp $RCFILE \ {{ working_dir }}/{{ tempest_deployer_input_file }} \ {% endif %} {{ working_dir }}/tempest_container.sh \ - {{ working_dir }}/tempest_data + $TEMPEST_HOST_DATA -# TODO(chkumar246): https://review.openstack.org/#/c/583940/ added tempest user to -# tempest container, The file getting mounted from host to tempest container have -# different permission as tempest user does not own those folders which will give -# permission denied So first check whether tempest user is there or not if present -# run the docker command to change the dir permission and if not found the usual -# command, Once new container image is available after promotion, we will the add -# the volume in THT itself and fix other stuffs. Also pull docker image locally -# as docker inspect needs the image to exist. -sudo docker pull {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} -if [ x$(sudo docker inspect --format "{{ '{{' }} .Config.User {{ '}}' }}" {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }}) == 'xtempest' ]; then - sudo docker run --net=host -u root -v {{ working_dir }}/tempest_data:{{ working_dir }} \ - {% if not 'http' in tempest_test_image_path %} - -v {{ tempest_test_image_path }}:{{ tempest_test_image_path }} \ - {% endif %} - {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} \ - chown -R tempest:tempest \ - {% if not 'http' in tempest_test_image_path %} - {{ tempest_test_image_path }} \ - {% endif %} - {{ working_dir }} -fi +{% if undercloud_container_cli is defined %} +export CONTAINER_BINARY={{ undercloud_container_cli }} +{% else %} +export CONTAINER_BINARY='docker' +{% endif %} + +sudo $CONTAINER_BINARY pull {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} # Run tempest container using docker mouting required files -sudo docker run --net=host -i -v {{ working_dir }}/tempest_data/:{{ working_dir }} \ +sudo $CONTAINER_BINARY run --net=host -i -v $TEMPEST_HOST_DATA:{{ tempest_data }} \ -e PYTHONWARNINGS="${PYTHONWARNINGS:-}" \ -e CURL_CA_BUNDLE="" \ + --user=root \ -v /var/log/containers/tempest:{{ tempest_log_dir }} \ {% if not 'http' in tempest_test_image_path %} -v {{ tempest_test_image_path }}:{{ tempest_test_image_path }} \ {% endif %} {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} \ - /usr/bin/bash -c 'set -e; {{ working_dir }}/tempest_container.sh' + /usr/bin/bash -c 'set -e; {{ tempest_data }}/tempest_container.sh' # Change permission of tempest workspace directory -sudo chmod -R 777 {{ working_dir }}/tempest_data +sudo chmod -R 777 $TEMPEST_HOST_DATA # Copy tempest related data to tempest folder so that stackviz can use it -cp -R {{ working_dir }}/tempest_data/tempest {{ working_dir }} +cp -R $TEMPEST_HOST_DATA/tempest {{ working_dir }} {% endif %} ### --stop_docs