diff --git a/molecule_lxd/playbooks/create.yml b/molecule_lxd/playbooks/create.yml new file mode 100644 index 0000000..1ecf609 --- /dev/null +++ b/molecule_lxd/playbooks/create.yml @@ -0,0 +1,37 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ molecule_no_log }}" + + vars: + default_source: + type: image + mode: pull + server: https://images.linuxcontainers.org + alias: ubuntu/bionic + protocol: simplestreams + default_config: + "security.nesting": "true" + + tasks: + - name: Create molecule instance(s) + lxd_container: + name: "{{ item.name }}" + state: started + source: "{{ default_source | combine(item.source | default({})) }}" + config: "{{ default_config | combine(item.config | default({})) }}" + architecture: "{{ item.architecture | default(omit) }}" + devices: "{{ item.devices | default(omit) }}" + profiles: "{{ item.profiles | default(omit) }}" + url: "{{ item.url | 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: true + timeout: 600 + loop: "{{ molecule_yml.platforms }}" + loop_control: + label: "{{ item.name }}" + no_log: false diff --git a/molecule_lxd/playbooks/destroy.yml b/molecule_lxd/playbooks/destroy.yml new file mode 100644 index 0000000..1a4ef6b --- /dev/null +++ b/molecule_lxd/playbooks/destroy.yml @@ -0,0 +1,21 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ molecule_no_log }}" + + tasks: + - name: Destroy molecule instance(s) + lxd_container: + name: "{{ item.name }}" + state: absent + force_stop: "{{ item.force_stop | default(true) }}" + url: "{{ item.url | default(omit) }}" + cert_file: "{{ item.cert_file | default(omit) }}" + key_file: "{{ item.key_file | default(omit) }}" + trust_password: "{{ item.trust_password | default(omit) }}" + loop: "{{ molecule_yml.platforms }}" + loop_control: + label: "{{ item.name }}" + no_log: false diff --git a/molecule_lxd/playbooks/prepare.yml b/molecule_lxd/playbooks/prepare.yml new file mode 100644 index 0000000..12fe738 --- /dev/null +++ b/molecule_lxd/playbooks/prepare.yml @@ -0,0 +1,25 @@ +--- +- name: Prepare + hosts: all + gather_facts: false + no_log: "{{ molecule_no_log }}" + + tasks: + - name: Install basic packages to bare containers + tags: skip_ansible_lint + raw: | + if [ -x "$(command -v apt-get)" ]; then + export DEBIAN_FRONTEND=noninteractive + apt-get update --quiet && apt-get install --assume-yes --no-install-recommends ca-certificates curl python3 python3-apt + elif [ -x "$(command -v dnf)" ]; then + dnf --assumeyes install ca-certificates curl python3 python3-dnf + elif [ -x "$(command -v yum)" ]; then + yum install --assumeyes ca-certificates curl python + elif [ -x "$(command -v zypper)" ]; then + zypper --non-interactive --gpg-auto-import-keys refresh + zypper --non-interactive install ca-certificates ca-certificates-cacert ca-certificates-mozilla curl python3 + elif [ -x "$(command -v apk)" ]; then + apk update && apk add ca-certificates curl python3 + elif [ -x "$(command -v pacman)" ]; then + pacman -Syu --noconfirm ca-certificates curl python3 + fi diff --git a/molecule_lxd/test/functional/test_func.py b/molecule_lxd/test/functional/test_func.py index 9c66888..2592e58 100644 --- a/molecule_lxd/test/functional/test_func.py +++ b/molecule_lxd/test/functional/test_func.py @@ -21,36 +21,38 @@ import pytest import os -import sh -from molecule import logger -from molecule.test.conftest import run_command, change_dir_to +from molecule import logger, util +from molecule.util import run_command +from molecule.test.conftest import change_dir_to from molecule.test.functional.conftest import metadata_lint_update -# import change_dir_to, temp_dir - LOG = logger.get_logger(__name__) @pytest.mark.xfail(reason="need to fix template path") def test_command_init_scenario(temp_dir): role_directory = os.path.join(temp_dir.strpath, "test-init") - options = {} - cmd = sh.molecule.bake("init", "role", "test-init", **options) - run_command(cmd) + cmd = ["molecule", "init", "role", "test-init"] + result = run_command(cmd) + assert result.returncode == 0 metadata_lint_update(role_directory) with change_dir_to(role_directory): molecule_directory = pytest.helpers.molecule_directory() scenario_directory = os.path.join(molecule_directory, "test-scenario") - options = { - "role_name": "test-init", - "driver-name": "lxd", - } - cmd = sh.molecule.bake("init", "scenario", "test-scenario", **options) - run_command(cmd) - + options = {"role_name": "test-init", "driver-name": "lxd"} + cmd = [ + "molecule", + "init", + "scenario", + "test-scenario", + *util.dict2args(options), + ] + result = run_command(cmd) + assert result.returncode == 0 assert os.path.isdir(scenario_directory) - cmd = sh.molecule.bake("test", "-s", "test-scenario") - run_command(cmd) + cmd = ["molecule", "--debug", "test", "-s", "test-scenario"] + result = run_command(cmd) + assert result.returncode == 0