Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
# 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.
from molecule import logger
from molecule import util
LOG = logger.get_logger(__name__)
class Platforms(object):
"""
Platforms define the instances to be tested, and the groups to which the
instances belong.
.. code-block:: yaml
platforms:
- name: instance-1
Multiple instances can be provided.
.. code-block:: yaml
# DEALINGS IN THE SOFTWARE.
import shutil
import os
import fnmatch
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
from molecule import logger
from molecule import scenarios
from molecule import util
LOG = logger.get_logger(__name__)
class Scenario(object):
"""
A scenario allows Molecule test a role in a particular way, this is a
fundamental change from Molecule v1.
A scenario is a self-contained directory containing everything necessary
for testing the role in a particular way. The default scenario is named
``default``, and every role should contain a default scenario.
Unless mentioned explicitly, the scenario name will be the directory name
hosting the files.
Any option set in this section will override the defaults.
# DEALINGS IN THE SOFTWARE.
import abc
import collections
import glob
import os
import six
import molecule.command
import molecule.scenarios
from molecule import config
from molecule import logger
from molecule import util
LOG = logger.get_logger(__name__)
MOLECULE_GLOB = os.environ.get('MOLECULE_GLOB', 'molecule/*/molecule.yml')
MOLECULE_DEFAULT_SCENARIO_NAME = 'default'
@six.add_metaclass(abc.ABCMeta)
class Base(object):
"""
An abstract base class used to define the command interface.
"""
def __init__(self, c):
"""
Base initializer for all :ref:`Command` classes.
:param c: An instance of a Molecule config.
:returns: None
# 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.
import os
import click
from molecule import logger
from molecule.command import base
from molecule import util
LOG = logger.get_logger(__name__)
MOLECULE_PARALLEL = os.environ.get('MOLECULE_PARALLEL', False)
class Check(base.Base):
"""
.. program:: molecule check
.. option:: molecule check
Target the default scenario.
.. program:: molecule check --scenario-name foo
.. option:: molecule check --scenario-name foo
Targeting a specific scenario.
from six.moves import UserList
import pluggy
from molecule import logger
from molecule.util import lru_cache
from molecule.driver.base import Driver # noqa
from molecule.verifier.base import Verifier # noqa
import traceback
LOG = logger.get_logger(__name__)
class UserListMap(UserList):
""" A list where you can also access elements by their name using:
foo['boo']
foo.boo
"""
def __getitem__(self, i):
if isinstance(i, int):
return super(UserListMap, self).__getitem__(i)
else:
return self.__dict__[i]
def get(self, key, default):
return self.__dict__.get(key, default)
# 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.
from molecule import logger
from molecule import util
from molecule.api import Driver
LOG = logger.get_logger(__name__)
class Delegated(Driver):
"""
The class responsible for managing delegated instances. Delegated is `not`
the default driver used in Molecule.
Under this driver, it is the developers responsibility to implement the
create and destroy playbooks. ``Managed`` is the default behaviour of all
drivers.
.. code-block:: yaml
driver:
name: delegated
# 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.
from molecule import logger
from molecule.api import Driver
from molecule import util
LOG = logger.get_logger(__name__)
class GCE(Driver):
"""
The class responsible for managing `GCE`_ instances. `GCE`_
is `not` the default driver used in Molecule.
GCE is somewhat different than other cloud providers. There is not
an Ansible module for managing ssh keys. This driver assumes the developer
has deployed project wide ssh key.
Molecule leverages Ansible's `gce_module`_, by mapping variables from
``molecule.yml`` into ``create.yml`` and ``destroy.yml``.
.. _`gce_module`: https://docs.ansible.com/ansible/latest/gce_module.html
# 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.
import os
import sh
from molecule import logger
from molecule import util
from molecule.provisioner.lint import base
LOG = logger.get_logger(__name__)
__metaclass__ = type
class AnsibleLintMixin:
def __init__(self, config):
"""
Sets up the requirements to execute `ansible-lint` and returns None.
:param config: An instance of a Molecule config.
:return: None
"""
super(AnsibleLintMixin, self).__init__(config)
self._ansible_lint_command = None
@property
#
# 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.
from molecule import logger
from molecule.api import Driver
LOG = logger.get_logger(__name__)
class LXC(Driver):
"""
The class responsible for managing `LXC`_ containers. `LXC`_ is `not` the
default driver used in Molecule.
Molecule leverages Ansible's `lxc_container`_ module, by mapping variables
from ``molecule.yml`` into ``create.yml`` and ``destroy.yml``.
.. _`lxc_container`: https://docs.ansible.com/ansible/latest/lxc_container_module.html
.. code-block:: yaml
driver:
name: lxc
except ImportError:
HAS_CRYPTOGRAPHY = False
try:
import boto3
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
from molecule import logger
from molecule.api import Driver
from molecule import util
LOG = logger.get_logger(__name__)
class EC2(Driver):
"""
The class responsible for managing `EC2`_ instances. `EC2`_
is ``not`` the default driver used in Molecule.
Molecule leverages Ansible's `ec2_module`_, by mapping variables from
``molecule.yml`` into ``create.yml`` and ``destroy.yml``.
.. _`ec2_module`: https://docs.ansible.com/ansible/latest/ec2_module.html
.. code-block:: yaml
driver:
name: ec2