From 3c252d0a2d3e6ce599e0466c672a3262d6ad6aba Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Thu, 19 Oct 2023 15:12:29 +0100 Subject: [PATCH] add optional vagrant senairo for local testing and development. The libvirt and nova roles currently uses the delegated driver which runs molecule agaisnt localhost. This is requried for ci as the podman driver cannot be used with this role however it also means you must use a seperate development vm. This change readds supprot for using the molecule vagrant plugin for this role and configures the vagrant senario to use the prepare, converge and verify playbooks from the default delegated senario. Addtionally this change updates yamllint and ansible-lint to not scan files in a venv i.e. .venv in the root of the edpm-ansible repo. .venv is already ignored by .gitignore so this also only affect local development. the molecule-plugins min version is raised to 23.5.0 to include https://github.com/ansible-community/molecule-plugins/pull/142 --- .ansible-lint | 1 + .yamllint | 1 + molecule-requirements.txt | 2 +- .../molecule/default/molecule.yml | 2 + roles/edpm_libvirt/molecule/vagrant/README.md | 28 ++++++++++++++ .../molecule/vagrant/molecule.yml | 32 ++++++++++++++++ .../edpm_libvirt/molecule/vagrant/verify.yml | 4 ++ roles/edpm_nova/molecule/default/converge.yml | 2 +- roles/edpm_nova/molecule/default/molecule.yml | 2 + roles/edpm_nova/molecule/default/verify.yml | 7 +++- roles/edpm_nova/molecule/vagrant/README.md | 28 ++++++++++++++ roles/edpm_nova/molecule/vagrant/molecule.yml | 37 +++++++++++++++++++ roles/edpm_nova/molecule/vagrant/verify.yml | 4 ++ 13 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 roles/edpm_libvirt/molecule/vagrant/README.md create mode 100644 roles/edpm_libvirt/molecule/vagrant/molecule.yml create mode 100644 roles/edpm_libvirt/molecule/vagrant/verify.yml create mode 100644 roles/edpm_nova/molecule/vagrant/README.md create mode 100644 roles/edpm_nova/molecule/vagrant/molecule.yml create mode 100644 roles/edpm_nova/molecule/vagrant/verify.yml diff --git a/.ansible-lint b/.ansible-lint index af6f0c1e6..3cdc7ce29 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -13,6 +13,7 @@ exclude_paths: - tests - plugins/tests/molecule - contribute + - .venv parseable: true quiet: false verbosity: 1 diff --git a/.yamllint b/.yamllint index 5d79317b7..aba54803e 100644 --- a/.yamllint +++ b/.yamllint @@ -8,3 +8,4 @@ rules: ignore: | zuul.d/*.yaml + .venv diff --git a/molecule-requirements.txt b/molecule-requirements.txt index 83fba8758..51b141814 100644 --- a/molecule-requirements.txt +++ b/molecule-requirements.txt @@ -1,6 +1,6 @@ ansible-core==2.14.6 molecule>=5.1.0,<6.0.0 -molecule-plugins[podman]>=23.4.0 +molecule-plugins[podman,vagrant]>=23.5.0 pytest-testinfra # this is required for the molecule jobs ansi2html diff --git a/roles/edpm_libvirt/molecule/default/molecule.yml b/roles/edpm_libvirt/molecule/default/molecule.yml index 1415e0d29..531cf2c04 100644 --- a/roles/edpm_libvirt/molecule/default/molecule.yml +++ b/roles/edpm_libvirt/molecule/default/molecule.yml @@ -17,6 +17,8 @@ verifier: name: ansible scenario: test_sequence: + - destroy + - create - prepare - converge - verify diff --git a/roles/edpm_libvirt/molecule/vagrant/README.md b/roles/edpm_libvirt/molecule/vagrant/README.md new file mode 100644 index 000000000..bf4902b69 --- /dev/null +++ b/roles/edpm_libvirt/molecule/vagrant/README.md @@ -0,0 +1,28 @@ +********************************* +Vagrant driver installation guide +********************************* + +Requirements +============ + +* Vagrant +* Libvirt + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule-plugins[vagrant]\>=23.5.0' + +23.5.0+ is required to avoid a bug in the vagrant driver where molecule utils were not being imported correctly. +This molecule env will be used for local devleopment only and the default delegated env will be used for ci. +as a result its imporant that this senairo mearly contains the the info requried to prepare the vm +and calls the prepare, convernge and verify playbooks from default to keep them in sync. diff --git a/roles/edpm_libvirt/molecule/vagrant/molecule.yml b/roles/edpm_libvirt/molecule/vagrant/molecule.yml new file mode 100644 index 000000000..2529e9fb0 --- /dev/null +++ b/roles/edpm_libvirt/molecule/vagrant/molecule.yml @@ -0,0 +1,32 @@ +--- +dependency: + name: galaxy +driver: + name: vagrant + provider: + name: libvirt + provision: no + parallel: true + # default_box: 'generic/rocky9' + default_box: 'generic/centos9s' +platforms: +- name: compute-1 + memory: 8192 + cpus: 8 + provider_options: + cpu_mode: 'host-passthrough' + nested: true + machine_type: 'q35' + groups: + - compute +provisioner: + name: ansible + playbooks: + converge: ../default/converge.yml + prepare: ../default/prepare.yml +verifier: + name: ansible +scenario: + # we disable all tests so that we dont + # run this in ci. + test_sequence: [] diff --git a/roles/edpm_libvirt/molecule/vagrant/verify.yml b/roles/edpm_libvirt/molecule/vagrant/verify.yml new file mode 100644 index 000000000..43ed2b591 --- /dev/null +++ b/roles/edpm_libvirt/molecule/vagrant/verify.yml @@ -0,0 +1,4 @@ +--- + +- name: run default scenario verify playbooks + ansible.builtin.import_playbook: ../default/verify.yml diff --git a/roles/edpm_nova/molecule/default/converge.yml b/roles/edpm_nova/molecule/default/converge.yml index 486dab4a3..891a9fa31 100644 --- a/roles/edpm_nova/molecule/default/converge.yml +++ b/roles/edpm_nova/molecule/default/converge.yml @@ -14,4 +14,4 @@ roles: - role: osp.edpm.edpm_nova vars: - edpm_nova_config_src: "{{lookup('env', 'MOLECULE_SCENARIO_DIRECTORY')}}/test-data" + edpm_nova_config_src: "{{lookup('env', 'MOLECULE_PROJECT_DIRECTORY')}}/molecule/default/test-data" diff --git a/roles/edpm_nova/molecule/default/molecule.yml b/roles/edpm_nova/molecule/default/molecule.yml index e1324a52e..560184d9e 100644 --- a/roles/edpm_nova/molecule/default/molecule.yml +++ b/roles/edpm_nova/molecule/default/molecule.yml @@ -24,6 +24,8 @@ verifier: name: ansible scenario: test_sequence: + - destroy + - create - prepare - converge - verify diff --git a/roles/edpm_nova/molecule/default/verify.yml b/roles/edpm_nova/molecule/default/verify.yml index 84cffc2f2..4c6aa8897 100644 --- a/roles/edpm_nova/molecule/default/verify.yml +++ b/roles/edpm_nova/molecule/default/verify.yml @@ -45,10 +45,15 @@ - "Copying /var/lib/kolla/config_files/ssh-privatekey to /var/lib/nova/.ssh/ssh-privatekey" - "Copying /var/lib/kolla/config_files/02-nova-host-specific.conf to /etc/nova/nova.conf.d/02-nova-host-specific.conf" + - name: slurp host specific config + ansible.builtin.slurp: + src: /var/lib/openstack/config/nova/02-nova-host-specific.conf + register: host_specific_config + - name: Assert that my_ip is rendered into the host specific config ansible.builtin.assert: that: - - "'10.0.0.3' in lookup('ansible.builtin.file', '/var/lib/openstack/config/nova/02-nova-host-specific.conf')" + - "'10.0.0.3' in host_specific_config.content | b64decode" - name: Check if user exists ansible.builtin.getent: diff --git a/roles/edpm_nova/molecule/vagrant/README.md b/roles/edpm_nova/molecule/vagrant/README.md new file mode 100644 index 000000000..bf4902b69 --- /dev/null +++ b/roles/edpm_nova/molecule/vagrant/README.md @@ -0,0 +1,28 @@ +********************************* +Vagrant driver installation guide +********************************* + +Requirements +============ + +* Vagrant +* Libvirt + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule-plugins[vagrant]\>=23.5.0' + +23.5.0+ is required to avoid a bug in the vagrant driver where molecule utils were not being imported correctly. +This molecule env will be used for local devleopment only and the default delegated env will be used for ci. +as a result its imporant that this senairo mearly contains the the info requried to prepare the vm +and calls the prepare, convernge and verify playbooks from default to keep them in sync. diff --git a/roles/edpm_nova/molecule/vagrant/molecule.yml b/roles/edpm_nova/molecule/vagrant/molecule.yml new file mode 100644 index 000000000..1541d3551 --- /dev/null +++ b/roles/edpm_nova/molecule/vagrant/molecule.yml @@ -0,0 +1,37 @@ +--- +dependency: + name: galaxy +driver: + name: vagrant + provider: + name: libvirt + provision: no + parallel: true + default_box: 'generic/rocky9' +platforms: +- name: compute-1 + memory: 8192 + cpus: 8 + provider_options: + cpu_mode: 'host-passthrough' + nested: true + machine_type: 'q35' + groups: + - compute +provisioner: + name: ansible + playbooks: + converge: ../default/converge.yml + prepare: ../default/prepare.yml + inventory: + hosts: + all: + hosts: + compute-1: + ctlplane_ip: 10.0.0.3 +verifier: + name: ansible +scenario: + # we disable all tests so that we dont + # run this in ci. + test_sequence: [] diff --git a/roles/edpm_nova/molecule/vagrant/verify.yml b/roles/edpm_nova/molecule/vagrant/verify.yml new file mode 100644 index 000000000..43ed2b591 --- /dev/null +++ b/roles/edpm_nova/molecule/vagrant/verify.yml @@ -0,0 +1,4 @@ +--- + +- name: run default scenario verify playbooks + ansible.builtin.import_playbook: ../default/verify.yml