From e21d20958765d8781e3f7686aad15315b5f5adea Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Thu, 18 Feb 2021 18:11:12 +0100 Subject: [PATCH] Set undercloud_ssh_hostname on tobiko.conf Tobiko IR tasks failed on some downstream environments when the undercloud hostname was not undercloud-0 When this happens, the tobiko IR command can be executed with --undercloud-host or --underclout-ssh-host options RHOSENTDFG-1695 Change-Id: Ife055b62682044bdc446e6447ef9da562fe4bb73 Co-Author: Eduardo Olivares Toledo --- infrared_plugin/plugin.spec | 8 ++++++++ roles/tests/Vagrantfile | 17 +++++++++++------ roles/tests/provision.yaml | 6 ++++-- roles/tests/test_infrared_plugin.yaml | 3 +-- roles/tobiko-common/defaults/main.yaml | 2 +- roles/tobiko-configure/defaults/main.yaml | 7 +++++++ roles/tobiko-configure/tasks/main.yaml | 11 +++++++++++ roles/tobiko-inventory/defaults/main.yaml | 3 ++- roles/tobiko-inventory/tasks/main.yaml | 6 +++--- .../templates/test_inventory.j2 | 11 +++++++++-- 10 files changed, 57 insertions(+), 17 deletions(-) diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index 6aa63ca14..3234a9917 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -117,6 +117,14 @@ subparsers: type: Value help: Test case timeout in seconds ansible_variable: test_case_timeout + undercloud_host: + type: Value + help: inventory hostname of the undercloud host + ansible_variable: undercloud_hostname + undercloud_ssh_host: + type: Value + help: hostname or IP address to be used to connect to undercloud host + ansible_variable: undercloud_ssh_hostname - title: Run stage options: diff --git a/roles/tests/Vagrantfile b/roles/tests/Vagrantfile index cfe10ea75..d99854549 100644 --- a/roles/tests/Vagrantfile +++ b/roles/tests/Vagrantfile @@ -27,8 +27,12 @@ UPPER_CONSTRAINTS_FILE = ENV.fetch( NODES = { 'primary' => {'ip' => '172.18.161.6', 'hostname' => 'primary'}, - 'secondary' => {'ip' => '172.18.161.7', - 'hostname' => 'secondary'}, + 'secundary' => {'ip' => '172.18.161.7', + 'hostname' => 'secundary'}, +} + +GROUPS = { + 'undercloud' => ['secundary'] } @@ -96,10 +100,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| libvirt.memory = MEMORY end - # Spawn secondary VMs - config.vm.define 'secondary' do |node| - node.vm.hostname = NODES['secondary']['hostname'] - node.vm.network "private_network", ip: NODES['secondary']['ip'] + # Spawn secundary VMs + config.vm.define 'secundary' do |node| + node.vm.hostname = NODES['secundary']['hostname'] + node.vm.network "private_network", ip: NODES['secundary']['ip'] end # Spawn primary VM and run test cases on it @@ -113,6 +117,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ansible.limit = "all" ansible.extra_vars = { 'vagrant_nodes' => NODES, + 'vagrant_groups' => GROUPS, 'ssh_key_file' => SSH_KEY_FILE, 'rh_username' => RH_USERNAME, 'rh_password' => RH_PASSWORD, diff --git a/roles/tests/provision.yaml b/roles/tests/provision.yaml index 975cdc468..84004f4f4 100644 --- a/roles/tests/provision.yaml +++ b/roles/tests/provision.yaml @@ -126,8 +126,10 @@ set_fact: test_inventory_hostvars: '{{ test_inventory_hostvars_yaml | from_yaml }}' + test_inventory_groups: '{{ vagrant_groups }}' - debug: var=test_inventory_hostvars + - debug: var=test_inventory_groups - hosts: primary @@ -138,8 +140,8 @@ - name: "copy '{{ tobiko_src_dir }}' to '{{ tobiko_dir }}'" synchronize: src: "{{ tobiko_src_dir | realpath }}/." - dest: "{{ tobiko_dir | realpath }}" + dest: "{{ tobiko_dir }}" use_ssh_args: yes recursive: yes rsync_opts: - - '--exclude-from={{ tobiko_src_dir | realpath }}/.gitignore' + - '--exclude-from={{ tobiko_src_dir }}/.gitignore' diff --git a/roles/tests/test_infrared_plugin.yaml b/roles/tests/test_infrared_plugin.yaml index feec7aee8..73463bb1b 100644 --- a/roles/tests/test_infrared_plugin.yaml +++ b/roles/tests/test_infrared_plugin.yaml @@ -36,10 +36,9 @@ register: include_platform_vars - name: "run Tox InfraRed plugin" - command: + shell: cmd: > '{{ tox_executable }}' -e infrared -- - --host secondary --collect-dir '{{ test_collect_dir }}' chdir: '{{ test_dir }}' environment: diff --git a/roles/tobiko-common/defaults/main.yaml b/roles/tobiko-common/defaults/main.yaml index 9c0d0570c..b91adf113 100644 --- a/roles/tobiko-common/defaults/main.yaml +++ b/roles/tobiko-common/defaults/main.yaml @@ -8,7 +8,7 @@ test_become: '{{ not (test_no_become | bool) }}' # --- Test deploy options ----------------------------------------------------- -test_deploy_home: '{{ ansible_user_dir | realpath }}/src' +test_deploy_home: '{{ ansible_user_dir }}/src' git_base: 'https://opendev.org' diff --git a/roles/tobiko-configure/defaults/main.yaml b/roles/tobiko-configure/defaults/main.yaml index e90dcc3b7..6035b0a75 100644 --- a/roles/tobiko-configure/defaults/main.yaml +++ b/roles/tobiko-configure/defaults/main.yaml @@ -9,9 +9,16 @@ test_default_conf: testcase: timeout: "{{ test_case_timeout }}" + tripleo: + undercloud_ssh_hostname: "{{ undercloud_ssh_hostname }}" + test_log_debug: false test_case_timeout: 7200. # OpenStack client credentials stackrc_file: '{{ ansible_user_dir }}/overcloudrc' + +undercloud_hostname: '{{ groups.get("undercloud", []) | first | default("undercloud-0") }}' + +undercloud_ssh_hostname: '' diff --git a/roles/tobiko-configure/tasks/main.yaml b/roles/tobiko-configure/tasks/main.yaml index 6aa158df2..ced1afc6d 100644 --- a/roles/tobiko-configure/tasks/main.yaml +++ b/roles/tobiko-configure/tasks/main.yaml @@ -1,5 +1,16 @@ --- +- name: "pick undercloud SSH shotname from inventory" + set_fact: + undercloud_ssh_hostname: >- + {{ hostvars[undercloud_hostname].ansible_hostname | + default(undercloud_hostname) }} + when: + - (undercloud_ssh_hostname | length) == 0 + - (undercloud_hostname | length) > 0 + - undercloud_hostname in hostvars + + - name: "list configuration options" set_fact: test_conf_yaml: | diff --git a/roles/tobiko-inventory/defaults/main.yaml b/roles/tobiko-inventory/defaults/main.yaml index 114f31eaa..30ce06b76 100644 --- a/roles/tobiko-inventory/defaults/main.yaml +++ b/roles/tobiko-inventory/defaults/main.yaml @@ -2,4 +2,5 @@ test_inventory_user: '{{ ansible_user }}' test_inventory_hostvars: {} -test_inventory_file: '{{ test_dir | realpath }}/ansible_hosts' +test_inventory_groups: {} +test_inventory_file: '{{ test_dir }}/ansible_hosts' diff --git a/roles/tobiko-inventory/tasks/main.yaml b/roles/tobiko-inventory/tasks/main.yaml index 8ed5a8305..c9f74250b 100644 --- a/roles/tobiko-inventory/tasks/main.yaml +++ b/roles/tobiko-inventory/tasks/main.yaml @@ -45,15 +45,15 @@ - hostvars[hostname][varname] is defined - test_inventory_hostvars[hostname][varname] is not defined - -- debug: var=test_inventory_hostvars - +- debug: var=test_inventory_file - name: "ensures inventory directory exists" file: path: '{{ test_inventory_file | dirname }}' state: directory +- debug: var=test_inventory_hostvars +- debug: var=test_inventory_groups - name: "writes inventory file to: '{{ test_inventory_file }}'" template: diff --git a/roles/tobiko-inventory/templates/test_inventory.j2 b/roles/tobiko-inventory/templates/test_inventory.j2 index 4ea3cd358..dc51181e8 100644 --- a/roles/tobiko-inventory/templates/test_inventory.j2 +++ b/roles/tobiko-inventory/templates/test_inventory.j2 @@ -1,8 +1,15 @@ [all] -{% for name, vars in (test_inventory_hostvars | dictsort) %} -{{ name }} ansible_host={{ vars.ansible_host }} +{% for host, vars in (test_inventory_hostvars | dictsort) %} +{{ host }} ansible_host={{ vars.ansible_host }} {% endfor %} [all:vars] ansible_python_interpreter = {{ test_inventory_python_interpreter }} ansible_user = {{ test_inventory_user }} + +{% for group, hosts in (test_inventory_groups | dictsort) %} +[{{ group }}] +{% for host in hosts %} +{{ host }} +{% endfor %} +{% endfor %}