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

Expand LXD driver functionality #1436

Merged
merged 14 commits into from Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion molecule/command/init/template.py
Expand Up @@ -35,7 +35,7 @@ class Template(base.Base):
"""
.. program:: molecule init template --url https://example.com/user/cookiecutter-repo

.. option:: molecule init init template --url https://example.com/user/cookiecutter-repo
.. option:: molecule init template --url https://example.com/user/cookiecutter-repo

Initialize a new role from a Cookiecutter URL.
""" # noqa
Expand Down

This file was deleted.

11 changes: 11 additions & 0 deletions molecule/driver/lxd.py
Expand Up @@ -38,6 +38,17 @@ class LXD(base.Base):

driver:
name: lxd
platforms:
- name: instance
url: https://127.0.0.1:8443
cert_file: "/root/.config/lxc/client.crt"
key_file: "/root/.config/lxc/client.key"
trust_password: password
mode: pull|local
server: https://images.linuxcontainers.org
alias: ubuntu/xenial/amd64
profiles:
- default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have implemented this API for molecule.yml we need to validate the schema. Can you update the v2 schema similar to what we did with dockder and vagrant.

https://github.com/metacloud/molecule/blob/master/molecule/model/schema_v2.py#L596
https://github.com/metacloud/molecule/blob/master/molecule/model/schema_v2.py#L862

And we will need to update tests with working and failing tests:

https://github.com/metacloud/molecule/blob/master/test/unit/model/v2/test_platforms_section.py


Provide the files Molecule will preserve upon each subcommand execution.

Expand Down
@@ -1,5 +1,4 @@
---
{% raw -%}
- name: Create
hosts: localhost
connection: local
Expand All @@ -8,16 +7,19 @@
tasks:
- name: Create molecule instance(s)
lxd_container:
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) }}"
name: "{{ item.name }}"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
mode: "{{ item.mode | default('pull') }}"
server: "{{ item.server | default('https://images.linuxcontainers.org') }}"
protocol: lxd
alias: ubuntu/xenial/amd64
profiles: ["default"]
alias: "{{ item.alias | default('ubuntu/xenial/amd64') }}"
profiles: "{{ item.profiles | default(omit) }}"
wait_for_ipv4_addresses: true
timeout: 600
with_items: "{{ molecule_yml.platforms }}"
{%- endraw %}
@@ -1,5 +1,4 @@
---
{% raw %}
- name: Destroy
hosts: localhost
connection: local
Expand All @@ -8,8 +7,11 @@
tasks:
- name: Destroy molecule instance(s)
lxd_container:
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) }}"
name: "{{ item.name }}"
state: absent
force_stop: "{{ item.force_stop | default(true) }}"
with_items: "{{ molecule_yml.platforms }}"
{%- endraw %}
53 changes: 53 additions & 0 deletions molecule/provisioner/ansible/playbooks/lxd/prepare.yml
@@ -0,0 +1,53 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Test if Python is installed
raw: python -V # execute Python
register: python_version
changed_when: "'not found' in python_version.stderr"
failed_when: false

- name: Install Python when not installed
raw: |
if [ -x "$(command -v apt-get)" ]
then
apt-get update && apt-get install -y python
elif [ -x "$(command -v yum)" ]
then
yum install -y python
elif [ -x "$(command -v zypper)" ]
then
zypper -n --gpg-auto-import-keys refresh && zypper -n install -y python python-xml
elif [ -x "$(command -v apk)" ]
then
apk update && apk add python
elif [ -x "$(command -v pacman)" ]
then
pacman -Syu --noconfirm python2
elif [ -x "$(command -v dnf)" ]
then
dnf --assumeyes install python python-devel python2-dnf
elif [ -x "$(command -v emerge)" ]
then
emerge --ask n dev-lang/python-2
fi
when: "'not found' in python_version.stderr"

- name: Gathering Facts
setup: # aka gather_facts

- name: Install equery on Gentoo based containers when not available
raw: test -e /usr/bin/equery || emerge --ask n gentoolkit
register: equery_status
changed_when: equery_status.stdout != ''
when: ansible_os_family == 'Gentoo'

- name: Install some basic packages because LXC containers are bare
package:
name:
- ca-certificates
- curl
- sudo
state: present
12 changes: 8 additions & 4 deletions test/resources/playbooks/lxd/create.yml
Expand Up @@ -7,15 +7,19 @@
tasks:
- name: Create molecule instance(s)
lxd_container:
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) }}"
name: "{{ item.name }}"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
mode: "{{ item.mode | default('pull') }}"
server: "{{ item.server | default('https://images.linuxcontainers.org') }}"
protocol: lxd
alias: ubuntu/xenial/amd64
profiles: ["default"]
alias: "{{ item.alias | default('ubuntu/xenial/amd64') }}"
profiles: "{{ item.profiles | default(omit) }}"
wait_for_ipv4_addresses: true
timeout: 600
with_items: "{{ molecule_yml.platforms }}"
4 changes: 4 additions & 0 deletions test/resources/playbooks/lxd/destroy.yml
Expand Up @@ -7,6 +7,10 @@
tasks:
- name: Destroy molecule instance(s)
lxd_container:
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) }}"
name: "{{ item.name }}"
state: absent
force_stop: "{{ item.force_stop | default(true) }}"
Expand Down
9 changes: 0 additions & 9 deletions test/scenarios/driver/lxd/molecule/default/prepare.yml

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenarios/driver/lxd/molecule/multi-node/prepare.yml

This file was deleted.