Skip to content

Commit bbaf82e

Browse files
authored
Adopt molecule-containers plugin (#68)
1 parent a7333cd commit bbaf82e

File tree

15 files changed

+183
-2
lines changed

15 files changed

+183
-2
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ubuntu-22.04
3535
needs: pre
3636
env:
37-
PYTEST_REQPASS: 11
37+
PYTEST_REQPASS: 13
3838
strategy:
3939
fail-fast: false
4040
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ podman = [
7979

8080
[project.entry-points."molecule.driver"]
8181
azure = "molecule_plugins.azure.driver:Azure"
82+
containers = "molecule_plugins.containers.driver:Container"
8283
docker = "molecule_plugins.docker.driver:Docker"
8384
ec2 = "molecule_plugins.ec2.driver:EC2"
8485
gce = "molecule_plugins.gce.driver:GCE"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Molecule Containers Drivers."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"molecule_directory": "molecule",
3+
"role_name": "OVERRIDDEN",
4+
"scenario_name": "OVERRIDDEN"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
# Disabled gather as it seems broken on podman
5+
# https://github.com/ansible-community/molecule-podman/issues/2
6+
gather_facts: false
7+
tasks:
8+
- name: Test implementation
9+
debug:
10+
msg: Add test implementation here
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Containers Driver Module."""
2+
from __future__ import absolute_import
3+
4+
import inspect
5+
import os
6+
import shutil
7+
from typing import Dict
8+
9+
from molecule import logger
10+
11+
_logger = logger.get_logger(__name__)
12+
13+
# Preference logic for picking backend driver to be used.
14+
drivers = os.environ.get("MOLECULE_CONTAINERS_BACKEND", "podman,docker").split(",")
15+
for driver in drivers:
16+
if shutil.which(driver):
17+
break
18+
else:
19+
driver = drivers[0]
20+
21+
# Logic for picking backend is subject to change.
22+
if driver == "docker":
23+
from molecule_plugins.docker.driver import Docker as DriverBackend
24+
elif driver == "podman":
25+
from molecule_plugins.podman.driver import Podman as DriverBackend
26+
else:
27+
raise NotImplementedError(f"Driver {driver} is not supported.")
28+
_logger.debug("Containers driver will use %s backend", driver)
29+
30+
31+
class Container(DriverBackend):
32+
"""
33+
Container Driver Class.
34+
35+
This class aims to provide an agnostic container enginer implementation,
36+
which should allow users to consume whichever enginer they have available.
37+
""" # noqa
38+
39+
def __init__(self, config=None):
40+
"""Construct Container."""
41+
super().__init__(config)
42+
self._name = "containers"
43+
# Assure that _path points to the driver we would be using, or
44+
# molecule will fail to find the embedded playbooks.
45+
self._path = os.path.abspath(os.path.dirname(inspect.getfile(DriverBackend)))
46+
47+
@property
48+
def required_collections(self) -> Dict[str, str]:
49+
"""Return collections dict containing names and versions required."""
50+
return {
51+
"ansible.posix": "1.3.0",
52+
"community.docker": "1.9.1",
53+
"containers.podman": "1.8.1",
54+
}

test/containers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Molecule Containers Driver Tests."""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ansible-lint config for functional testing, used to bypass expected metadata
2+
# errors in molecule-generated roles. Loaded via the metadata_lint_update
3+
# pytest helper. For reference, see "E7xx - metadata" in:
4+
# https://docs.ansible.com/ansible-lint/rules/default_rules.html
5+
skip_list:
6+
# metadata/701 - Role info should contain platforms
7+
- '701'
8+
# metadata/703 - Should change default metadata: <field>"
9+
- '703'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Functional Tests."""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2015-2018 Cisco Systems, Inc.
2+
# Copyright (c) 2018 Red Hat, Inc.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to
6+
# deal in the Software without restriction, including without limitation the
7+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
# sell copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
# DEALINGS IN THE SOFTWARE.
21+
"""PyTest Config."""
22+
23+
from molecule.test.conftest import * # noqa pylint: disable=wildcard-import,unused-wildcard-import

0 commit comments

Comments
 (0)