-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt molecule-containers plugin (#68)
- Loading branch information
Showing
15 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Molecule Containers Drivers.""" |
5 changes: 5 additions & 0 deletions
5
src/molecule_plugins/containers/cookiecutter/cookiecutter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"molecule_directory": "molecule", | ||
"role_name": "OVERRIDDEN", | ||
"scenario_name": "OVERRIDDEN" | ||
} |
10 changes: 10 additions & 0 deletions
10
...kiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/converge.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
# Disabled gather as it seems broken on podman | ||
# https://github.com/ansible-community/molecule-podman/issues/2 | ||
gather_facts: false | ||
tasks: | ||
- name: Test implementation | ||
debug: | ||
msg: Add test implementation here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Containers Driver Module.""" | ||
from __future__ import absolute_import | ||
|
||
import inspect | ||
import os | ||
import shutil | ||
from typing import Dict | ||
|
||
from molecule import logger | ||
|
||
_logger = logger.get_logger(__name__) | ||
|
||
# Preference logic for picking backend driver to be used. | ||
drivers = os.environ.get("MOLECULE_CONTAINERS_BACKEND", "podman,docker").split(",") | ||
for driver in drivers: | ||
if shutil.which(driver): | ||
break | ||
else: | ||
driver = drivers[0] | ||
|
||
# Logic for picking backend is subject to change. | ||
if driver == "docker": | ||
from molecule_plugins.docker.driver import Docker as DriverBackend | ||
elif driver == "podman": | ||
from molecule_plugins.podman.driver import Podman as DriverBackend | ||
else: | ||
raise NotImplementedError(f"Driver {driver} is not supported.") | ||
_logger.debug("Containers driver will use %s backend", driver) | ||
|
||
|
||
class Container(DriverBackend): | ||
""" | ||
Container Driver Class. | ||
This class aims to provide an agnostic container enginer implementation, | ||
which should allow users to consume whichever enginer they have available. | ||
""" # noqa | ||
|
||
def __init__(self, config=None): | ||
"""Construct Container.""" | ||
super().__init__(config) | ||
self._name = "containers" | ||
# Assure that _path points to the driver we would be using, or | ||
# molecule will fail to find the embedded playbooks. | ||
self._path = os.path.abspath(os.path.dirname(inspect.getfile(DriverBackend))) | ||
|
||
@property | ||
def required_collections(self) -> Dict[str, str]: | ||
"""Return collections dict containing names and versions required.""" | ||
return { | ||
"ansible.posix": "1.3.0", | ||
"community.docker": "1.9.1", | ||
"containers.podman": "1.8.1", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Molecule Containers Driver Tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ansible-lint config for functional testing, used to bypass expected metadata | ||
# errors in molecule-generated roles. Loaded via the metadata_lint_update | ||
# pytest helper. For reference, see "E7xx - metadata" in: | ||
# https://docs.ansible.com/ansible-lint/rules/default_rules.html | ||
skip_list: | ||
# metadata/701 - Role info should contain platforms | ||
- '701' | ||
# metadata/703 - Should change default metadata: <field>" | ||
- '703' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Functional Tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2015-2018 Cisco Systems, Inc. | ||
# Copyright (c) 2018 Red Hat, Inc. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
"""PyTest Config.""" | ||
|
||
from molecule.test.conftest import * # noqa pylint: disable=wildcard-import,unused-wildcard-import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2015-2018 Cisco Systems, Inc. | ||
# Copyright (c) 2018 Red Hat, Inc. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
"""Functional Tests.""" | ||
import os | ||
|
||
from molecule import logger | ||
from molecule.test.conftest import change_dir_to, molecule_directory | ||
from molecule.util import run_command | ||
|
||
LOG = logger.get_logger(__name__) | ||
|
||
|
||
def test_command_init_scenario(temp_dir): | ||
"""Verify that we can initialize a new scenario with this driver.""" | ||
with change_dir_to(temp_dir): | ||
scenario_directory = os.path.join(molecule_directory(), "default") | ||
cmd = [ | ||
"molecule", | ||
"init", | ||
"scenario", | ||
"default", | ||
"--driver-name", | ||
"containers", | ||
] | ||
result = run_command(cmd) | ||
assert result.returncode == 0 | ||
|
||
assert os.path.isdir(scenario_directory) | ||
|
||
# we do not run the full "test" sequence because lint will fail, check | ||
# is shorter but comprehensive enough to test the most important | ||
# functionality: destroy, dependency, create, prepare, converge | ||
cmd = ["molecule", "check", "-s", "default"] | ||
result = run_command(cmd) | ||
assert result.returncode == 0 |
9 changes: 9 additions & 0 deletions
9
test/containers/scenarios/driver/containers/molecule/default/converge.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
gather_facts: false | ||
become: true | ||
tasks: | ||
- name: Display bogus message | ||
ansible.builtin.debug: | ||
msg: seems ok |
7 changes: 7 additions & 0 deletions
7
test/containers/scenarios/driver/containers/molecule/default/molecule.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
driver: | ||
name: containers | ||
platforms: | ||
- name: instance | ||
provisioner: | ||
name: ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Unit Tests.""" | ||
from molecule import api | ||
|
||
|
||
def test_driver_is_detected(): | ||
"""Check that driver is recognized.""" | ||
assert "containers" in [str(d) for d in api.drivers()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters