Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin openstack (2) #219

Merged
merged 20 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ test/roles/azureplugin/molecule/default/create.yml yaml[octal-values]
test/roles/azureplugin/molecule/default/destroy.yml yaml[octal-values]

test/roles/ec2plugin/molecule/default/destroy.yml risky-file-permissions

test/roles/openstackplugin/molecule/default/create.yml yaml[octal-values]
test/roles/openstackplugin/molecule/default/destroy.yml yaml[octal-values]
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-22.04
needs: pre
env:
PYTEST_REQPASS: 13
PYTEST_REQPASS: 14
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This repository contains the following molecule plugins:
- docker
- ec2
- gce
- openstack
- podman
- vagrant

Expand Down
78 changes: 78 additions & 0 deletions doc/openstack/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
*************************
Molecule Openstack Plugin
*************************

Molecule Openstack is designed to allow use of Openstack
for provisioning of test resources.

.. _quickstart:

Quickstart
==========

Installation
------------

.. code-block:: bash

pip install molecule-plugins

Create a scenario
-----------------

In a pre-existing role
^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: bash

molecule init scenario -d openstack

This will create a default scenario with the openstack driver
in a molecule folder, located in the current working directory.

Example
-------
This is a molecule.yml example file

.. code-block:: yaml

dependency:
name: galaxy
driver:
name: openstack
platforms:
- name: ubuntu2004
flavor: m1.small
image: Ubuntu_22.04
user: ubuntu
provisioner:
name: ansible

Then run

.. code-block:: bash

molecule test

.. note::
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.

Documentation
=============

Details on the parameters for the platforms section are detailed in
`<platforms.rst>`__.

.. _license:

License
=======

The `MIT`_ License.

.. _`MIT`: https://github.com/ansible/molecule/blob/master/LICENSE

The logo is licensed under the `Creative Commons NoDerivatives 4.0 License`_.

If you have some other use in mind, contact us.

.. _`Creative Commons NoDerivatives 4.0 License`: https://creativecommons.org/licenses/by-nd/4.0/
151 changes: 151 additions & 0 deletions doc/openstack/platforms.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
*********************
Options documentation
*********************

Authentication
==============

See https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html#config-environment-variables

Platform Arguments
==================

=============================== ===============================================
Variable Description
=============================== ===============================================
description Set description for instance, \
default = 'Molecule test instance'
flavor Set flavor for instance
image Set instance image
network Mapping of network settings (optional)
network.name Name of network
network.create Create network, default = true
network.router Mapping of network router settings
network.router.name Name of router
network.router.ext_network External gateway network
network.router.snat Enable or disable snat, default = omit
network.subnet Mapping of network subnet settings
network.subnet.name Name of subnet
network.subnet.cidr CIDR of subnet
network.subnet.ipv IP Version, default = 4
network.subnet.dns_nameservers List of dns nameservers, default = omit
network.subnet.host_routers List of host router (destination, nexthop), \
default = omit
security_group Mapping of security_group settings (optional)
security_group.name Name of security_group
security_group.create Create security group, default = true
security_group.description Description of security_group
security_group.rules Ingress Rules (list) defined in security_group
security_group.rules[].proto Protocol for rule
security_group.rules[].port Port
security_group.rules[].cidr Source IP address(es) in CIDR notation
security_group.rules[].port_min Starting port (can't be used with port)
security_group.rules[].port_max Ending port (can't be used with port)
security_group.rules[].type IPv4 or IPv6, default 'IPv4'
user Default user of image
volume Mapping of volume settings (optional if \
flavor provides volume)
volume.size Size of volume (GB)
=============================== ===============================================


Image User
==========

More information: https://docs.openstack.org/image-guide/obtain-images.html

Security Groups
===============

If you specifiy a security group,
the security group will be managed by create and destroy playbook.
You can define some rules (see example below).

You can use unmanaged security groups by specifying the name of the group
and setting `create` to `false` (see debian11 example below).
In this case, the specified security group must exist.

Networks
========

If you specify a network,
the network will be managed by create and destroy playbook.
You need to define a subnet and router (see example below).

You can use unmanaged network by specifying the name of the network
and setting `create` to `false`.
In this case, the specified network must exist.


Volumes
=======

If you specify a volume,
the volume will be managed by create and destroy playbook.
You need to define the size of the volume.

This setting is required if your flavor doesn't provide a disk.

Examples
========

.. code-block:: yaml

platforms:
- name: debian10
flavor: m1.small
image: Debian_10
user: debian
network:
name: molecule
router:
name: router1
ext_network: public
subnet: subnet1
subnet:
name: subnet1
cidr: 192.168.11.0/24
ipv: 4 # default
dns_nameservers: # default omit
- 8.8.8.8
host_routes: # default omit
- destination: 192.168.0.0/24
nexthop: 192.168.0.1
security_group:
name: molecule
description: Molecule test
rules:
- proto: tcp
port: 22
cidr: 0.0.0.0/0
- proto: tcp
port: 22
cidr: '::/0'
type: IPv6
- proto: icmp
port: -1
cidr: 0.0.0.0/0
- proto: tcp
port_min: 5000
port_max: 5050
cidr: 0.0.0.0/0
- name: debian11
flavor: m1.small
image: Debian_11
user: debian
security_group:
name: existing-sec
create: false
network:
name: molecule # use network from debian10 instance
- name: ubuntu2004
falvor: m1.tiny
image: Ubuntu_2004
user: ubuntu
security_group:
name: molecule # use security group from debian10 instance
network:
name: existing-net # use existing network
create: false
volume:
size: 10 # GB
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ selinux = [
vagrant = [
"python-vagrant",
]
openstack = [
"openstacksdk >= 1.1.0"
]

[tool.ruff]
ignore = [
Expand Down Expand Up @@ -132,6 +135,7 @@ ec2 = "molecule_plugins.ec2.driver:EC2"
gce = "molecule_plugins.gce.driver:GCE"
podman = "molecule_plugins.podman.driver:Podman"
vagrant = "molecule_plugins.vagrant.driver:Vagrant"
openstack = "molecule_plugins.openstack.driver:Openstack"

[tool.setuptools_scm]
local_scheme = "no-local-version"
Expand Down
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ collections:
- name: community.crypto
version: ">=1.8.0"
- name: community.vagrant
- name: openstack.cloud
1 change: 1 addition & 0 deletions src/molecule_plugins/openstack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Molecule Openstack Driver."""
5 changes: 5 additions & 0 deletions src/molecule_plugins/openstack/cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"molecule_directory": "molecule",
"role_name": "OVERRIDDEN",
"scenario_name": "OVERRIDDEN"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include {{ cookiecutter.role_name }}"
ansible.builtin.include_role:
name: "{{ cookiecutter.role_name }}"
Loading