Skip to content

Commit

Permalink
add optional vagrant senairo for local testing and development.
Browse files Browse the repository at this point in the history
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
ansible-community/molecule-plugins#142
  • Loading branch information
SeanMooney committed Dec 21, 2023
1 parent 467848f commit 3c252d0
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 3 deletions.
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exclude_paths:
- tests
- plugins/tests/molecule
- contribute
- .venv
parseable: true
quiet: false
verbosity: 1
Expand Down
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ rules:

ignore: |
zuul.d/*.yaml
.venv
2 changes: 1 addition & 1 deletion molecule-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions roles/edpm_libvirt/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ verifier:
name: ansible
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
28 changes: 28 additions & 0 deletions roles/edpm_libvirt/molecule/vagrant/README.md
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 32 additions & 0 deletions roles/edpm_libvirt/molecule/vagrant/molecule.yml
Original file line number Diff line number Diff line change
@@ -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: []
4 changes: 4 additions & 0 deletions roles/edpm_libvirt/molecule/vagrant/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

- name: run default scenario verify playbooks
ansible.builtin.import_playbook: ../default/verify.yml
2 changes: 1 addition & 1 deletion roles/edpm_nova/molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions roles/edpm_nova/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ verifier:
name: ansible
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
7 changes: 6 additions & 1 deletion roles/edpm_nova/molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions roles/edpm_nova/molecule/vagrant/README.md
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 37 additions & 0 deletions roles/edpm_nova/molecule/vagrant/molecule.yml
Original file line number Diff line number Diff line change
@@ -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: []
4 changes: 4 additions & 0 deletions roles/edpm_nova/molecule/vagrant/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

- name: run default scenario verify playbooks
ansible.builtin.import_playbook: ../default/verify.yml

0 comments on commit 3c252d0

Please sign in to comment.