Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from bonddim/master
Browse files Browse the repository at this point in the history
Updated plugin to use newer molecule APIs
  • Loading branch information
ssbarnea authored Mar 2, 2021
2 parents e27e24a + 455a67f commit cc40697
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
37 changes: 37 additions & 0 deletions molecule_lxd/playbooks/create.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions molecule_lxd/playbooks/destroy.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions molecule_lxd/playbooks/prepare.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 19 additions & 17 deletions molecule_lxd/test/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc40697

Please sign in to comment.