From 92a2183d75af3638b4733c80c5ac4ae4e6432f60 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Thu, 7 May 2020 14:57:25 +0200 Subject: [PATCH] Add RH subscription manager support to role testing Vagrantfile This also fixes some lessero tobiko-inventory things Change-Id: I0b5080ad210e86e772940170c70972f3ecf93e81 --- roles/tests/Vagrantfile | 14 ++++++++------ roles/tests/provision.yaml | 17 +++++++++++++++-- roles/tests/test_infrared_plugin.yaml | 9 ++++----- roles/tobiko-inventory/defaults/main.yaml | 2 +- roles/tobiko-inventory/tasks/main.yaml | 6 ++++++ 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/roles/tests/Vagrantfile b/roles/tests/Vagrantfile index 01f799dc9..6f48ac34e 100644 --- a/roles/tests/Vagrantfile +++ b/roles/tests/Vagrantfile @@ -14,10 +14,11 @@ MEMORY = ENV.fetch("VM_SIZE", "1024").to_i # boxes at https://vagrantcloud.com/search. BOX = ENV.fetch("VM_BOX", "generic/centos8") -TOX_INI_DIR = '../..' - TEST_DIR = File.dirname(__FILE__) +TOBIKO_SRC_DIR = File.realpath(ENV.fetch( + 'TOBIKO_SRC_DIR', TEST_DIR + '/../..')) + UPPER_CONSTRAINTS_FILE = ENV.fetch( "UPPER_CONSTRAINTS_FILE", "https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt") @@ -32,6 +33,8 @@ NODES = { SSH_KEY_FILE = File.join([TEST_DIR, 'ssh_id']) +RH_USERNAME = ENV.fetch("RH_USERNAME", "") +RH_PASSWORD = ENV.fetch("RH_PASSWORD", "") # All Vagrant configuration is done below. The "2" in Vagrant.configure @@ -104,10 +107,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| node.vm.hostname = NODES['primary']['hostname'] node.vm.network "private_network", ip: NODES['primary']['ip'] - # No need to copy .tox/ dir to node to execute test cases - node.vm.synced_folder TOX_INI_DIR, "/vagrant", type: "rsync", - rsync__exclude: [".tox/"] - # Prepare VMs using ansible playbook node.vm.provision "ansible" do |ansible| ansible.playbook = "provision.yaml" @@ -115,6 +114,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ansible.extra_vars = { 'vagrant_nodes' => NODES, 'ssh_key_file' => SSH_KEY_FILE, + 'rh_username' => RH_USERNAME, + 'rh_password' => RH_PASSWORD, + 'tobiko_src_dir' => TOBIKO_SRC_DIR, } end diff --git a/roles/tests/provision.yaml b/roles/tests/provision.yaml index a9113eb4e..144fbb4cb 100644 --- a/roles/tests/provision.yaml +++ b/roles/tests/provision.yaml @@ -1,5 +1,19 @@ --- +- hosts: all + tasks: + - name: Register as user '{{ rh_username }}' and auto-subscribe to available content + become: yes + redhat_subscription: + state: present + username: '{{ rh_username }}' + password: '{{ rh_password }}' + auto_attach: yes + when: + - rh_username is defined + - rh_username != '' + + - hosts: primary tasks: - name: "copy /etc/resolv.conf" @@ -106,5 +120,4 @@ - hosts: primary roles: - role: tobiko-inventory - vars: - test_inventory_file: /vagrant/ansible_hosts + - role: tobiko-deploy diff --git a/roles/tests/test_infrared_plugin.yaml b/roles/tests/test_infrared_plugin.yaml index 72e54bff7..acb1ddfc8 100644 --- a/roles/tests/test_infrared_plugin.yaml +++ b/roles/tests/test_infrared_plugin.yaml @@ -2,8 +2,8 @@ - hosts: primary vars: - test_src_dir: /vagrant - test_collect_dir: '{{ test_src_dir }}/test_results' + test_collect_dir: '{{ test_dir }}/test_results' + roles: - tobiko-ensure-tox - tobiko-ensure-git @@ -21,7 +21,7 @@ '{{ tox_executable }}' -e infrared -- --host secondary --collect-dir '{{ test_collect_dir }}' - chdir: /vagrant + chdir: '{{ test_dir }}' environment: UPPER_CONSTRAINTS_FILE: '{{ remote_constraints_file }}' ignore_errors: yes @@ -38,7 +38,6 @@ - hosts: primary vars: - test_src_dir: /vagrant - test_collect_dir: '{{ test_src_dir }}/test_results' + test_collect_dir: '{{ test_dir }}/test_results' roles: - tobiko-check-collected-files diff --git a/roles/tobiko-inventory/defaults/main.yaml b/roles/tobiko-inventory/defaults/main.yaml index 39995c48c..114f31eaa 100644 --- a/roles/tobiko-inventory/defaults/main.yaml +++ b/roles/tobiko-inventory/defaults/main.yaml @@ -2,4 +2,4 @@ test_inventory_user: '{{ ansible_user }}' test_inventory_hostvars: {} -test_inventory_file: '{{ test_src_dir | realpath }}/ansible_hosts' +test_inventory_file: '{{ test_dir | realpath }}/ansible_hosts' diff --git a/roles/tobiko-inventory/tasks/main.yaml b/roles/tobiko-inventory/tasks/main.yaml index 749b3a452..8ed5a8305 100644 --- a/roles/tobiko-inventory/tasks/main.yaml +++ b/roles/tobiko-inventory/tasks/main.yaml @@ -49,6 +49,12 @@ - debug: var=test_inventory_hostvars +- name: "ensures inventory directory exists" + file: + path: '{{ test_inventory_file | dirname }}' + state: directory + + - name: "writes inventory file to: '{{ test_inventory_file }}'" template: src: 'test_inventory.j2'