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

drivers: refactored sanity_check #2284

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions molecule/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import pluggy
from importlib import import_module
from molecule import logger
from molecule.util import lru_cache
import traceback

LOG = logger.get_logger(__name__)
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache


CORE_DRIVERS = [
Expand Down
23 changes: 9 additions & 14 deletions molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
from molecule.verifier import inspec
from molecule.verifier import testinfra

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache


LOG = logger.get_logger(__name__)
MOLECULE_DEBUG = boolean(os.environ.get('MOLECULE_DEBUG', 'False'))
Expand Down Expand Up @@ -145,7 +140,7 @@ def molecule_directory(self):
return molecule_directory(self.project_directory)

@property
@lru_cache()
@util.lru_cache()
def dependency(self):
dependency_name = self.config['dependency']['name']
if dependency_name == 'galaxy':
Expand All @@ -156,7 +151,7 @@ def dependency(self):
return shell.Shell(self)

@property
@lru_cache()
@util.lru_cache()
def driver(self):
driver_name = self._get_driver_name()
driver = None
Expand Down Expand Up @@ -194,36 +189,36 @@ def env(self):
}

@property
@lru_cache()
@util.lru_cache()
def lint(self):
lint_name = self.config['lint']['name']
if lint_name == 'yamllint':
return yamllint.Yamllint(self)

@property
@lru_cache()
@util.lru_cache()
def platforms(self):
return platforms.Platforms(self, parallelize_platforms=self.is_parallel)

@property
@lru_cache()
@util.lru_cache()
def provisioner(self):
provisioner_name = self.config['provisioner']['name']
if provisioner_name == 'ansible':
return ansible.Ansible(self)

@property
@lru_cache()
@util.lru_cache()
def scenario(self):
return scenario.Scenario(self)

@property
@lru_cache()
@util.lru_cache()
def state(self):
return state.State(self)

@property
@lru_cache()
@util.lru_cache()
def verifier(self):
verifier_name = self.config['verifier']['name']
if verifier_name == 'testinfra':
Expand All @@ -236,7 +231,7 @@ def verifier(self):
return ansible_verifier.Ansible(self)

@property
@lru_cache()
@util.lru_cache()
def verifiers(self):
return molecule_verifiers()

Expand Down
7 changes: 2 additions & 5 deletions molecule/driver/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from molecule import logger
from molecule.driver import base
from molecule.util import lru_cache
from molecule.util import sysexit_with_message

log = logger.get_logger(__name__)
Expand Down Expand Up @@ -204,12 +205,10 @@ def login_options(self, instance_name):
def ansible_connection_options(self, instance_name):
return {'ansible_connection': 'docker'}

@lru_cache()
def sanity_checks(self):
"""Implement Docker driver sanity checks."""

if self._config.state.sanity_checked:
return

log.info("Sanity checks: '{}'".format(self._name))

try:
Expand Down Expand Up @@ -241,8 +240,6 @@ def sanity_checks(self):
)
sysexit_with_message(msg)

self._config.state.change_state('sanity_checked', True)


def load(self):
return Docker(self)
7 changes: 2 additions & 5 deletions molecule/driver/hetznercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from molecule import logger, util
from molecule.driver import base
from molecule.util import lru_cache
from molecule.util import sysexit_with_message

log = logger.get_logger(__name__)
Expand Down Expand Up @@ -148,12 +149,10 @@ def _get_instance_config(self, instance_name):
item for item in instance_config_dict if item['instance'] == instance_name
)

@lru_cache()
def sanity_checks(self):
"""Hetzner Cloud driver sanity checks."""

if self._config.state.sanity_checked:
return

log.info("Sanity checks: '{}'".format(self._name))

try:
Expand All @@ -174,8 +173,6 @@ def sanity_checks(self):
)
sysexit_with_message(msg)

self._config.state.change_state('sanity_checked', True)


def load(self):
return HetznerCloud(self)
6 changes: 2 additions & 4 deletions molecule/driver/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from molecule import logger
from molecule.driver import base
from molecule.util import lru_cache

log = logger.get_logger(__name__)

Expand Down Expand Up @@ -179,14 +180,11 @@ def login_options(self, instance_name):
def ansible_connection_options(self, instance_name):
return {'ansible_connection': 'podman'}

@lru_cache()
def sanity_checks(self):
"""Implement Podman driver sanity checks."""

if self._config.state.sanity_checked:
return

log.info("Sanity checks: '{}'".format(self._name))
self._config.state.change_state('sanity_checked', True)


def load(self):
Expand Down
7 changes: 1 addition & 6 deletions molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
import os
import shutil

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache

from molecule import logger
from molecule import util
from molecule.provisioner import base
Expand Down Expand Up @@ -634,7 +629,7 @@ def config_file(self):
return os.path.join(self._config.scenario.ephemeral_directory, 'ansible.cfg')

@property
@lru_cache()
@util.lru_cache()
def playbooks(self):
return ansible_playbooks.AnsiblePlaybooks(self._config)

Expand Down
6 changes: 1 addition & 5 deletions molecule/provisioner/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

import abc

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache

from molecule.util import lru_cache
from molecule.provisioner.lint import ansible_lint


Expand Down
15 changes: 1 addition & 14 deletions molecule/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
from molecule import util

LOG = logger.get_logger(__name__)
VALID_KEYS = [
'created',
'converged',
'driver',
'prepared',
'sanity_checked',
'run_uuid',
'is_parallel',
]
VALID_KEYS = ['created', 'converged', 'driver', 'prepared', 'run_uuid', 'is_parallel']


class InvalidState(Exception):
Expand Down Expand Up @@ -100,10 +92,6 @@ def driver(self):
def prepared(self):
return self._data.get('prepared')

@property
def sanity_checked(self):
return self._data.get('sanity_checked')

@property
def run_uuid(self):
return self._data.get('run_uuid')
Expand Down Expand Up @@ -143,7 +131,6 @@ def _default_data(self):
'created': False,
'driver': None,
'prepared': None,
'sanity_checked': False,
'run_uuid': self._config._run_uuid,
'is_parallel': self._config.is_parallel,
}
Expand Down
5 changes: 0 additions & 5 deletions molecule/test/unit/provisioner/test_ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
def _instance(config_instance):
_instance = ansible_playbook.AnsiblePlaybook('playbook', config_instance)

# FIXME(decentral1se): temporarily force the sanity checks to not run while
# putting the AnsiblePlaybook under test. TBD: reconsider whether invoking
# sanity checks within the `execute()` function makes sense.
_instance._config.state.change_state('sanity_checked', True)

return _instance


Expand Down
5 changes: 5 additions & 0 deletions molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import re
import sys

try:
from functools import lru_cache # noqa
except ImportError:
from backports.functools_lru_cache import lru_cache # noqa

import anyconfig
import colorama
import yaml
Expand Down
7 changes: 1 addition & 6 deletions molecule/verifier/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

import abc

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache

from molecule import util
from molecule.verifier.lint import flake8
from molecule.verifier.lint import precommit
Expand Down Expand Up @@ -107,7 +102,7 @@ def env(self):
)

@property
@lru_cache()
@util.lru_cache()
def lint(self):
lint_name = self._config.config['verifier']['lint']['name']
if lint_name == 'flake8':
Expand Down