From 5237dd7558cab08f655975d6810e7520545c47ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 12:56:36 +0200 Subject: [PATCH 01/25] Improve create playbook: - set default alias to ubuntu/jammy/amd64 - allow to configure source params with source_* vars - allow to configure timeout, project and target --- src/molecule_lxd/playbooks/create.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/molecule_lxd/playbooks/create.yml b/src/molecule_lxd/playbooks/create.yml index 1f9dea8..50d4ebd 100644 --- a/src/molecule_lxd/playbooks/create.yml +++ b/src/molecule_lxd/playbooks/create.yml @@ -11,7 +11,7 @@ type: image mode: pull server: https://images.linuxcontainers.org - alias: ubuntu/jammy + alias: ubuntu/jammy/amd64 protocol: simplestreams tasks: @@ -19,21 +19,31 @@ community.general.lxd_container: name: "{{ item.name }}" state: started - source: "{{ default_source | combine(item.source | default({})) }}" - config: "{{ item.config | default({}) }}" + type: "{{ item.type | default(omit) }}" architecture: "{{ item.architecture | default(omit) }}" + source: >- + {{ + { + 'type': item.source_type | default(default_source.type), + 'mode': item.source_mode | default(default_source.mode), + 'server': item.source_server | default('https://cloud-images.ubuntu.com/releases' if item.type | default('container') == 'virtual-machine' else default_source.server), + 'alias': item.source_alias | default(default_source.alias), + 'protocol': item.source_protocol | default(default_source.protocol) + } | combine(item.source | default({})) + }} + profiles: "{{ item.profiles | default(omit) }}" + project: "{{ item.project | default(omit) }}" + config: "{{ item.config | default({}) }}" devices: "{{ item.devices | default(omit) }}" ignore_volatile_options: "{{ item.ignore_volatile_options | default(false) }}" - target: "{{ item.target | default(omit) }}" - type: "{{ item.type | default(omit) }}" - profiles: "{{ item.profiles | default(omit) }}" url: "{{ item.url | default(omit) }}" snap_url: "{{ item.snap_url | default(omit) }}" + target: "{{ item.target | default(omit) }}" cert_file: "{{ item.cert_file | default(omit) }}" key_file: "{{ item.key_file | default(omit) }}" trust_password: "{{ item.trust_password | default(omit) }}" wait_for_ipv4_addresses: "{{ item.wait_for_ipv4_addresses | default(true) }}" - timeout: 600 + timeout: "{{ item.timeout | default(600) }}" loop: "{{ molecule_yml.platforms }}" loop_control: label: "{{ item.name }}" From 39b4be35d8bc8842185f09f8bc1a971df0803350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 12:57:16 +0200 Subject: [PATCH 02/25] Fix destroy playbook for virtual-machines using the type param --- src/molecule_lxd/playbooks/destroy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/molecule_lxd/playbooks/destroy.yml b/src/molecule_lxd/playbooks/destroy.yml index 4e76580..645dbc0 100644 --- a/src/molecule_lxd/playbooks/destroy.yml +++ b/src/molecule_lxd/playbooks/destroy.yml @@ -10,6 +10,7 @@ - name: Destroy molecule instance(s) community.general.lxd_container: name: "{{ item.name }}" + type: "{{ item.type | default(omit) }}" state: absent force_stop: "{{ item.force_stop | default(true) }}" url: "{{ item.url | default(omit) }}" From 046e8d42d25f927eff136311a31fd2bf7a3237ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 12:58:18 +0200 Subject: [PATCH 03/25] Add test scenarios --- .../molecule/basic-packages/molecule.yml | 13 ++++++ .../scenarios/molecule/default/converge.yml | 11 +++++ .../scenarios/molecule/default/molecule.yml | 7 ++++ .../molecule/virtual-machine/molecule.yml | 41 +++++++++++++++++++ src/molecule_lxd/test/test_func.py | 23 +++++++++++ 5 files changed, 95 insertions(+) create mode 100644 src/molecule_lxd/test/scenarios/molecule/basic-packages/molecule.yml create mode 100644 src/molecule_lxd/test/scenarios/molecule/default/converge.yml create mode 100644 src/molecule_lxd/test/scenarios/molecule/default/molecule.yml create mode 100644 src/molecule_lxd/test/scenarios/molecule/virtual-machine/molecule.yml diff --git a/src/molecule_lxd/test/scenarios/molecule/basic-packages/molecule.yml b/src/molecule_lxd/test/scenarios/molecule/basic-packages/molecule.yml new file mode 100644 index 0000000..adad049 --- /dev/null +++ b/src/molecule_lxd/test/scenarios/molecule/basic-packages/molecule.yml @@ -0,0 +1,13 @@ +--- + +driver: + name: lxd + +platforms: + - name: instance + install_basic_packages: true + +provisioner: + name: ansible + playbooks: + converge: ../default/converge.yml diff --git a/src/molecule_lxd/test/scenarios/molecule/default/converge.yml b/src/molecule_lxd/test/scenarios/molecule/default/converge.yml new file mode 100644 index 0000000..9e7e428 --- /dev/null +++ b/src/molecule_lxd/test/scenarios/molecule/default/converge.yml @@ -0,0 +1,11 @@ +--- + +- name: Converge + hosts: all + gather_facts: false + become: true + tasks: + - name: Sample task # noqa command-instead-of-shell + ansible.builtin.shell: + cmd: uname + changed_when: false diff --git a/src/molecule_lxd/test/scenarios/molecule/default/molecule.yml b/src/molecule_lxd/test/scenarios/molecule/default/molecule.yml new file mode 100644 index 0000000..ae230c4 --- /dev/null +++ b/src/molecule_lxd/test/scenarios/molecule/default/molecule.yml @@ -0,0 +1,7 @@ +--- + +driver: + name: lxd + +platforms: + - name: instance diff --git a/src/molecule_lxd/test/scenarios/molecule/virtual-machine/molecule.yml b/src/molecule_lxd/test/scenarios/molecule/virtual-machine/molecule.yml new file mode 100644 index 0000000..43bf7de --- /dev/null +++ b/src/molecule_lxd/test/scenarios/molecule/virtual-machine/molecule.yml @@ -0,0 +1,41 @@ +--- + +driver: + name: lxd + +platforms: + - name: instance + source_alias: focal + groups: + - my_group + type: virtual-machine + config: + "limits.cpu": "2" + "limits.memory": 2GB + "user.user-data": | + #cloud-config + growpart: + mode: auto + devices: + - '/' + - '/dev/sda' + - '/dev/sda2' + ignore_growroot_disabled: false + devices: + config: + source: cloud-init:config + type: disk + eth0: + nictype: bridged + parent: lxdbr0 + type: nic + root: + path: / + pool: default + size: 5GB + type: disk + +provisioner: + name: ansible + playbooks: + converge: ../default/converge.yml diff --git a/src/molecule_lxd/test/test_func.py b/src/molecule_lxd/test/test_func.py index 9d0ad9f..af5b843 100644 --- a/src/molecule_lxd/test/test_func.py +++ b/src/molecule_lxd/test/test_func.py @@ -20,7 +20,10 @@ # DEALINGS IN THE SOFTWARE. """Functional tests""" import pathlib +import pytest +import os +from molecule import util from molecule.util import run_command from molecule.test.conftest import change_dir_to @@ -55,3 +58,23 @@ def test_command_init_scenario(tmp_path: pathlib.Path): cmd = ["molecule", "--debug", "test", "-s", scenario_name] result = run_command(cmd) assert result.returncode == 0 + + +@pytest.mark.parametrize( + "scenario", + [ + ("default"), + ("basic-packages"), + ("virtual-machine") + ], +) +def test_scenario(tmp_path: pathlib.Path, scenario): + + scenario_directory = os.path.join( + os.path.dirname(util.abs_path(__file__)), "scenarios" + ) + + with change_dir_to(scenario_directory): + cmd = ["molecule", "--debug", "test", "-s", scenario] + result = run_command(cmd) + assert result.returncode == 0 From 40d4f907e1756fba9a8c600ba1fd67fdfd934d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 13:20:46 +0200 Subject: [PATCH 04/25] Split test scenarios and skip virtual-machines scenarios if /dev/kvm not found --- src/molecule_lxd/test/test_func.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/molecule_lxd/test/test_func.py b/src/molecule_lxd/test/test_func.py index af5b843..cabd859 100644 --- a/src/molecule_lxd/test/test_func.py +++ b/src/molecule_lxd/test/test_func.py @@ -64,11 +64,30 @@ def test_command_init_scenario(tmp_path: pathlib.Path): "scenario", [ ("default"), - ("basic-packages"), + ("basic-packages") + ], +) +def test_container_scenario(tmp_path: pathlib.Path, scenario): + + scenario_directory = os.path.join( + os.path.dirname(util.abs_path(__file__)), "scenarios" + ) + + with change_dir_to(scenario_directory): + cmd = ["molecule", "--debug", "test", "-s", scenario] + result = run_command(cmd) + assert result.returncode == 0 + + +@pytest.mark.parametrize( + "scenario", + [ ("virtual-machine") ], ) -def test_scenario(tmp_path: pathlib.Path, scenario): +@pytest.mark.skipif(not os.path.exists('/dev/kvm'), + reason="requires KVM") +def test_vm_scenario(tmp_path: pathlib.Path, scenario): scenario_directory = os.path.join( os.path.dirname(util.abs_path(__file__)), "scenarios" From 05fc00efc2de5d355966167abb828a932740641f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 13:26:08 +0200 Subject: [PATCH 05/25] Expect 4 passed tests in github tox workflow --- .github/workflows/tox.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index e453077..35ce4e3 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -30,13 +30,13 @@ jobs: - tox_env: packaging python-version: "3.9" - tox_env: py38 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=4 python-version: "3.8" - tox_env: py39 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=4 python-version: "3.9" - tox_env: py310 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=4 python-version: "3.10" steps: From 678364eb211c531b42b6d9aaaf1bd4d0d892a673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 13:33:19 +0200 Subject: [PATCH 06/25] Remove pypi badge and add github workflow badge in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ac2c51..39b56ec 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Molecule LXD Plugin -[![PyPI Package](https://badge.fury.io/py/molecule-lxd.svg)](https://badge.fury.io/py/molecule-lxd) +[![CI](https://github.com/nextlayer-ansible/molecule-lxd/actions/workflows/tox.yml/badge.svg)](https://github.com/ansible-community/molecule-lxd/actions/workflows/tox.yml) [![Python Black Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) [![Ansible Code of Conduct](https://img.shields.io/badge/Code%20of%20Conduct-Ansible-silver.svg)](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) [![Repository License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -Molecule LXD allows using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual machines as test resources for [molecule](https://ansible.readthedocs.io/projects/molecule/). +Molecule LXD allows using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources for [molecule](https://ansible.readthedocs.io/projects/molecule/). This project is a maintained fork of [ansible-community/molecule-lxd](https://github.com/ansible-community/molecule-lxd), which was archived on January 8, 2023. From 89d8381f2a1ce81058902ef5ef59a26463e67ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 16 Jun 2023 23:40:37 +0200 Subject: [PATCH 07/25] Add .idea directory to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 86d0c1b..86520a9 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,6 @@ venv.bak/ # mypy .mypy_cache/ pip-wheel-metadata + +# JetBrains +.idea/ From c486ebe812d15a499383bb851f2476c7d552be5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 10:52:09 +0200 Subject: [PATCH 08/25] Lower timeout for tox github workflow --- .github/workflows/tox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 35ce4e3..4cb2dc4 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -20,7 +20,7 @@ jobs: tests: name: ${{ matrix.tox_env }} runs-on: ubuntu-22.04 - timeout-minutes: 60 + timeout-minutes: 15 strategy: fail-fast: false matrix: From bb7acade83074c1644b519fc8827bfec685d0888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 10:57:49 +0200 Subject: [PATCH 09/25] Add quickstart section to docs --- docs/quickstart.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docs/quickstart.md diff --git a/docs/quickstart.md b/docs/quickstart.md new file mode 100644 index 0000000..8b44ecf --- /dev/null +++ b/docs/quickstart.md @@ -0,0 +1,52 @@ +# Quickstart + +This tutorial requires a working local LXD environment. Learn how to set up one in the [requirements section](requirements.md) of the docs. + +## Installation + +Install the *molecule LXD* plugin: +```sh +pip install git+https://github.com/nextlayer-ansible/molecule-lxd.git@main#egg=molecule-lxd +``` + +## Create a scenario + +### With a new role + +Create a new role `my-role` with a molecule default scenario using the `lxd` driver: +```sh +molecule init role -d lxd my-role +``` + +### In a pre-existing role + +Create a molecule default scenario using the `lxd` driver: +```sh +molecule init scenario -d lxd +``` + +### Example scenario definition + +Here's a simple `molecule.yml` example scenario definition, if you want to add it by hand: +```yml +driver: + name: lxd +platforms: + - name: instance + source_alias: ubuntu/jammy/amd64 +provisioner: + name: ansible +verifier: + name: ansible +``` + +## Run tests + +After configuration, you can run molecule: +```sh +molecule test +``` + +## Further reading + +More examples can be found in the [example section](examples.md). From bea9073329c377eae501a707d9b3bee9baa002c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 10:59:23 +0200 Subject: [PATCH 10/25] Add requirements section to docs --- docs/requirements.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/requirements.md diff --git a/docs/requirements.md b/docs/requirements.md new file mode 100644 index 0000000..e1e2452 --- /dev/null +++ b/docs/requirements.md @@ -0,0 +1,22 @@ +# Requirements + +## LXD Environment + +*Molecule LXD* requires a working [LXD environment](https://linuxcontainers.org/lxd/docs/latest/), either local or remote. + +Instructions on installing LXD can be found in the [LXD documentation](https://linuxcontainers.org/lxd/docs/latest/installing/) and on the [LXD website](https://linuxcontainers.org/lxd/getting-started-cli/). + +### Example setup on Ubuntu + +Install LXD via snaps: +```sh +snap install lxd +``` + +Initialize LXD: +```sh +lxd init --minimal +``` +Other initialization options are described in the [LXD documentation](https://linuxcontainers.org/lxd/docs/latest/howto/initialize/). + + From d2595064a1cad44a65dbeb9e375e263109bda4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:03:27 +0200 Subject: [PATCH 11/25] Move DEVELOPMENT.md to docs/development.md --- DEVELOPMENT.md | 27 ---------------------- docs/development.md | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 27 deletions(-) delete mode 100644 DEVELOPMENT.md create mode 100644 docs/development.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md deleted file mode 100644 index 9c61dbe..0000000 --- a/DEVELOPMENT.md +++ /dev/null @@ -1,27 +0,0 @@ -# Development - -## Requirements - -```sh -sudo apt install make python3-venv -``` - -## Makefile - -Use the Makefile targets to run tests or build the package: - -```sh -make help - -Usage: - make help show this message - make clean remove intermediate files - - make lint run all linters - - make test-py38 run tests with python 3.8 - make test-py39 run tests with python 3.9 - make test-py310 run tests with python 3.10 - - make build build the package -``` diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..93dc581 --- /dev/null +++ b/docs/development.md @@ -0,0 +1,56 @@ +# Development + +## Requirements + +```sh +sudo apt install make python3-venv +``` + +## Testing + +*Molecule LXD* has a few codestyle, unit and functional tests. It uses [Tox](https://tox.readthedocs.io/en/latest/) +factors to generate a matrix of python x unit/functional tests. +Please note, that you have to set up python on your own. + +### Run all tests + +```sh +make test +``` + +### Run linter + +```sh +make lint +``` + +### Run tests for a specific python version + +```sh +make test-py39 +``` + +## Makefile + +Use the Makefile target `help` to get all options: + +```sh +make help +``` + +Output: + +```text +Usage: + make help show this message + make clean remove intermediate files + + make lint run all linters + + make test run all tests. Allows passing arguments to tox. + make test-py38 run tests with python 3.8 + make test-py39 run tests with python 3.9 + make test-py310 run tests with python 3.10 + + make build build the package +``` From f07fe8c5cb6bd8ef056d2f82d2058e88a23aa646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:35:04 +0200 Subject: [PATCH 12/25] Rename make target tox to test --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1c1a80d..7ff7f25 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ help: @echo @echo " make lint run all linters" @echo + @echo " make test run all tests. Allows passing arguments to tox." @echo " make test-py38 run tests with python 3.8" @echo " make test-py39 run tests with python 3.9" @echo " make test-py310 run tests with python 3.10" @@ -24,15 +25,15 @@ $(RUN_VENV_BIN)/activate: setup.cfg tox.ini pyproject.toml . $(RUN_VENV_BIN)/activate && python3 --version # Allow to pass-through arguments to ansible-playbook -ifeq (tox,$(firstword $(MAKECMDGOALS))) +ifeq (test,$(firstword $(MAKECMDGOALS))) # use the rest as arguments for "good" RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) # ...and turn them into do-nothing targets $(eval $(RUN_ARGS):;@:) endif -.PHONY: tox -tox: $(RUN_VENV_BIN)/activate +.PHONY: test +test: $(RUN_VENV_BIN)/activate . $(RUN_VENV_BIN)/activate && tox $(RUN_ARGS) .PHONY: lint From 8cc8acaae6ec37c99e5e74a4f5e03ed32b561f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:40:02 +0200 Subject: [PATCH 13/25] Add platform options section to docs --- docs/platform-options.md | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/platform-options.md diff --git a/docs/platform-options.md b/docs/platform-options.md new file mode 100644 index 0000000..0ea616b --- /dev/null +++ b/docs/platform-options.md @@ -0,0 +1,86 @@ +# Platform Options + +*Molecule LXD* allows a wide degree of customisation via platform arguments. Most of them are passed to the +underlying [Ansible LXD container module](https://docs.ansible.com/ansible/latest/collections/community/general/lxd_container_module.html) +without changes. Because this module uses the LXD API, you can look at +the [LXD OpenAPI documentation](https://linuxcontainers.org/lxd/api/master/#/instances/instances_post) to get the latest +options. + +| Variable | Default | Description | +|-------------------------|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| +| name | | Instance name, used for the internal Ansible inventory and as LXD instance name. | +| groups | `[]` | Inventory groups, the instance should be a member of. | +| type | `container` | Instance type. Choice of: `container`, `virtual-machine` | +| architecture | `x86_64` | Instance architecture. Choice of: `x86_64`, `i686` | +| source_type | `image` | Source type. | +| source_mode | `pull` | Source mode: Whether to use `pull` or `push` mode. | +| source_server | `https://images.linuxcontainers.org` (if type=container)
`https://cloud-images.ubuntu.com/releases` (if type=virtual-machine) | Source remote server URL (to get remote images). | +| source_alias | `ubuntu/jammy/amd64` | Source image alias name. | +| source_protocol | `simplestreams` | Source protocol name (for remote image). | +| source | `{}` | The source for the instance. See [source section](#source). | +| profiles | `[]` | Profiles to be used by the instance. | +| config | `{}` | The config for the instance. See [config section](#config). | +| devices | `{}` | The devices for the instance. See [devices section](#devices). | +| ignore_volatile_options | `false` | If `true`, config options starting with `volatile.` are ignored | +| url | `unix:/var/lib/lxd/unix.socket` | The unix domain socket path or the https URL for the LXD server. | +| snap_url | `unix:/var/snap/lxd/common/lxd/unix.socket` | The unix domain socket path when LXD is installed by snap package manager. | +| target | | For cluster deployments. Will attempt to create an instance on a target node. | +| project | | Project of an instance. | +| cert_file | `${HOME}/.config/lxc/client.crt` | The client certificate file path. | +| key_file | `${HOME}/.config/lxc/client.key` | The client certificate key file path. | +| trust_password | | The client trusted password. | +| wait_for_ipv4_addresses | `true` | If `true`, the create playbook waits until IPv4 addresses are set to all network interfaces. | +| timeout | `600` | Timeout for creating or destroying the instance. | +| force_stop | `true` | If `true`, the instance will be forced to stop. | +| install_basic_packages | `false` | If `true`, some basic packages will be installed in the prepare phase. | + +## Source + +A dict with options to define the source for the instance. +This dict is defaulted to the options starting with `source_`. + +Example: + +```yaml +platforms: + - name: my-instance + source: + alias: ubuntu/bionic/amd64 +``` + +The above example is equal to the following example: + +```yaml +platforms: + - name: my-instance + source_alias: ubuntu/bionic/amd64 +``` + +## Config + +The config for the instance. + +Example: + +```yaml +platforms: + - name: my-instance + config: + "limits.cpu": 2 + "security.nesting": true +``` + +## Devices + +The devices for the instance. + +Example: + +```yaml +platforms: + - name: my-instance + devices: + kvm: + path: /dev/kvm + type: unix-char +``` From 06ee04706d742e50b8be7144f7c692da72c97dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:40:31 +0200 Subject: [PATCH 14/25] Add initial CHANGELOG.md --- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..882ce8c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,33 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +--- + +## [v0.4.0a0] - 2022-02-18 + +### Changed +- Update driver to match latest requirements (#25) @bonddim +- Update ansible connection options (#26) @bonddim + +### Fixed +- Fix functional tests after pytest-helpers-namespace drop (#17) @bonddim + +## [0.3] - 2021-06-22 + +### Changed +- Added retries to create and destroy playbooks (#14) @bonddim +- Switch from freenode to libera.chat (#15) @bonddim + +## [0.2] - 2021-03-02 + +### Changed +- Updated plugin to use newer molecule APIs (#7) @bonddim + +## [0.1] - 2020-10-29 + +### Changed +- Made driver compatible with molecule 3.2 (#6) @ssbarnea + From 0bb86318e0572475e392b7f886cdfcc48007efbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:56:23 +0200 Subject: [PATCH 15/25] Add examples to docs --- docs/examples.md | 74 ++++++++++++++++++++++++++++++++++++++++ docs/platform-options.md | 4 +-- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 docs/examples.md diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..c232df4 --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,74 @@ +# Examples + +## Minimal + +```yaml +driver: + name: lxd + +platforms: + - name: instance + source_alias: ubuntu/jammy/amd64 +``` + +## Container + +```yaml +driver: + name: lxd + +platforms: + - name: instance + groups: + - my_group + source: + alias: ubuntu/jammy/amd64 + type: image + mode: pull + server: https://images.linuxcontainers.org + protocol: simplestreams + config: + security.nesting: "true" + security.syscalls.intercept.mknod: "true" + security.syscalls.intercept.setxattr: "true" +``` + +## Virtual-Machine + +```yaml +driver: + name: lxd + +platforms: + - name: instance + groups: + - my_group + source_alias: focal + type: virtual-machine + config: + limits.cpu: "2" + limits.memory: 2GB + user.user-data: | + #cloud-config + growpart: + mode: auto + devices: + - '/' + - '/dev/sda' + - '/dev/sda2' + ignore_growroot_disabled: false + devices: + config: + source: cloud-init:config + type: disk + eth0: + nictype: bridged + parent: lxdbr0 + type: nic + root: + path: / + pool: default + size: 5GB + type: disk +``` + diff --git a/docs/platform-options.md b/docs/platform-options.md index 0ea616b..8536e97 100644 --- a/docs/platform-options.md +++ b/docs/platform-options.md @@ -66,8 +66,8 @@ Example: platforms: - name: my-instance config: - "limits.cpu": 2 - "security.nesting": true + "limits.cpu": "2" + "security.nesting": "true" ``` ## Devices From f95533f0816581396c1e297ba2f6514b4d2524e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:56:39 +0200 Subject: [PATCH 16/25] Add docs introduction --- docs/index.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/index.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..9181f53 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,22 @@ +# Molecule LXD + +*Molecule LXD* is a driver plugin for the Ansible test +runner [molecule](https://ansible.readthedocs.io/projects/molecule/) and allows +using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources. The plugin +supports local and remote LXD environments, and configures molecule to connect to the test resources using +the [LXD connection plugin](https://docs.ansible.com/ansible/latest/collections/community/general/lxd_connection.html). + +## Topics + +- [Quickstart](quickstart.md) +- [Requirements](requirements.md) +- [Platform Options](platform-options.md) +- [Examples](examples.md) +- [Development](development.md) +- [Changelog](../CHANGELOG.md) + +## Further reading + +- [Molecule Documentation](https://molecule.readthedocs.io/) +- [LXD Getting-Started-Guide](https://linuxcontainers.org/lxd/getting-started-cli/) +- [LXD Documentation](https://linuxcontainers.org/lxd/docs/latest/) From bf05801d892fdb792f1f871d76240fee644b14ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 14:57:10 +0200 Subject: [PATCH 17/25] Cleanup --- src/molecule_lxd/driver.py | 6 +++--- src/molecule_lxd/test/test_func.py | 14 +++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/molecule_lxd/driver.py b/src/molecule_lxd/driver.py index 13c3aae..b2e6926 100644 --- a/src/molecule_lxd/driver.py +++ b/src/molecule_lxd/driver.py @@ -55,7 +55,7 @@ class LXD(Driver): mode: pull server: https://images.linuxcontainers.org protocol: lxd|simplestreams - alias: ubuntu/xenial/amd64 + alias: ubuntu/jammy/amd64 architecture: x86_64|i686 config: limits.cpu: 2 @@ -118,11 +118,11 @@ def ansible_connection_options(self, instance_name): } def sanity_checks(self): - # FIXME(decentral1se): Implement sanity checks + # FIXME(decentralize): Implement sanity checks pass def template_dir(self): - """Return path to its own cookiecutterm templates. It is used by init + """Return path to its own cookiecutter templates. It is used by init command in order to figure out where to load the templates from. """ return os.path.join(os.path.dirname(__file__), "cookiecutter") diff --git a/src/molecule_lxd/test/test_func.py b/src/molecule_lxd/test/test_func.py index cabd859..7dd8130 100644 --- a/src/molecule_lxd/test/test_func.py +++ b/src/molecule_lxd/test/test_func.py @@ -62,13 +62,9 @@ def test_command_init_scenario(tmp_path: pathlib.Path): @pytest.mark.parametrize( "scenario", - [ - ("default"), - ("basic-packages") - ], + ["default", "basic-packages"], ) def test_container_scenario(tmp_path: pathlib.Path, scenario): - scenario_directory = os.path.join( os.path.dirname(util.abs_path(__file__)), "scenarios" ) @@ -81,14 +77,10 @@ def test_container_scenario(tmp_path: pathlib.Path, scenario): @pytest.mark.parametrize( "scenario", - [ - ("virtual-machine") - ], + ["virtual-machine"], ) -@pytest.mark.skipif(not os.path.exists('/dev/kvm'), - reason="requires KVM") +@pytest.mark.skipif(not os.path.exists("/dev/kvm"), reason="requires KVM") def test_vm_scenario(tmp_path: pathlib.Path, scenario): - scenario_directory = os.path.join( os.path.dirname(util.abs_path(__file__)), "scenarios" ) From 7daa427089e9fc5f850498c66d86ecd8452db0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 15:10:10 +0200 Subject: [PATCH 18/25] Add links to README and cleanup docs --- README.md | 20 +++++++++++++++++--- docs/index.md | 9 +++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 39b56ec..4ce1719 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,32 @@ # Molecule LXD Plugin -[![CI](https://github.com/nextlayer-ansible/molecule-lxd/actions/workflows/tox.yml/badge.svg)](https://github.com/ansible-community/molecule-lxd/actions/workflows/tox.yml) +[![CI](https://github.com/nextlayer-ansible/molecule-lxd/actions/workflows/tox.yml/badge.svg)](https://github.com/nextlayer-ansible/molecule-lxd/actions/workflows/tox.yml) [![Python Black Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) [![Ansible Code of Conduct](https://img.shields.io/badge/Code%20of%20Conduct-Ansible-silver.svg)](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) [![Repository License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -Molecule LXD allows using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources for [molecule](https://ansible.readthedocs.io/projects/molecule/). +*Molecule LXD* allows using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources for [molecule](https://ansible.readthedocs.io/projects/molecule/). This project is a maintained fork of [ansible-community/molecule-lxd](https://github.com/ansible-community/molecule-lxd), which was archived on January 8, 2023. +## Features + +- Use Linux-Containers and Virtual-Machines as test resources for molecule. +- Configures molecule to connect to the test resources. +- Supports local and remote LXD environments. + +## Documentation + +A [Quickstart-Tutorial](docs/quickstart.md), [examples](docs/examples.md) and more can be found in the [documentation](docs/index.md). + +## Changelog + +Notable changes to this project are documented in the [CHANGELOG](CHANGELOG.md). + ## License The [MIT](https://github.com/ansible/molecule/blob/master/LICENSE) License. -The logo is licensed under the [Creative Commons NoDerivatives 4.0 License](https://creativecommons.org/licenses/by-nd/4.0/). +The Molecule logo is licensed under the [Creative Commons NoDerivatives 4.0 License](https://creativecommons.org/licenses/by-nd/4.0/). If you have some other use in mind, contact us. diff --git a/docs/index.md b/docs/index.md index 9181f53..affb081 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,10 +1,11 @@ # Molecule LXD -*Molecule LXD* is a driver plugin for the Ansible test +*Molecule LXD* is a driver plugin for the [Ansible](https://docs.ansible.com/ansible/latest/index.html) test runner [molecule](https://ansible.readthedocs.io/projects/molecule/) and allows -using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources. The plugin -supports local and remote LXD environments, and configures molecule to connect to the test resources using -the [LXD connection plugin](https://docs.ansible.com/ansible/latest/collections/community/general/lxd_connection.html). +using [LXD](https://linuxcontainers.org/lxd/) to provision containers or virtual-machines as test resources by using +the [Ansible LXD container module](https://docs.ansible.com/ansible/latest/collections/community/general/lxd_container_module.html). +The plugin supports local and remote LXD environments, and configures molecule to connect to the test resources using +the [Ansible LXD connection plugin](https://docs.ansible.com/ansible/latest/collections/community/general/lxd_connection.html). ## Topics From 88bde6d3fbc8c09fdc49770edae3511c9821e5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 15:14:07 +0200 Subject: [PATCH 19/25] Fix platform-options --- docs/platform-options.md | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/platform-options.md b/docs/platform-options.md index 8536e97..97a7287 100644 --- a/docs/platform-options.md +++ b/docs/platform-options.md @@ -6,33 +6,33 @@ without changes. Because this module uses the LXD API, you can look at the [LXD OpenAPI documentation](https://linuxcontainers.org/lxd/api/master/#/instances/instances_post) to get the latest options. -| Variable | Default | Description | -|-------------------------|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| -| name | | Instance name, used for the internal Ansible inventory and as LXD instance name. | -| groups | `[]` | Inventory groups, the instance should be a member of. | -| type | `container` | Instance type. Choice of: `container`, `virtual-machine` | -| architecture | `x86_64` | Instance architecture. Choice of: `x86_64`, `i686` | -| source_type | `image` | Source type. | -| source_mode | `pull` | Source mode: Whether to use `pull` or `push` mode. | -| source_server | `https://images.linuxcontainers.org` (if type=container)
`https://cloud-images.ubuntu.com/releases` (if type=virtual-machine) | Source remote server URL (to get remote images). | -| source_alias | `ubuntu/jammy/amd64` | Source image alias name. | -| source_protocol | `simplestreams` | Source protocol name (for remote image). | -| source | `{}` | The source for the instance. See [source section](#source). | -| profiles | `[]` | Profiles to be used by the instance. | -| config | `{}` | The config for the instance. See [config section](#config). | -| devices | `{}` | The devices for the instance. See [devices section](#devices). | -| ignore_volatile_options | `false` | If `true`, config options starting with `volatile.` are ignored | -| url | `unix:/var/lib/lxd/unix.socket` | The unix domain socket path or the https URL for the LXD server. | -| snap_url | `unix:/var/snap/lxd/common/lxd/unix.socket` | The unix domain socket path when LXD is installed by snap package manager. | -| target | | For cluster deployments. Will attempt to create an instance on a target node. | -| project | | Project of an instance. | -| cert_file | `${HOME}/.config/lxc/client.crt` | The client certificate file path. | -| key_file | `${HOME}/.config/lxc/client.key` | The client certificate key file path. | -| trust_password | | The client trusted password. | -| wait_for_ipv4_addresses | `true` | If `true`, the create playbook waits until IPv4 addresses are set to all network interfaces. | -| timeout | `600` | Timeout for creating or destroying the instance. | -| force_stop | `true` | If `true`, the instance will be forced to stop. | -| install_basic_packages | `false` | If `true`, some basic packages will be installed in the prepare phase. | +| Variable | Default | Description | +|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| +| name | | Instance name, used for the internal Ansible inventory and as LXD instance name. | +| groups | `[]` | Inventory groups, the instance should be a member of. | +| type | `container` | Instance type. Choice of: `container`, `virtual-machine` | +| architecture | `x86_64` | Instance architecture. Choice of: `x86_64`, `i686` | +| source_type | `image` | Source type. | +| source_mode | `pull` | Source mode: Whether to use `pull` or `push` mode. | +| source_server | if type=container:
`https://images.linuxcontainers.org`

if type=virtual-machine:
`https://cloud-images.ubuntu.com/releases` | Source remote server URL (to get remote images). | +| source_alias | `ubuntu/jammy/amd64` | Source image alias name. | +| source_protocol | `simplestreams` | Source protocol name (for remote image). | +| source | `{}` | The source for the instance. See [source section](#source). | +| profiles | `[]` | Profiles to be used by the instance. | +| config | `{}` | The config for the instance. See [config section](#config). | +| devices | `{}` | The devices for the instance. See [devices section](#devices). | +| ignore_volatile_options | `false` | If `true`, config options starting with `volatile.` are ignored | +| url | `unix:/var/lib/lxd/unix.socket` | The unix domain socket path or the https URL for the LXD server. | +| snap_url | `unix:/var/snap/lxd/common/lxd/unix.socket` | The unix domain socket path when LXD is installed by snap package manager. | +| target | | For cluster deployments. Will attempt to create an instance on a target node. | +| project | | Project of an instance. | +| cert_file | `${HOME}/.config/lxc/client.crt` | The client certificate file path. | +| key_file | `${HOME}/.config/lxc/client.key` | The client certificate key file path. | +| trust_password | | The client trusted password. | +| wait_for_ipv4_addresses | `true` | If `true`, the create playbook waits until IPv4 addresses are set to all network interfaces. | +| timeout | `600` | Timeout for creating or destroying the instance. | +| force_stop | `true` | If `true`, the instance will be forced to stop. | +| install_basic_packages | `false` | If `true`, some basic packages will be installed in the prepare phase. | ## Source From 63b5f975be73d0c659a6248aaa707b33d35fa4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 15:18:43 +0200 Subject: [PATCH 20/25] Fix formatting --- docs/examples.md | 28 ++++++++++++++-------------- docs/platform-options.md | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index c232df4..4b4f057 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -20,13 +20,13 @@ driver: platforms: - name: instance groups: - - my_group + - my_group source: - alias: ubuntu/jammy/amd64 - type: image - mode: pull - server: https://images.linuxcontainers.org - protocol: simplestreams + alias: ubuntu/jammy/amd64 + type: image + mode: pull + server: https://images.linuxcontainers.org + protocol: simplestreams config: security.nesting: "true" security.syscalls.intercept.mknod: "true" @@ -49,14 +49,14 @@ platforms: limits.cpu: "2" limits.memory: 2GB user.user-data: | - #cloud-config - growpart: - mode: auto - devices: - - '/' - - '/dev/sda' - - '/dev/sda2' - ignore_growroot_disabled: false + #cloud-config + growpart: + mode: auto + devices: + - '/' + - '/dev/sda' + - '/dev/sda2' + ignore_growroot_disabled: false devices: config: source: cloud-init:config diff --git a/docs/platform-options.md b/docs/platform-options.md index 97a7287..3aa384c 100644 --- a/docs/platform-options.md +++ b/docs/platform-options.md @@ -43,17 +43,17 @@ Example: ```yaml platforms: - - name: my-instance - source: - alias: ubuntu/bionic/amd64 + - name: my-instance + source: + alias: ubuntu/bionic/amd64 ``` The above example is equal to the following example: ```yaml platforms: - - name: my-instance - source_alias: ubuntu/bionic/amd64 + - name: my-instance + source_alias: ubuntu/bionic/amd64 ``` ## Config @@ -64,10 +64,10 @@ Example: ```yaml platforms: - - name: my-instance - config: - "limits.cpu": "2" - "security.nesting": "true" + - name: my-instance + config: + "limits.cpu": "2" + "security.nesting": "true" ``` ## Devices @@ -78,9 +78,9 @@ Example: ```yaml platforms: - - name: my-instance - devices: - kvm: - path: /dev/kvm - type: unix-char + - name: my-instance + devices: + kvm: + path: /dev/kvm + type: unix-char ``` From 31a16250091ee147815b96054500d9916cf642a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 15:35:32 +0200 Subject: [PATCH 21/25] Add changelog entry for 0.5.0 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 882ce8c..559c13d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [0.5.0] - 2023-06-17 + +### Added + +- Add test scenarios +- Add documentation and examples + +### Changed +- Use canonical/setup-lxd Github action to set up LXD + +### Fixed +- Hardcoded "security.nesting" key from config in create.yml should be removed (#1) +- Fix destroy playbook for virtual-machines + ## [v0.4.0a0] - 2022-02-18 ### Changed From 9b3714cad73863e3eda74efd91b24449fa7ec15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 15:35:55 +0200 Subject: [PATCH 22/25] Add timeout option to destroy task --- src/molecule_lxd/playbooks/destroy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/molecule_lxd/playbooks/destroy.yml b/src/molecule_lxd/playbooks/destroy.yml index 645dbc0..1db1e10 100644 --- a/src/molecule_lxd/playbooks/destroy.yml +++ b/src/molecule_lxd/playbooks/destroy.yml @@ -19,6 +19,7 @@ key_file: "{{ item.key_file | default(omit) }}" trust_password: "{{ item.trust_password | default(omit) }}" ignore_volatile_options: "{{ item.ignore_volatile_options | default(false) }}" + timeout: "{{ item.timeout | default(600) }}" loop: "{{ molecule_yml.platforms }}" loop_control: label: "{{ item.name }}" From c04b95542f67bed7010f7b518a8568abe72dc683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 16:04:11 +0200 Subject: [PATCH 23/25] Allow using alias and deprecate this option --- docs/platform-options.md | 3 ++- src/molecule_lxd/playbooks/create.yml | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/platform-options.md b/docs/platform-options.md index 3aa384c..0e963ad 100644 --- a/docs/platform-options.md +++ b/docs/platform-options.md @@ -12,10 +12,11 @@ options. | groups | `[]` | Inventory groups, the instance should be a member of. | | type | `container` | Instance type. Choice of: `container`, `virtual-machine` | | architecture | `x86_64` | Instance architecture. Choice of: `x86_64`, `i686` | +| ~~alias~~ | `ubuntu/jammy/amd64` | Source image alias name. (Deprecated) | +| source_alias | `ubuntu/jammy/amd64` | Source image alias name. | | source_type | `image` | Source type. | | source_mode | `pull` | Source mode: Whether to use `pull` or `push` mode. | | source_server | if type=container:
`https://images.linuxcontainers.org`

if type=virtual-machine:
`https://cloud-images.ubuntu.com/releases` | Source remote server URL (to get remote images). | -| source_alias | `ubuntu/jammy/amd64` | Source image alias name. | | source_protocol | `simplestreams` | Source protocol name (for remote image). | | source | `{}` | The source for the instance. See [source section](#source). | | profiles | `[]` | Profiles to be used by the instance. | diff --git a/src/molecule_lxd/playbooks/create.yml b/src/molecule_lxd/playbooks/create.yml index 50d4ebd..67da4c8 100644 --- a/src/molecule_lxd/playbooks/create.yml +++ b/src/molecule_lxd/playbooks/create.yml @@ -15,6 +15,14 @@ protocol: simplestreams tasks: + - name: Print warning for using deprecated var 'alias' + debug: + msg: "Using 'alias' for instance {{ item.name }} is deprecated. Use 'source_alias' instead." + when: item.alias | defined + loop: "{{ molecule_yml.platforms }}" + loop_control: + label: "{{ item.name }}" + - name: Create molecule instance(s) community.general.lxd_container: name: "{{ item.name }}" @@ -27,7 +35,7 @@ 'type': item.source_type | default(default_source.type), 'mode': item.source_mode | default(default_source.mode), 'server': item.source_server | default('https://cloud-images.ubuntu.com/releases' if item.type | default('container') == 'virtual-machine' else default_source.server), - 'alias': item.source_alias | default(default_source.alias), + 'alias': item.alias | default(item.source_alias | default(default_source.alias)), 'protocol': item.source_protocol | default(default_source.protocol) } | combine(item.source | default({})) }} From bff8bfbeabf04636084839e685280fc7c74eda8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 17:48:46 +0200 Subject: [PATCH 24/25] Cleanup docstrings in driver.py --- src/molecule_lxd/driver.py | 64 ++------------------------------------ 1 file changed, 2 insertions(+), 62 deletions(-) diff --git a/src/molecule_lxd/driver.py b/src/molecule_lxd/driver.py index b2e6926..d46a18c 100644 --- a/src/molecule_lxd/driver.py +++ b/src/molecule_lxd/driver.py @@ -22,67 +22,11 @@ from molecule import logger from molecule.api import Driver - LOG = logger.get_logger(__name__) class LXD(Driver): - """ - The class responsible for managing `LXD`_ containers. `LXD`_ is `not` the - default driver used in Molecule. - - Molecule leverages Ansible's `lxd_container`_ module, by mapping variables - from ``molecule.yml`` into ``create.yml`` and ``destroy.yml``. - The `lxd_container`_ module leverages the LXD API. Useful information - about, for example the source variable can be found in the `LXD API documentation`. - - .. _`lxd_container`: https://docs.ansible.com/ansible/latest/lxd_container_module.html - .. _`LXD API documentation`: https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1 - - .. code-block:: yaml - - driver: - name: lxd - platforms: - - name: instance - url: https://127.0.0.1:8443 - snap_url: unix:/var/snap/lxd/common/lxd/unix.socket - cert_file: /root/.config/lxc/client.crt - key_file: /root/.config/lxc/client.key - trust_password: password - source: - type: image - mode: pull - server: https://images.linuxcontainers.org - protocol: lxd|simplestreams - alias: ubuntu/jammy/amd64 - architecture: x86_64|i686 - config: - limits.cpu: 2 - devices: - kvm: - path: /dev/kvm - type: unix-char - profiles: - - default - force_stop: true - ignore_volatile_options: false - target: node_name - type: virtual-machine - install_basic_packages: false - - Provide a list of files Molecule will preserve, relative to the scenario - ephemeral directory, after any ``destroy`` subcommand execution. - - .. code-block:: yaml - - driver: - name: lxd - safe_files: - - foo - - .. _`LXD`: https://linuxcontainers.org/lxd/introduction/ - """ # noqa + """LXD molecule driver plugin.""" def __init__(self, config=None): super(LXD, self).__init__(config) @@ -118,13 +62,10 @@ def ansible_connection_options(self, instance_name): } def sanity_checks(self): - # FIXME(decentralize): Implement sanity checks + # TODO: Implement sanity checks pass def template_dir(self): - """Return path to its own cookiecutter templates. It is used by init - command in order to figure out where to load the templates from. - """ return os.path.join(os.path.dirname(__file__), "cookiecutter") def modules_dir(self): @@ -132,5 +73,4 @@ def modules_dir(self): @property def required_collections(self) -> Dict[str, str]: - """Return collections dict containing names and versions required.""" return {"community.general": "4.1.0"} From 8f670306d2fb685fca4fee61533b81f9f1e9b62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sat, 17 Jun 2023 17:49:01 +0200 Subject: [PATCH 25/25] Fix create playbook --- src/molecule_lxd/playbooks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/molecule_lxd/playbooks/create.yml b/src/molecule_lxd/playbooks/create.yml index 67da4c8..a8f5359 100644 --- a/src/molecule_lxd/playbooks/create.yml +++ b/src/molecule_lxd/playbooks/create.yml @@ -18,7 +18,7 @@ - name: Print warning for using deprecated var 'alias' debug: msg: "Using 'alias' for instance {{ item.name }} is deprecated. Use 'source_alias' instead." - when: item.alias | defined + when: item.alias is defined loop: "{{ molecule_yml.platforms }}" loop_control: label: "{{ item.name }}"