diff --git a/playbooks/tobiko.yml b/playbooks/tobiko.yml new file mode 100644 index 000000000..e96c05921 --- /dev/null +++ b/playbooks/tobiko.yml @@ -0,0 +1,13 @@ +--- +- name: Prepare and run Tobiko + hosts: undercloud + vars: + debug: true + tobiko_config: true + tobiko_run: true + tempest_cloud_name: overcloud + tags: + - overcloud-validate + - standalone + roles: + - {role: validate-tobiko} diff --git a/roles/validate-tobiko/README.md b/roles/validate-tobiko/README.md new file mode 100644 index 000000000..c46d10677 --- /dev/null +++ b/roles/validate-tobiko/README.md @@ -0,0 +1,88 @@ +validate-tobiko +================ + +Ansible role for running [Tobiko](https://opendev.org/x/tobiko/) +tests on undercloud or overcloud. + +This role should be run on deployed undercloud or overcloud. It may also be run +e.g. after update or upgrade of cloud. +This role supports run on standalone deployment too. +Example of tests which are run by this role are: + +* tobiko.tests.scenario.neutron.test_floating_ip - to test connectivity to VM with + floating IP, +* tobiko.tests.scenario.nova.test_server.ServerStackResourcesTest.test_server - to + test server actions. + +Role Variables +-------------- + +* `tobiko_config`: false/true - to prepare tobiko's config or not (default: yes) +* `tobiko_run`: false/true - to run tobiko tests or not (default: false) +* `tobiko_envlist`: - The name of tox envlist to be run (default: + scenario) +* `tobiko_extra_args`: - Extra arguments to be passed to tobiko tox + command (default: "") +* `tobiko_config_dir`: - directory where tobiko config files will be + stored (default: "{{ working_dir }}/.tobiko") +* `tobiko_config_file`: - name of tobiko config file (default: + "tobiko.conf") +* `tobiko_log_dir`: - directory where tobiko log files will be + stored (default: "{{ working_dir }}/.tobiko") +* `tobiko_log_file`: - name of tobiko log file (default: "tobiko.log") +* `tobiko_key_file_name`: - path to ssh key used by tobiko in tests + (default: "~/.ssh/id_rsa") +* `tobiko_floating_ip_network`: - name of floating IP network used by + tobiko in tests (default: "public") +* `public_network_type`: - type of public neutron network used for floating + IPs during tobiko testing (default: flat) +* `public_network_pool_start`: - neutron public network allocation pool start + (default: {{ floating_ip_cidr|nthhost(100) }}) +* `public_network_pool_end`: - neutron public network allocation pool end + (default: {{ floating_ip_cidr|nthhost(120) }}) +* `public_network_gateway`: - gateway IP for neutron public network, when + not set, neutron will choose it automatically + (default: {{ floating_ip_cidr|nthhost(1) }}) +* `public_physical_network`: - name of physical network used in neutron for public + network (default: datacentre) +* `public_segmentation_id`: - segmentation_id for neutron public network + (default: '') +* `floating_ip_cidr`: - the network CIDR to be used for a public floating IP + network during testing (default: {{ undercloud_network_cidr }}) + + +Using validate-tobiko role with tripleo-quickstart +--------------------------------------------------- + +To run tobiko with tripleo-quickstart, run the following command: + + $WORKSPACE/tripleo-quickstart + + bash quickstart.sh \ + --tags all \ + --no-clone \ + --release master \ + --extra-vars run_tobiko=True \ + $VIRTHOST + +Note: by using --extra-vars, we can change the validate-tobiko role variables. + +Example Playbook +---------------- + + --- + - name: Run tobiko + hosts: undercloud + gather_facts: false + roles: + - validate-tobiko + +License +------- + +Apache 2.0 + +Author Information +------------------ + +RDO-CI Team diff --git a/roles/validate-tobiko/defaults/main.yml b/roles/validate-tobiko/defaults/main.yml new file mode 100644 index 000000000..f9a66909b --- /dev/null +++ b/roles/validate-tobiko/defaults/main.yml @@ -0,0 +1,23 @@ +--- +tobiko_config: true +tobiko_run: true + +tobiko_envlist: "scenario" +tobiko_extra_args: "" +tobiko_config_dir: "{{ working_dir }}/.tobiko" +tobiko_config_file: "tobiko.conf" + +tobiko_log_dir: "{{ working_dir }}/.tobiko" +tobiko_log_file_base: "tobiko" +tobiko_key_file_name: "~/.ssh/id_rsa" + +tobiko_floating_ip_network: "public" +public_network_type: "flat" +public_physical_network: datacentre +public_segmentation_id: '' +floating_ip_cidr: "{{ undercloud_network_cidr }}" +public_network_pool_start: "{{ floating_ip_cidr|nthhost(100) }}" +public_network_pool_end: "{{ floating_ip_cidr|nthhost(120) }}" +public_network_gateway: "{{ floating_ip_cidr|nthhost(1) }}" + +python_package_prefix: "python" diff --git a/roles/validate-tobiko/meta/main.yml b/roles/validate-tobiko/meta/main.yml new file mode 100644 index 000000000..98bfef3b5 --- /dev/null +++ b/roles/validate-tobiko/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - extras-common diff --git a/roles/validate-tobiko/tasks/main.yml b/roles/validate-tobiko/tasks/main.yml new file mode 100644 index 000000000..6a0066009 --- /dev/null +++ b/roles/validate-tobiko/tasks/main.yml @@ -0,0 +1,34 @@ +--- +- name: gather facts used by role + setup: + gather_subset: "!min,python,processor" + when: > + ansible_python is not defined or + ansible_processor_vcpus is not defined + +- name: set python_cmd + set_fact: + python_cmd: "python{{ ansible_python.version.major }}" + cacheable: true + when: python_cmd is not defined + +- name: change python_package_prefix for python > 2 + set_fact: + python_package_prefix: "python{{ ansible_python.version.major }}" + cacheable: true + when: ansible_python.version.major > 2 + +- include: prepare-tobiko.yml + when: tobiko_config|bool + tags: + - prepare-tobiko + +- include: run-tobiko.yml + when: tobiko_run|bool + tags: + - tobiko-run + +- include: tobiko-results.yml + when: tobiko_run|bool + tags: + - tobiko-results diff --git a/roles/validate-tobiko/tasks/prepare-tobiko.yml b/roles/validate-tobiko/tasks/prepare-tobiko.yml new file mode 100644 index 000000000..cee52b3a2 --- /dev/null +++ b/roles/validate-tobiko/tasks/prepare-tobiko.yml @@ -0,0 +1,69 @@ +--- +- name: Install packages to generate subunit results + become: true + package: + name: + - "{{ python_package_prefix }}-os-testr" + - "{{ python_package_prefix }}-subunit" + - subunit-filters + state: present + +- name: Install packages required for create venv + become: true + package: + state: present + name: + - gcc + - libffi-devel + - openssl-devel + +- name: Install virtualenv + become: true + package: + state: present + name: "{{ python_package_prefix }}-virtualenv" + +- name: Install pip + become: true + package: + state: present + name: "{{ python_package_prefix }}-pip" + +- name: Copy tobiko to undercloud node + synchronize: + src: "{{ ansible_user_dir }}/src/opendev.org/x/tobiko" + dest: "{{ working_dir }}" + use_ssh_args: true + recursive: true + +- name: Get number of existing tobiko log files + shell: > + number_of_files=$(ls {{ tobiko_log_dir }} | grep -E "{{ tobiko_log_file_base }}-[0-9]+.log$" -c); + echo $(( $number_of_files + 1 )); + register: current_tobiko_log_file_number + +- name: Set tobiko_file_name + set_fact: + tobiko_log_file: "{{ tobiko_log_file_base }}-{{ current_tobiko_log_file_number.stdout }}.log" + +- name: Ensure tobiko config dir exists + file: + path: "{{ tobiko_config_dir }}" + state: directory + mode: '0755' + +- name: Create tobiko config file + template: + src: "tobiko.conf.j2" + dest: "{{ tobiko_config_dir }}/{{ tobiko_config_file }}" + mode: 0755 + +- name: Create tobiko network config script + template: + src: "configure_public_network.sh.j2" + dest: "{{ tobiko_config_dir }}/configure_public_network.sh" + mode: 0755 + +- name: Ensure floating IP network exists + shell: > + bash {{ tobiko_config_dir }}/configure_public_network.sh diff --git a/roles/validate-tobiko/tasks/run-tobiko.yml b/roles/validate-tobiko/tasks/run-tobiko.yml new file mode 100644 index 000000000..7cb48c8cb --- /dev/null +++ b/roles/validate-tobiko/tasks/run-tobiko.yml @@ -0,0 +1,12 @@ +--- +- name: Execute Tobiko + shell: > + set -o pipefail && + tools/ci/tox -e {{ tobiko_envlist }} {{ tobiko_extra_args }} 2>&1 {{ timestamper_cmd }} > {{ tobiko_log_dir }}/{{ tobiko_log_file }}; + args: + chdir: "{{ working_dir }}/tobiko" + executable: /bin/bash + register: tobiko_tests_run + ignore_errors: true + environment: + OS_CLOUD: "{{ tempest_cloud_name }}" diff --git a/roles/validate-tobiko/tasks/tobiko-results.yml b/roles/validate-tobiko/tasks/tobiko-results.yml new file mode 100644 index 000000000..0e7ec4554 --- /dev/null +++ b/roles/validate-tobiko/tasks/tobiko-results.yml @@ -0,0 +1,32 @@ +--- +- name: Check for .stestr directory + stat: + path: "{{ working_dir }}/tobiko/.stestr" + register: testr_dir + +- name: Define testr facts + set_fact: + testr_command: "{{ python_cmd }} -m stestr.cli" + +- name: Generate testrepository.subunit results file + shell: > + set -o pipefail && + {{ testr_command }} last --subunit > {{ tobiko_log_dir }}/testrepository.subunit + args: + chdir: "{{ working_dir }}/tobiko" + +- name: Generate HTML results file + shell: | + set -o pipefail && + subunit2html {{ tobiko_log_dir }}/testrepository.subunit {{ tobiko_log_dir }}/{{ tobiko_log_file }}.html + +- name: Fetch HTML results + fetch: + src: "{{ tobiko_log_dir }}/{{ tobiko_log_file }}.html" + dest: "{{ local_working_dir }}/{{ tobiko_log_file }}.html" + flat: true + +- name: Fail if tobiko tests did not succeed + assert: + that: + - "tobiko_tests_run.rc == 0" diff --git a/roles/validate-tobiko/templates/configure_public_network.sh.j2 b/roles/validate-tobiko/templates/configure_public_network.sh.j2 new file mode 100644 index 000000000..d0cd44a37 --- /dev/null +++ b/roles/validate-tobiko/templates/configure_public_network.sh.j2 @@ -0,0 +1,25 @@ +#!/bin/bash + +export OS_CLOUD={{ tempest_cloud_name }} + +openstack network list -c Name -f value | grep -q -e "^{{ tobiko_floating_ip_network }}$" +if [ $? -eq 0 ]; then + exit 0 +fi + +openstack network create {{ tobiko_floating_ip_network }} --external \ +{% if public_physical_network != '' %} + --provider-network-type {{ public_network_type }} \ + {% if public_segmentation_id != '' %} + --provider-segment {{ public_segmentation_id }} \ + {% endif %} + --provider-physical-network {{ public_physical_network }} +{% endif %} + +openstack subnet create ext-subnet \ + --allocation-pool \ + start={{ public_network_pool_start }},end={{ public_network_pool_end }} \ + --no-dhcp \ + --gateway {{ public_network_gateway }} \ + --network {{ tobiko_floating_ip_network }} \ + --subnet-range {{ floating_ip_cidr }} diff --git a/roles/validate-tobiko/templates/tobiko.conf.j2 b/roles/validate-tobiko/templates/tobiko.conf.j2 new file mode 100644 index 000000000..a3ecf64da --- /dev/null +++ b/roles/validate-tobiko/templates/tobiko.conf.j2 @@ -0,0 +1,18 @@ +[DEFAULT] +debug = True +log_file = "{{ tobiko_log_file }}" +log_dir = "{{ working_dir }}" + +{% if tobiko_no_proxy_servers is defined %} +[http] +no_proxy = "{{ tobiko_no_proxy_servers }}" +{% endif %} + +[nova] +key_file = "{{ tobiko_key_file_name }}" + +[neutron] +floating_network = "{{ tobiko_floating_ip_network }}" + +[glance] +images_dir = "{{ working_dir }}"/.tobiko/cache/glance/images"