-
Notifications
You must be signed in to change notification settings - Fork 658
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
Changes from 9 commits
d62c4ea
038c512
cae3eff
c046ad8
2394c5b
2d50359
6ed927d
b12752e
9a6ed00
d307ad4
f9441c4
221fceb
8a99924
f9b0eec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -710,6 +710,85 @@ def pre_validate_base_schema(env, keep_string): | |
}, | ||
} | ||
|
||
platforms_lxd_schema = { | ||
'platforms': { | ||
'type': 'list', | ||
'schema': { | ||
'type': 'dict', | ||
'schema': { | ||
'name': { | ||
'type': 'string', | ||
}, | ||
'url': { | ||
'type': 'string', | ||
}, | ||
'cert_file': { | ||
'type': 'string', | ||
}, | ||
'key_file': { | ||
'type': 'string', | ||
}, | ||
'trust_password': { | ||
'type': 'string', | ||
}, | ||
'source': { | ||
'type': 'dict', | ||
'schema': { | ||
'type': { | ||
'type': 'string', | ||
}, | ||
'mode': { | ||
'type': 'string', | ||
'allowed': [ | ||
'pull', | ||
'local', | ||
], | ||
}, | ||
'server': { | ||
'type': 'string', | ||
}, | ||
'protocol': { | ||
'type': 'string', | ||
'allowed': [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the schema as specific as possible, these are the only values valid for the LXD api. There are now allowed values (source). |
||
'lxd', | ||
'simplestreams', | ||
], | ||
}, | ||
'alias': { | ||
'type': 'string', | ||
}, | ||
}, | ||
}, | ||
'architecture': { | ||
'type': 'string', | ||
'allowed': [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here (source) |
||
'x86_64', | ||
'i686', | ||
], | ||
}, | ||
'devices': { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take a good look at the devices schema, that is the one I struggled with since I am not familiar with the markup. Might be not 100% correct |
||
'type': 'dict', | ||
'schema': { | ||
'type': 'dict', | ||
'keyschema': { | ||
'type': 'string', | ||
}, | ||
}, | ||
}, | ||
'profiles': { | ||
'type': 'list', | ||
'schema': { | ||
'type': 'string' | ||
} | ||
}, | ||
'force_stop': { | ||
'type': 'boolean', | ||
}, | ||
} | ||
} | ||
}, | ||
} | ||
|
||
dependency_command_nullable_schema = { | ||
'dependency': { | ||
'type': 'dict', | ||
|
@@ -863,6 +942,8 @@ def validate(c): | |
elif c['driver']['name'] == 'vagrant': | ||
util.merge_dicts(schema, driver_vagrant_provider_section_schema) | ||
util.merge_dicts(schema, platforms_vagrant_schema) | ||
elif c['driver']['name'] == 'lxd': | ||
util.merge_dicts(schema, platforms_lxd_schema) | ||
else: | ||
util.merge_dicts(schema, platforms_base_schema) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
- name: Create | ||
hosts: localhost | ||
connection: local | ||
gather_facts: false | ||
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}" | ||
tasks: | ||
- name: Create default source variable | ||
set_fact: | ||
default_source: | ||
type: image | ||
server: https://images.linuxcontainers.org | ||
alias: ubuntu/xenial/amd64 | ||
|
||
- 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: "{{ default_source | combine(item.source | default({})) }}" | ||
architecture: "{{ item.architecture | default(omit) }}" | ||
devices: "{{ item.devices | default(omit) }}" | ||
profiles: "{{ item.profiles | default(omit) }}" | ||
wait_for_ipv4_addresses: true | ||
timeout: 600 | ||
with_items: "{{ molecule_yml.platforms }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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