Skip to content

Commit 3407427

Browse files
juanlufontgenaumannzhan9sanpre-commit-ci[bot]
authored
Plugin openstack (2) (#219)
* Add openstack driver * Add openstack test scenarios default: single instance multiple: multiple instances security_group: multiple instances with different sec_groups and rules * Add openstack playbooks create: create openstack destroy: destroy openstack prepare: prepare openstack instance * Add openstack network * Add all instances to local hosts * Add openstack.cloud to requirements * Add openstack network docs * Add openstack documentation * Increase PYTEST_REQPASS to 14 * Fix lint issues * Add openstack volume * Add openstack volume test * Add openstack volume docs * Refactor openstack volume creation * Fixes from PR #157 This commit add minor fixes described in PR <#157> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update conftest imports * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Gino Naumann <[email protected]> Co-authored-by: Jack <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fe3ceb6 commit 3407427

File tree

32 files changed

+1121
-1
lines changed

32 files changed

+1121
-1
lines changed

.ansible-lint-ignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ test/roles/azureplugin/molecule/default/create.yml yaml[octal-values]
1818
test/roles/azureplugin/molecule/default/destroy.yml yaml[octal-values]
1919

2020
test/roles/ec2plugin/molecule/default/destroy.yml risky-file-permissions
21+
22+
test/roles/openstackplugin/molecule/default/create.yml yaml[octal-values]
23+
test/roles/openstackplugin/molecule/default/destroy.yml yaml[octal-values]

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ubuntu-22.04
3535
needs: pre
3636
env:
37-
PYTEST_REQPASS: 13
37+
PYTEST_REQPASS: 14
3838
strategy:
3939
fail-fast: false
4040
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This repository contains the following molecule plugins:
77
- docker
88
- ec2
99
- gce
10+
- openstack
1011
- podman
1112
- vagrant
1213

doc/openstack/README.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
*************************
2+
Molecule Openstack Plugin
3+
*************************
4+
5+
Molecule Openstack is designed to allow use of Openstack
6+
for provisioning of test resources.
7+
8+
.. _quickstart:
9+
10+
Quickstart
11+
==========
12+
13+
Installation
14+
------------
15+
16+
.. code-block:: bash
17+
18+
pip install molecule-plugins
19+
20+
Create a scenario
21+
-----------------
22+
23+
In a pre-existing role
24+
^^^^^^^^^^^^^^^^^^^^^^
25+
.. code-block:: bash
26+
27+
molecule init scenario -d openstack
28+
29+
This will create a default scenario with the openstack driver
30+
in a molecule folder, located in the current working directory.
31+
32+
Example
33+
-------
34+
This is a molecule.yml example file
35+
36+
.. code-block:: yaml
37+
38+
dependency:
39+
name: galaxy
40+
driver:
41+
name: openstack
42+
platforms:
43+
- name: ubuntu2004
44+
flavor: m1.small
45+
image: Ubuntu_22.04
46+
user: ubuntu
47+
provisioner:
48+
name: ansible
49+
50+
Then run
51+
52+
.. code-block:: bash
53+
54+
molecule test
55+
56+
.. note::
57+
You need to configure `openstack authentication <https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html#config-environment-variables>` using config file or environment variables.
58+
59+
Documentation
60+
=============
61+
62+
Details on the parameters for the platforms section are detailed in
63+
`<platforms.rst>`__.
64+
65+
.. _license:
66+
67+
License
68+
=======
69+
70+
The `MIT`_ License.
71+
72+
.. _`MIT`: https://github.com/ansible/molecule/blob/master/LICENSE
73+
74+
The logo is licensed under the `Creative Commons NoDerivatives 4.0 License`_.
75+
76+
If you have some other use in mind, contact us.
77+
78+
.. _`Creative Commons NoDerivatives 4.0 License`: https://creativecommons.org/licenses/by-nd/4.0/

doc/openstack/platforms.rst

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
*********************
2+
Options documentation
3+
*********************
4+
5+
Authentication
6+
==============
7+
8+
See https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html#config-environment-variables
9+
10+
Platform Arguments
11+
==================
12+
13+
=============================== ===============================================
14+
Variable Description
15+
=============================== ===============================================
16+
description Set description for instance, \
17+
default = 'Molecule test instance'
18+
flavor Set flavor for instance
19+
image Set instance image
20+
network Mapping of network settings (optional)
21+
network.name Name of network
22+
network.create Create network, default = true
23+
network.router Mapping of network router settings
24+
network.router.name Name of router
25+
network.router.ext_network External gateway network
26+
network.router.snat Enable or disable snat, default = omit
27+
network.subnet Mapping of network subnet settings
28+
network.subnet.name Name of subnet
29+
network.subnet.cidr CIDR of subnet
30+
network.subnet.ipv IP Version, default = 4
31+
network.subnet.dns_nameservers List of dns nameservers, default = omit
32+
network.subnet.host_routers List of host router (destination, nexthop), \
33+
default = omit
34+
security_group Mapping of security_group settings (optional)
35+
security_group.name Name of security_group
36+
security_group.create Create security group, default = true
37+
security_group.description Description of security_group
38+
security_group.rules Ingress Rules (list) defined in security_group
39+
security_group.rules[].proto Protocol for rule
40+
security_group.rules[].port Port
41+
security_group.rules[].cidr Source IP address(es) in CIDR notation
42+
security_group.rules[].port_min Starting port (can't be used with port)
43+
security_group.rules[].port_max Ending port (can't be used with port)
44+
security_group.rules[].type IPv4 or IPv6, default 'IPv4'
45+
user Default user of image
46+
volume Mapping of volume settings (optional if \
47+
flavor provides volume)
48+
volume.size Size of volume (GB)
49+
=============================== ===============================================
50+
51+
52+
Image User
53+
==========
54+
55+
More information: https://docs.openstack.org/image-guide/obtain-images.html
56+
57+
Security Groups
58+
===============
59+
60+
If you specifiy a security group,
61+
the security group will be managed by create and destroy playbook.
62+
You can define some rules (see example below).
63+
64+
You can use unmanaged security groups by specifying the name of the group
65+
and setting `create` to `false` (see debian11 example below).
66+
In this case, the specified security group must exist.
67+
68+
Networks
69+
========
70+
71+
If you specify a network,
72+
the network will be managed by create and destroy playbook.
73+
You need to define a subnet and router (see example below).
74+
75+
You can use unmanaged network by specifying the name of the network
76+
and setting `create` to `false`.
77+
In this case, the specified network must exist.
78+
79+
80+
Volumes
81+
=======
82+
83+
If you specify a volume,
84+
the volume will be managed by create and destroy playbook.
85+
You need to define the size of the volume.
86+
87+
This setting is required if your flavor doesn't provide a disk.
88+
89+
Examples
90+
========
91+
92+
.. code-block:: yaml
93+
94+
platforms:
95+
- name: debian10
96+
flavor: m1.small
97+
image: Debian_10
98+
user: debian
99+
network:
100+
name: molecule
101+
router:
102+
name: router1
103+
ext_network: public
104+
subnet: subnet1
105+
subnet:
106+
name: subnet1
107+
cidr: 192.168.11.0/24
108+
ipv: 4 # default
109+
dns_nameservers: # default omit
110+
- 8.8.8.8
111+
host_routes: # default omit
112+
- destination: 192.168.0.0/24
113+
nexthop: 192.168.0.1
114+
security_group:
115+
name: molecule
116+
description: Molecule test
117+
rules:
118+
- proto: tcp
119+
port: 22
120+
cidr: 0.0.0.0/0
121+
- proto: tcp
122+
port: 22
123+
cidr: '::/0'
124+
type: IPv6
125+
- proto: icmp
126+
port: -1
127+
cidr: 0.0.0.0/0
128+
- proto: tcp
129+
port_min: 5000
130+
port_max: 5050
131+
cidr: 0.0.0.0/0
132+
- name: debian11
133+
flavor: m1.small
134+
image: Debian_11
135+
user: debian
136+
security_group:
137+
name: existing-sec
138+
create: false
139+
network:
140+
name: molecule # use network from debian10 instance
141+
- name: ubuntu2004
142+
falvor: m1.tiny
143+
image: Ubuntu_2004
144+
user: ubuntu
145+
security_group:
146+
name: molecule # use security group from debian10 instance
147+
network:
148+
name: existing-net # use existing network
149+
create: false
150+
volume:
151+
size: 10 # GB

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ selinux = [
8181
vagrant = [
8282
"python-vagrant",
8383
]
84+
openstack = [
85+
"openstacksdk >= 1.1.0"
86+
]
8487

8588
[tool.ruff]
8689
ignore = [
@@ -132,6 +135,7 @@ ec2 = "molecule_plugins.ec2.driver:EC2"
132135
gce = "molecule_plugins.gce.driver:GCE"
133136
podman = "molecule_plugins.podman.driver:Podman"
134137
vagrant = "molecule_plugins.vagrant.driver:Vagrant"
138+
openstack = "molecule_plugins.openstack.driver:Openstack"
135139

136140
[tool.setuptools_scm]
137141
local_scheme = "no-local-version"

requirements.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ collections:
1111
- name: community.crypto
1212
version: ">=1.8.0"
1313
- name: community.vagrant
14+
- name: openstack.cloud
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Molecule Openstack Driver."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"molecule_directory": "molecule",
3+
"role_name": "OVERRIDDEN",
4+
"scenario_name": "OVERRIDDEN"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
tasks:
5+
- name: "Include {{ cookiecutter.role_name }}"
6+
ansible.builtin.include_role:
7+
name: "{{ cookiecutter.role_name }}"

0 commit comments

Comments
 (0)