Add list tests ansible module

Add an ansible module to list the skipped tests.
Also, update zuul job definition and documentation, removing some
variables that are no longer required.

Change-Id: Ic481c75c9345c62d29c9eb37a18df5324afe6de0
This commit is contained in:
Arx Cruz 2020-06-10 11:32:51 +02:00
parent 9f1dd0411e
commit 4c1bfdf4d9
12 changed files with 168 additions and 21 deletions

View File

@ -31,4 +31,6 @@
name: openstack-tempest-skiplist-validate
parent: openstack-tempest-skiplist-base
description: Tempest skiplist to validate yaml file
pre-run:
- playbooks/tempest_skip_install.yaml
run: playbooks/tempest_skip_validate.yaml

View File

@ -0,0 +1,7 @@
---
- hosts: all
roles:
- ensure-pip
- install_skiplist
vars:
tempest_skip_path: "{{ zuul.projects['opendev.org/openstack/openstack-tempest-skiplist'].src_dir }}"

View File

@ -1,8 +1,8 @@
---
- hosts: all
roles:
- ensure-pip
- install_skiplist
- validate_yaml
- list_skipped
vars:
tempest_skip_path: "{{ zuul.projects['opendev.org/openstack/openstack-tempest-skiplist'].src_dir }}"
list_skipped_yaml_file: "{{ tempest_skip_path }}/roles/validate-tempest/vars/tempest_skip.yml"

View File

@ -1,16 +1,10 @@
Install tempest skiplist
========================
This role install tempest-siplist in a virtual environment.
This role install tempest-skiplist.
**Role Variables**
.. zuul:rolevar:: virtualenvs.tempest_skip
:type: string
:default: ~/.virtualenvs/.tempest_skip
A path to virtualenv used to install openstack-tempest-skiplist
.. zuul:rolevar:: tempest_skip_path
:type: string

View File

@ -1,5 +1,3 @@
---
virtualenvs:
tempest_skip: "~/.virtualenvs/.tempest_skip"
# Path for the tempest skip
# tempest_skip_path:

View File

@ -1,19 +1,13 @@
---
- block:
- name: Install virtualenv
pip:
name: virtualenv
executable: pip3
become: yes
- name: Create tempest-skiplist venv with latest pip, setuptools and pbr
pip:
virtualenv: "{{ virtualenvs.tempest_skip }}"
name: ['setuptools', 'pbr']
state: latest
extra_args: --user
- name: Install tempest-skiplist
pip:
name: "."
virtualenv: "{{ virtualenvs.tempest_skip }}"
chdir: "{{ tempest_skip_path }}"
extra_args: --user

View File

@ -0,0 +1,22 @@
List skipped tempest tests
==========================
This role execute the tempest-skip tool and return the list of tests to be
skipped.
**Role Variables**
.. zuul:rolevar:: list_skipped_yaml_file
:type: string
Path to the yaml file containing the skipped tests
.. zuul:rolevar:: list_skipped_release
:type: string
Release name to be used in the filter if required.
.. zuul:rolevar:: list_skipped_job
:type: string
Job name to be used in the filter if required.

View File

@ -0,0 +1,4 @@
---
# list_skipped_yaml_file: /home/zuul/src/openstack/openstack-tempest-skiplist/roles/validate-tempest/vars/tempest_skip.yml
# list_skipped_job: tripleo-ci-centos-8-containers-multinode
# list_skipped_release: master

View File

@ -0,0 +1,119 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ansible.module_utils.basic import AnsibleModule
from tempest_skip.list_yaml import ListYaml
import sys
ANSIBLE_METADATA = {
'metadata_version': '0.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: list_skipped
author:
- "Arx Cruz (@arxcruz)
version_added: '2.9'
short_description:
- Parse skipped tests from tempest
notes: []
requirements:
- tempest-skip
options:
yaml_file:
description:
- Path to a yaml file containing the skipped tests in
openstack-tempest-skiplist format
required: True
type: str
job:
description:
- Name of the job to be used in the filter. Passing the job it will
filter only tests that have the specified job in the jobs list.
required: False
type: str
release:
description:
- Release name to be used in the filter. Default is set to 'master'
required: False
type: str
'''
EXAMPLES = '''
- name: Get list of skipped tests
list_skipped:
yaml_file: /tmp/skipped.yaml
job: tripleo-ci-centos-8-standalone
release: master
'''
RETURN = '''
skipped_tests:
description:
- List of tests filtered
returned: Always
type: list
sample: [
"tempest.api.volume.test_volumes_snapshots.VolumesSnapshotTestJSON"
]
'''
def run_module():
module_args = dict(
yaml_file=dict(type='str', required=True),
job=dict(type='str', required=False, default=None),
release=dict(type='str', required=False, default='master')
)
result = dict(
changed=True,
message='',
skipped_tests=[]
)
module = AnsibleModule(
argument_spec=module_args
)
if not module.params['yaml_file']:
module.fail_json(msg="A yaml file must be provided!")
cmd = ListYaml(__name__, sys.argv[1:])
parser = cmd.get_parser(__name__)
parser.file = module.params['yaml_file']
parser.release = module.params['release']
parser.job = module.params['job']
tests = cmd.take_action(parser)
skipped_tests = [test[0] for test in tests[1]]
result.update({'skipped_tests': skipped_tests})
module.exit_json(**result)
def main():
run_module()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,7 @@
---
- name: List skipped tests
list_skipped:
yaml_file: "{{ list_skipped_yaml_file }}"
release: "{{ list_skipped_release | default(omit) }}"
job: "{{ list_skipped_job | default(omit) }}"
register: tempest_skip_register

View File

@ -15,8 +15,7 @@
- name: Validate tempest-skip yaml files
shell: |
set -ex
export PATH=$PATH:/usr/local/sbin:/usr/sbin
source {{ virtualenvs.tempest_skip }}/bin/activate
export PATH=$PATH:/usr/local/sbin:/usr/sbin:$HOME/.local/bin
tempest-skip validate --file roles/validate-tempest/vars/tempest_skip.yml
args:
chdir: "{{ tempest_skip_path }}"

View File

@ -22,6 +22,7 @@ packages =
data_files =
usr/local/share/ansible/roles/install_skiplist = roles/install_skiplist/*
usr/local/share/ansible/roles/validate_yaml = roles/validate_yaml/*
usr/local/share/ansible/roles/list_skipped = roles/list_skipped/*
[entry_points]
console_scripts =