diff --git a/playbooks/tobiko-devstack-run.yaml b/playbooks/tobiko-devstack-run.yaml index 0d43546e8..9260861fd 100644 --- a/playbooks/tobiko-devstack-run.yaml +++ b/playbooks/tobiko-devstack-run.yaml @@ -14,6 +14,11 @@ --- -- hosts: tempest +- name: Run Tobiko + hosts: tempest roles: - - run-tox + - role: tobiko + become: true + become_user: stack + vars: + tobiko_dir: /opt/stack/tobiko diff --git a/roles/run-tox/defaults/main.yaml b/roles/run-tox/defaults/main.yaml deleted file mode 100644 index f4d4523b2..000000000 --- a/roles/run-tox/defaults/main.yaml +++ /dev/null @@ -1,4 +0,0 @@ -tox_dir: /opt/stack/tobiko -tox_envlist: scenario -tox_extra_args: '' -tox_python_version: '' diff --git a/roles/run-tox/tasks/main.yaml b/roles/run-tox/tasks/main.yaml deleted file mode 100644 index 1d3bc5043..000000000 --- a/roles/run-tox/tasks/main.yaml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Run Tobiko test cases - shell: - chdir: "{{ tox_dir }}" - cmd: | - export PYTHON_VERSION={{ tox_python_version }} - tools/ci/tox -e "{{ tox_envlist }}" {{ tox_extra_args }} - become: true - become_user: stack diff --git a/roles/tobiko/defaults/main.yaml b/roles/tobiko/defaults/main.yaml new file mode 100644 index 000000000..c9d859f18 --- /dev/null +++ b/roles/tobiko/defaults/main.yaml @@ -0,0 +1,20 @@ +--- + +# Tobiko workflow parameters +tobiko_check_tools: true +tobiko_run_tests: true +tobiko_run_faults: false + +# Remote tobiko directory +tobiko_dir: "~/src/tobiko" + +# Python parameteres +python_version: '' +python_command: "{{ tobiko_dir }}/tools/ci/python" + +# Tobiko tox parameters +tox_dir: "{{ tobiko_dir }}" +tox_command: "{{ tobiko_dir }}/tools/ci/tox" +tox_envlist: scenario +tox_extra_args: '' +tox_posargs: '' diff --git a/roles/tobiko/tasks/check_tools.yaml b/roles/tobiko/tasks/check_tools.yaml new file mode 100644 index 000000000..6a1a084f2 --- /dev/null +++ b/roles/tobiko/tasks/check_tools.yaml @@ -0,0 +1,16 @@ +--- + +- name: "Check Python command '{{ python_command }}'" + shell: "{{ python_command }} --version" + + +- name: "Check Python command version is '{{ python_version }}'" + shell: | + {{ python_command }} '{{ tobiko_dir }}/tools/ci/python_version' \ + --check-prefix + + +- name: "Check Tox command: '{{ tox_command }}'" + shell: + chdir: "{{ tox_dir }}" + cmd: "{{ tox_command }} --version" diff --git a/roles/tobiko/tasks/main.yaml b/roles/tobiko/tasks/main.yaml new file mode 100644 index 000000000..714189d26 --- /dev/null +++ b/roles/tobiko/tasks/main.yaml @@ -0,0 +1,29 @@ +--- + +- environment: + PYTHON_VERSION: "{{ python_version }}" + block: + + - name: "Check CLI tools" + when: tobiko_check_tools | bool + include: check_tools.yaml + + - when: tobiko_run_tests + block: + + - name: "Run tests" + when: tobiko_run_tests | bool + include: tasks/run_tests.yaml + + - when: tobiko_run_faults | bool + block: + + - name: "Run faults" + include: run_tests.yaml + vars: + tox_envlist: faults + + - name: "Run tests after faults" + include: run_tests.yaml + vars: + tox_posargs: "--combine" diff --git a/roles/tobiko/tasks/run_tests.yaml b/roles/tobiko/tasks/run_tests.yaml new file mode 100644 index 000000000..e03c107bf --- /dev/null +++ b/roles/tobiko/tasks/run_tests.yaml @@ -0,0 +1,8 @@ +--- + +- name: "Run test '{{ tox_envlist }}' cases from '{{ tox_dir }}'" + shell: + chdir: "{{ tox_dir }}" + cmd: | + {{ tox_command }} -e '{{ tox_envlist }}' {{ tox_extra_args }} -- \ + {{ tox_posargs }} diff --git a/tools/ci/python_version b/tools/ci/python_version new file mode 100755 index 000000000..efa1b2360 --- /dev/null +++ b/tools/ci/python_version @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import argparse +import os +import sys + + +def get_python_version(): + return '.'.join(str(i) for i in sys.version_info[:3]) + + +def main(): + parser = argparse.ArgumentParser(description='Print Python version') + parser.add_argument('--check-prefix', action='store_const', const=True, + default=False, + help='check version matches $PYTHON_VERSION prefix') + args = parser.parse_args() + + version = get_python_version() + + if args.check_prefix: + expected_version = os.environ.get('PYTHON_VERSION') + if expected_version and not version.startswith(expected_version): + message = ("Version {version!r} must starts with" + " {expected_version!r}\n").format( + version=version, + expected_version=expected_version) + sys.stderr.write(message) + sys.exit(1) + + sys.stdout.write(version + '\n') + + +if __name__ == '__main__': + main() diff --git a/tox.ini b/tox.ini index b73fcc24f..9b4fc7dd2 100644 --- a/tox.ini +++ b/tox.ini @@ -140,11 +140,10 @@ deps = {[testenv:scenario]deps} passenv = {[testenv:scenario]passenv} setenv = {[testenv:scenario]setenv} + OS_TEST_PATH={toxinidir}/tobiko/tests/faults TOBIKO_PREVENT_CREATE=true commands = - stestr run --serial \ - --test-path '{toxinidir}/tobiko/tests/faults' {posargs} - stestr run --combine {posargs} + stestr run --serial {posargs} [testenv:venv] diff --git a/zuul.d/tobiko-devstack-ovn.yaml b/zuul.d/tobiko-devstack-ovn.yaml index c3cf3141e..924034aca 100644 --- a/zuul.d/tobiko-devstack-ovn.yaml +++ b/zuul.d/tobiko-devstack-ovn.yaml @@ -1,6 +1,6 @@ - job: name: tobiko-devstack-ovn - parent: tobiko-devstack-multinode + parent: tobiko-devstack-scenario-multinode abstract: true nodeset: openstack-three-node-bionic description: | diff --git a/zuul.d/tobiko-devstack.yaml b/zuul.d/tobiko-devstack.yaml index 909321049..92b917356 100644 --- a/zuul.d/tobiko-devstack.yaml +++ b/zuul.d/tobiko-devstack.yaml @@ -17,7 +17,6 @@ - x/tobiko timeout: 7200 vars: - tox_python_version: 3 devstack_localrc: MULTI_HOST: 0 USE_PYTHON3: true @@ -168,8 +167,8 @@ - job: - name: tobiko-devstack-multinode - parent: tobiko-devstack + name: tobiko-devstack-scenario-multinode + parent: tobiko-devstack-scenario abstract: true description: Base Tobiko devstack job with multinode. vars: @@ -201,12 +200,12 @@ - job: name: tobiko-devstack-faults - parent: tobiko-devstack-multinode + parent: tobiko-devstack-scenario-multinode abstract: true description: | Base Tobiko devstack job to execute scenario+faults+scenario test cases. vars: - tox_envlist: scenario,faults + tobiko_run_faults: true irrelevant-files: - ^.*\.rst$ - ^doc/ @@ -226,7 +225,7 @@ devstack_localrc: # CentOS has no support for Python3 USE_PYTHON3: false - tox_python_version: 2 + python_version: 2 - job: