From ac7a4a6d610c324a64ad0303ad7718e90f4c6cd8 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 8 Apr 2020 15:21:32 +0200 Subject: [PATCH] Switch to 2-node configuration for IR plugin testing Change-Id: Ifeed49ee6a5f57fc2ebf69adbae16894ad3c69a2 --- playbooks/infrared/run.yaml | 39 +--------- roles/tests/Vagrantfile | 2 +- roles/tests/provision.yaml | 51 ++++++------ roles/tests/templates/ansible_hosts.j2 | 9 --- roles/tests/templates/hosts.j2 | 1 - roles/tests/test_infrared_plugin.yaml | 31 ++------ roles/tests/vars/provision-CentOS-8.yaml | 3 - roles/tests/vars/provision-Ubuntu.yaml | 3 - .../meta/main.yaml | 4 + .../tasks/main.yaml | 40 ++++++++++ roles/tobiko-inventory/defaults/main.yaml | 5 ++ roles/tobiko-inventory/meta/main.yaml | 4 + roles/tobiko-inventory/tasks/main.yaml | 65 ++++++++++++++++ .../templates/test_inventory.j2 | 8 ++ .../vars/test-inventory-CentOS-7.yaml | 3 + .../vars/test-inventory-RedHat.yaml | 3 + .../vars/test-inventory-Ubuntu.yaml | 3 + zuul.d/infrared.yaml | 14 +++- zuul.d/nodes.yaml | 78 +++++++++++-------- 19 files changed, 229 insertions(+), 137 deletions(-) delete mode 100644 roles/tests/templates/ansible_hosts.j2 delete mode 100644 roles/tests/vars/provision-CentOS-8.yaml delete mode 100644 roles/tests/vars/provision-Ubuntu.yaml create mode 100644 roles/tobiko-check-collected-files/meta/main.yaml create mode 100644 roles/tobiko-check-collected-files/tasks/main.yaml create mode 100644 roles/tobiko-inventory/defaults/main.yaml create mode 100644 roles/tobiko-inventory/meta/main.yaml create mode 100644 roles/tobiko-inventory/tasks/main.yaml create mode 100644 roles/tobiko-inventory/templates/test_inventory.j2 create mode 100644 roles/tobiko-inventory/vars/test-inventory-CentOS-7.yaml create mode 100644 roles/tobiko-inventory/vars/test-inventory-RedHat.yaml create mode 100644 roles/tobiko-inventory/vars/test-inventory-Ubuntu.yaml diff --git a/playbooks/infrared/run.yaml b/playbooks/infrared/run.yaml index 7928884c3..0428485ac 100644 --- a/playbooks/infrared/run.yaml +++ b/playbooks/infrared/run.yaml @@ -1,39 +1,8 @@ --- -- hosts: all - vars: - zuul_output_dir: '{{ ansible_user_dir }}/zuul-output' - test_collect_dir: '{{ zuul_output_dir }}/logs' - +- hosts: primary roles: - role: tobiko-ensure-python3 - - - name: "run Tox InfraRed plugin" - role: tox - vars: - tox_envlist: infrared - tox_extra_args: '-- --collect-dir {{ test_collect_dir | quote }}' - - tasks: - - name: "list collected files" - command: > - ls '{{ test_collect_dir }}' - register: list_test_result_files - - - name: "set collected files fact" - set_fact: - collected_files: '{{ list_test_result_files.stdout_lines }}' - - - name: "show collected files" - debug: var=collected_files - - - name: "check collected files" - assert: - that: - - item in collected_files - loop: - - tobiko.log - - tobiko.conf - - test_results.html - - test_results.subunit - - test_results.xml + - role: tobiko-inventory + - role: tox + - role: tobiko-check-collected-files diff --git a/roles/tests/Vagrantfile b/roles/tests/Vagrantfile index 609dd8dc7..1d28dcbb8 100644 --- a/roles/tests/Vagrantfile +++ b/roles/tests/Vagrantfile @@ -8,7 +8,7 @@ VAGRANTFILE_API_VERSION = "2" CPUS = 4 # Customize the amount of memory on the VM -MEMORY = ENV.fetch("VM_SIZE", "512").to_i +MEMORY = ENV.fetch("VM_SIZE", "1024").to_i # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. diff --git a/roles/tests/provision.yaml b/roles/tests/provision.yaml index 6db873d0f..a9113eb4e 100644 --- a/roles/tests/provision.yaml +++ b/roles/tests/provision.yaml @@ -1,25 +1,5 @@ --- -- hosts: all - tasks: - - name: "show platform id variables" - debug: - msg: - ansible_architecture: '{{ ansible_architecture }}' - ansible_distribution: '{{ ansible_distribution }}' - ansible_distribution_major_version: '{{ ansible_distribution_major_version }}' - ansible_os_family: '{{ ansible_os_family }}' - - - name: "include platform variables" - include_vars: "{{ item }}" - with_first_found: - - "provision-{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml" - - "provision-{{ ansible_distribution }}.{{ ansible_architecture }}.yaml" - - "provision-{{ ansible_distribution }}.yaml" - - "provision-{{ ansible_os_family }}.yaml" - register: include_platform_vars - - - hosts: primary tasks: - name: "copy /etc/resolv.conf" @@ -66,11 +46,6 @@ - '' - '.pub' - - name: "make Ansible inventory file with vagrant nodes" - template: - src: 'ansible_hosts.j2' - dest: '/vagrant/ansible_hosts' - - hosts: all tasks: @@ -92,12 +67,12 @@ - hosts: primary tasks: - - name: "check ICMP connectivity" shell: | set -xe ping -c 1 '{{ item.1.ip }}' ping -c 1 '{{ item.1.hostname }}' + changed_when: false register: check_icmp_connectivity loop: '{{ vagrant_nodes | dictsort }}' @@ -107,5 +82,29 @@ ssh '{{ item.1.ip }}' hostname ssh '{{ item.1.hostname }}' hostname ssh '{{ item.0 }}' hostname + changed_when: false register: check_ssh_connectivity loop: '{{ vagrant_nodes | dictsort }}' + + - name: "set test_inventory_hostvars_yaml fact" + set_fact: + test_inventory_hostvars_yaml: | + --- + {% for name, node in (vagrant_nodes | dictsort) %} + {{ name }}: + ansible_host: {{ node.hostname }} + {% endfor %} + + - name: "set test_inventory_hostvars fact" + set_fact: + test_inventory_hostvars: + '{{ test_inventory_hostvars_yaml | from_yaml }}' + + - debug: var=test_inventory_hostvars + + +- hosts: primary + roles: + - role: tobiko-inventory + vars: + test_inventory_file: /vagrant/ansible_hosts diff --git a/roles/tests/templates/ansible_hosts.j2 b/roles/tests/templates/ansible_hosts.j2 deleted file mode 100644 index c2f81ac1e..000000000 --- a/roles/tests/templates/ansible_hosts.j2 +++ /dev/null @@ -1,9 +0,0 @@ - -[vagrant] -{% for node in (vagrant_nodes | dictsort) %} -{{ node.0 }} -{% endfor %} - -[vagrant:vars] -ansible_python_interpreter = {{ ansible_python_interpreter }} - diff --git a/roles/tests/templates/hosts.j2 b/roles/tests/templates/hosts.j2 index f38cdc8a6..ed4a945fa 100644 --- a/roles/tests/templates/hosts.j2 +++ b/roles/tests/templates/hosts.j2 @@ -11,4 +11,3 @@ {% for node in (vagrant_nodes | dictsort) %} {{ node.1.ip }} {{ node.1.hostname }} {% endfor %} - diff --git a/roles/tests/test_infrared_plugin.yaml b/roles/tests/test_infrared_plugin.yaml index 1d9e2a6e5..d0e4e4ed3 100644 --- a/roles/tests/test_infrared_plugin.yaml +++ b/roles/tests/test_infrared_plugin.yaml @@ -1,18 +1,16 @@ --- - hosts: primary - vars: test_src_dir: /vagrant test_collect_dir: '{{ test_src_dir }}/test_results' - roles: - tobiko-ensure-tox - tobiko-ensure-git - tobiko-ensure-rsync tasks: - - name: "remove collected files" + - name: "remove '{{ test_collect_dir }}' dir" file: path: '{{ test_collect_dir }}' state: absent @@ -35,25 +33,10 @@ when: run_tox is failed failed_when: yes - - name: "list collected files" - command: > - ls '{{ test_collect_dir }}' - register: list_test_result_files - - name: "set collected files fact" - set_fact: - collected_files: '{{ list_test_result_files.stdout_lines }}' - - - name: "show collected files" - debug: var=collected_files - - - name: "check collected files" - assert: - that: - - item in collected_files - loop: - - tobiko.log - - tobiko.conf - - test_results.html - - test_results.subunit - - test_results.xml +- hosts: primary + vars: + test_src_dir: /vagrant + test_collect_dir: '{{ test_src_dir }}/test_results' + roles: + - tobiko-check-collected-files diff --git a/roles/tests/vars/provision-CentOS-8.yaml b/roles/tests/vars/provision-CentOS-8.yaml deleted file mode 100644 index bdb035e47..000000000 --- a/roles/tests/vars/provision-CentOS-8.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- - -ansible_python_interpreter: /usr/libexec/platform-python diff --git a/roles/tests/vars/provision-Ubuntu.yaml b/roles/tests/vars/provision-Ubuntu.yaml deleted file mode 100644 index 165337ecd..000000000 --- a/roles/tests/vars/provision-Ubuntu.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- - -ansible_python_interpreter: /usr/bin/python3 diff --git a/roles/tobiko-check-collected-files/meta/main.yaml b/roles/tobiko-check-collected-files/meta/main.yaml new file mode 100644 index 000000000..0d4361583 --- /dev/null +++ b/roles/tobiko-check-collected-files/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: tobiko-common diff --git a/roles/tobiko-check-collected-files/tasks/main.yaml b/roles/tobiko-check-collected-files/tasks/main.yaml new file mode 100644 index 000000000..00a0a125b --- /dev/null +++ b/roles/tobiko-check-collected-files/tasks/main.yaml @@ -0,0 +1,40 @@ +--- + +- name: "find for collected files in '{{ test_collect_dir }}'" + find: + paths: + - "{{ test_collect_dir }}" + patterns: + - "tobiko.conf" + - "tobiko.log" + - "{{ test_report_name }}*.log" + - "{{ test_report_name }}*.subunit" + - "{{ test_report_name }}*.html" + - "{{ test_report_name }}*.xml" + register: find_collected_files + + +- name: "set collected_files fact" + set_fact: + collected_files: > + {{ find_collected_files.files | + map(attribute='path') | + map('basename') | + list }} + + +- block: + - name: "check collected files" + assert: + that: + - item in collected_files + loop: + - tobiko.log + - tobiko.conf + - '{{ test_report_name }}.html' + - '{{ test_report_name }}.subunit' + - '{{ test_report_name }}.xml' + + rescue: + - debug: var=collected_files + failed_when: yes diff --git a/roles/tobiko-inventory/defaults/main.yaml b/roles/tobiko-inventory/defaults/main.yaml new file mode 100644 index 000000000..39995c48c --- /dev/null +++ b/roles/tobiko-inventory/defaults/main.yaml @@ -0,0 +1,5 @@ +--- + +test_inventory_user: '{{ ansible_user }}' +test_inventory_hostvars: {} +test_inventory_file: '{{ test_src_dir | realpath }}/ansible_hosts' diff --git a/roles/tobiko-inventory/meta/main.yaml b/roles/tobiko-inventory/meta/main.yaml new file mode 100644 index 000000000..0d4361583 --- /dev/null +++ b/roles/tobiko-inventory/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: tobiko-common diff --git a/roles/tobiko-inventory/tasks/main.yaml b/roles/tobiko-inventory/tasks/main.yaml new file mode 100644 index 000000000..116fc7921 --- /dev/null +++ b/roles/tobiko-inventory/tasks/main.yaml @@ -0,0 +1,65 @@ +--- + +- name: "read platform vars from file" + include_vars: "{{ item }}" + with_first_found: + - "test-inventory-{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml" + - "test-inventory-{{ ansible_distribution }}.{{ ansible_architecture }}.yaml" + - "test-inventory-{{ ansible_distribution }}.yaml" + - "test-inventory-{{ ansible_os_family }}.yaml" + register: include_platform_vars + + +- debug: var=test_inventory_python_interpreter + + +- when: test_inventory_user is not defined + block: + - name: "get remote username" + command: whoami + changed_when: false + become: false + register: get_inventory_user + + - name: "set test_inventory_user fact" + set_fact: + test_inventory_user: "{{ get_inventory_user.stdout_lines | first }}" + + +- debug: var=test_inventory_user + + +- name: "get default test_inventory_hostvars entries from hostvars" + set_fact: + test_inventory_hostvars: > + {{ {hostname: {varname: value} } | + combine(test_inventory_hostvars) }} + vars: + hostname: '{{ item.0 }}' + varname: '{{ item.1 }}' + value: '{{ hostvars[hostname][varname] }}' + loop: "{{ hostvars.keys() | product(['ansible_host']) | list }}" + loop_control: + label: '{{ hostname }}.{{ varname }} = {{ value }}' + when: + - hostvars[hostname][varname] is defined + - test_inventory_hostvars[hostname][varname] is not defined + + +- debug: var=test_inventory_hostvars + + +- name: "writes inventory file to: '{{ test_inventory_file }}'" + template: + src: 'test_inventory.j2' + dest: '{{ test_inventory_file }}' + + +- name: "read inventory file from: '{{ test_inventory_file }}'" + command: "cat '{{ test_inventory_file }}'" + changed_when: false + register: read_test_inventory_file + + +- name: "show inventory file: '{{ test_inventory_file }}'" + debug: var=read_test_inventory_file.stdout_lines diff --git a/roles/tobiko-inventory/templates/test_inventory.j2 b/roles/tobiko-inventory/templates/test_inventory.j2 new file mode 100644 index 000000000..4ea3cd358 --- /dev/null +++ b/roles/tobiko-inventory/templates/test_inventory.j2 @@ -0,0 +1,8 @@ +[all] +{% for name, vars in (test_inventory_hostvars | dictsort) %} +{{ name }} ansible_host={{ vars.ansible_host }} +{% endfor %} + +[all:vars] +ansible_python_interpreter = {{ test_inventory_python_interpreter }} +ansible_user = {{ test_inventory_user }} diff --git a/roles/tobiko-inventory/vars/test-inventory-CentOS-7.yaml b/roles/tobiko-inventory/vars/test-inventory-CentOS-7.yaml new file mode 100644 index 000000000..b71835a50 --- /dev/null +++ b/roles/tobiko-inventory/vars/test-inventory-CentOS-7.yaml @@ -0,0 +1,3 @@ +--- + +test_inventory_python_interpreter: /usr/bin/python diff --git a/roles/tobiko-inventory/vars/test-inventory-RedHat.yaml b/roles/tobiko-inventory/vars/test-inventory-RedHat.yaml new file mode 100644 index 000000000..d278e927a --- /dev/null +++ b/roles/tobiko-inventory/vars/test-inventory-RedHat.yaml @@ -0,0 +1,3 @@ +--- + +test_inventory_python_interpreter: /usr/libexec/platform-python diff --git a/roles/tobiko-inventory/vars/test-inventory-Ubuntu.yaml b/roles/tobiko-inventory/vars/test-inventory-Ubuntu.yaml new file mode 100644 index 000000000..7167d5ef4 --- /dev/null +++ b/roles/tobiko-inventory/vars/test-inventory-Ubuntu.yaml @@ -0,0 +1,3 @@ +--- + +test_inventory_python_interpreter: /usr/bin/python3 diff --git a/zuul.d/infrared.yaml b/zuul.d/infrared.yaml index 768af3b85..786345804 100644 --- a/zuul.d/infrared.yaml +++ b/zuul.d/infrared.yaml @@ -8,12 +8,20 @@ description: | Run test cases using tobiko infrared plugin run: playbooks/infrared/run.yaml + vars: + test_collect_dir: '{{ zuul_output_dir }}/logs' + test_inventory_file: '{{ zuul_work_dir }}/ansible_hosts' + tox_envlist: infrared + tox_extra_args: -- --host secondary --collect-dir {{ test_collect_dir | quote }} + tox_environ: + ANSIBLE_INVENTORY: '{{ test_inventory_file }}' + zuul_output_dir: '{{ ansible_user_dir }}/zuul-output' - job: name: tobiko-tox-infrared-centos-7 parent: tobiko-tox-infrared - nodeset: centos-7 + nodeset: centos-7-2-node voting: false description: | Run py36 test cases using tobiko infrared plugin on CentOS 7 @@ -22,7 +30,7 @@ - job: name: tobiko-tox-infrared-centos-8 parent: tobiko-tox-infrared - nodeset: centos-8 + nodeset: centos-8-2-node voting: false description: | Run py36 test cases using tobiko infrared plugin on CentOS 8 @@ -30,7 +38,7 @@ - job: name: tobiko-tox-infrared-ubuntu-bionic parent: tobiko-tox-infrared - nodeset: ubuntu-bionic + nodeset: ubuntu-bionic-2-node voting: false description: | Run py36 test cases using tobiko infrared plugin on Ubuntu Bionic diff --git a/zuul.d/nodes.yaml b/zuul.d/nodes.yaml index d56e8b532..7079e1ae5 100644 --- a/zuul.d/nodes.yaml +++ b/zuul.d/nodes.yaml @@ -1,33 +1,47 @@ - nodeset: - name: openstack-three-node-centos-7 - nodes: - - name: controller - label: centos-7 - - name: compute1 - label: centos-7 - - name: compute2 - label: centos-7 - groups: - # Node where tests are executed and test results collected - - name: tempest - nodes: - - controller - # Nodes running the compute service - - name: compute - nodes: - - compute1 - - compute2 - # Nodes that are not the controller - - name: subnode - nodes: - - compute1 - - compute2 - # Switch node for multinode networking setup - - name: switch - nodes: - - controller - # Peer nodes for multinode networking setup - - name: peers - nodes: - - compute1 - - compute2 + name: centos-8-2-node + nodes: + - name: primary + label: centos-8 + - name: secondary + label: centos-8 + groups: + - name: subnodes + nodes: + - secondary + + +- nodeset: + name: openstack-three-node-centos-7 + nodes: + - name: controller + label: centos-7 + - name: compute1 + label: centos-7 + - name: compute2 + label: centos-7 + + groups: + # Node where tests are executed and test results collected + - name: tempest + nodes: + - controller + # Nodes running the compute service + - name: compute + nodes: + - compute1 + - compute2 + # Nodes that are not the controller + - name: subnode + nodes: + - compute1 + - compute2 + # Switch node for multinode networking setup + - name: switch + nodes: + - controller + # Peer nodes for multinode networking setup + - name: peers + nodes: + - compute1 + - compute2