Support dropping sh
dependency
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
8e06794f3c
commit
781e7ec7bb
@ -5,7 +5,7 @@ Hetzner Cloud plugin installation guide
|
|||||||
Requirements
|
Requirements
|
||||||
============
|
============
|
||||||
|
|
||||||
* Ansible >= 2.9
|
* Ansible >= 2.10
|
||||||
* ``HCLOUD_TOKEN`` exposed in your environment
|
* ``HCLOUD_TOKEN`` exposed in your environment
|
||||||
|
|
||||||
Install
|
Install
|
||||||
|
@ -12,13 +12,14 @@ LOG = logger.get_logger(__name__)
|
|||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def run_command(cmd, env=os.environ, log=True):
|
def run_command(cmd, env=os.environ, log=True):
|
||||||
if log:
|
if cmd.__class__.__name__ == "Command":
|
||||||
cmd = _rebake_command(cmd, env)
|
if log:
|
||||||
cmd = cmd.bake(_truncate_exc=False)
|
cmd = _rebake_command(cmd, env)
|
||||||
return util.run_command(cmd)
|
cmd = cmd.bake(_truncate_exc=False)
|
||||||
|
return util.run_command(cmd, env=env)
|
||||||
|
|
||||||
|
|
||||||
def _rebake_command(cmd, env, out=LOG.out, err=LOG.error):
|
def _rebake_command(cmd, env, out=LOG.info, err=LOG.error):
|
||||||
return cmd.bake(_env=env, _out=out, _err=err)
|
return cmd.bake(_env=env, _out=out, _err=err)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import pkg_resources
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
|
import pkg_resources
|
||||||
import pytest
|
import pytest
|
||||||
import sh
|
from molecule import logger, util
|
||||||
|
|
||||||
from molecule import logger
|
|
||||||
from molecule import util
|
|
||||||
|
|
||||||
from ..conftest import change_dir_to
|
from ..conftest import change_dir_to
|
||||||
|
|
||||||
@ -37,9 +34,8 @@ def with_scenario(request, scenario_to_test, driver_name, scenario_name, skip_te
|
|||||||
yield
|
yield
|
||||||
if scenario_name:
|
if scenario_name:
|
||||||
msg = "CLEANUP: Destroying instances for all scenario(s)"
|
msg = "CLEANUP: Destroying instances for all scenario(s)"
|
||||||
LOG.out(msg)
|
LOG.info(msg)
|
||||||
options = {"driver_name": driver_name, "all": True}
|
cmd = ["molecule", "destroy", "--driver-name", driver_name, "--all"]
|
||||||
cmd = sh.molecule.bake("destroy", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@ -63,56 +59,56 @@ def skip_test(request, driver_name):
|
|||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def idempotence(scenario_name):
|
def idempotence(scenario_name):
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "create", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("create", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "converge", "--scenario_name", scenario_name]
|
||||||
cmd = sh.molecule.bake("converge", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "--scenario_name", scenario_name]
|
||||||
cmd = sh.molecule.bake("idempotence", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def init_role(temp_dir, driver_name):
|
def init_role(temp_dir, driver_name):
|
||||||
role_directory = os.path.join(temp_dir.strpath, "test-init")
|
cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]
|
||||||
|
|
||||||
cmd = sh.molecule.bake(
|
|
||||||
"init", "role", {"driver-name": driver_name, "role-name": "test-init"}
|
|
||||||
)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
role_directory = os.path.join(temp_dir.strpath, "test-init")
|
||||||
pytest.helpers.metadata_lint_update(role_directory)
|
pytest.helpers.metadata_lint_update(role_directory)
|
||||||
|
|
||||||
with change_dir_to(role_directory):
|
with change_dir_to(role_directory):
|
||||||
options = {"all": True}
|
cmd = ["molecule", "test", "--all"]
|
||||||
cmd = sh.molecule.bake("test", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def init_scenario(temp_dir, driver_name):
|
def init_scenario(temp_dir, driver_name):
|
||||||
role_directory = os.path.join(temp_dir.strpath, "test-init")
|
cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]
|
||||||
cmd = sh.molecule.bake(
|
|
||||||
"init", "role", {"driver-name": driver_name, "role-name": "test-init"}
|
|
||||||
)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
role_directory = os.path.join(temp_dir.strpath, "test-init")
|
||||||
pytest.helpers.metadata_lint_update(role_directory)
|
pytest.helpers.metadata_lint_update(role_directory)
|
||||||
|
|
||||||
with change_dir_to(role_directory):
|
with change_dir_to(role_directory):
|
||||||
molecule_directory = pytest.helpers.molecule_directory()
|
molecule_directory = pytest.helpers.molecule_directory()
|
||||||
scenario_directory = os.path.join(molecule_directory, "test-scenario")
|
scenario_directory = os.path.join(molecule_directory, "test-scenario")
|
||||||
|
|
||||||
options = {"scenario_name": "test-scenario", "role_name": "test-init"}
|
cmd = [
|
||||||
cmd = sh.molecule.bake("init", "scenario", **options)
|
"molecule",
|
||||||
|
"init",
|
||||||
|
"scenario",
|
||||||
|
"test-scenario",
|
||||||
|
"--role-name",
|
||||||
|
"test-init",
|
||||||
|
"--driver-name",
|
||||||
|
driver_name,
|
||||||
|
]
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
assert os.path.isdir(scenario_directory)
|
assert os.path.isdir(scenario_directory)
|
||||||
|
|
||||||
options = {"scenario_name": "test-scenario", "all": True}
|
cmd = ["molecule", "test", "--scenario-name", "test-scenario", "--all"]
|
||||||
cmd = sh.molecule.bake("test", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@ -125,13 +121,13 @@ def metadata_lint_update(role_directory):
|
|||||||
shutil.copy(ansible_lint_src, role_directory)
|
shutil.copy(ansible_lint_src, role_directory)
|
||||||
|
|
||||||
with change_dir_to(role_directory):
|
with change_dir_to(role_directory):
|
||||||
cmd = sh.ansible_lint.bake(".")
|
cmd = ["ansible-lint", "."]
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def list(x):
|
def list(x):
|
||||||
cmd = sh.molecule.bake("list")
|
cmd = ["molecule", "list"]
|
||||||
out = pytest.helpers.run_command(cmd, log=False)
|
out = pytest.helpers.run_command(cmd, log=False)
|
||||||
out = out.stdout.decode("utf-8")
|
out = out.stdout.decode("utf-8")
|
||||||
out = util.strip_ansi_color(out)
|
out = util.strip_ansi_color(out)
|
||||||
@ -142,10 +138,9 @@ def list(x):
|
|||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def list_with_format_plain(x):
|
def list_with_format_plain(x):
|
||||||
cmd = sh.molecule.bake("list", {"format": "plain"})
|
cmd = ["molecule", "list", "--format", "plain"]
|
||||||
out = pytest.helpers.run_command(cmd, log=False)
|
result = util.run_command(cmd)
|
||||||
out = out.stdout.decode("utf-8")
|
out = util.strip_ansi_color(result.stdout)
|
||||||
out = util.strip_ansi_color(out)
|
|
||||||
|
|
||||||
for l in x.splitlines():
|
for l in x.splitlines():
|
||||||
assert l in out
|
assert l in out
|
||||||
@ -153,12 +148,10 @@ def list_with_format_plain(x):
|
|||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def login(login_args, scenario_name="default"):
|
def login(login_args, scenario_name="default"):
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "destroy", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("destroy", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "create", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("create", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
for instance, regexp in login_args:
|
for instance, regexp in login_args:
|
||||||
@ -175,31 +168,26 @@ def login(login_args, scenario_name="default"):
|
|||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def test(driver_name, scenario_name="default", parallel=False):
|
def test(driver_name, scenario_name="default", parallel=False):
|
||||||
options = {
|
cmd = ["molecule", "test", "--scenario-name", scenario_name]
|
||||||
"scenario_name": scenario_name,
|
|
||||||
"all": scenario_name is None,
|
|
||||||
"parallel": parallel,
|
|
||||||
}
|
|
||||||
|
|
||||||
if driver_name == "delegated":
|
if driver_name != "delegated":
|
||||||
options = {"scenario_name": scenario_name}
|
if scenario_name is None:
|
||||||
|
cmd.append("--all")
|
||||||
|
if parallel:
|
||||||
|
cmd.append("--parallel")
|
||||||
|
|
||||||
cmd = sh.molecule.bake("test", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def verify(scenario_name="default"):
|
def verify(scenario_name="default"):
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "create", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("create", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "converge", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("converge", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
options = {"scenario_name": scenario_name}
|
cmd = ["molecule", "verify", "--scenario-name", scenario_name]
|
||||||
cmd = sh.molecule.bake("verify", **options)
|
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import sh
|
|
||||||
|
|
||||||
from molecule import util
|
from molecule import util
|
||||||
from molecule.command.init import base
|
from molecule.command.init import base
|
||||||
from molecule.model import schema_v3
|
from molecule.model import schema_v3
|
||||||
@ -57,5 +55,5 @@ def test_drivers(
|
|||||||
|
|
||||||
assert {} == schema_v3.validate(data)
|
assert {} == schema_v3.validate(data)
|
||||||
|
|
||||||
cmd = sh.yamllint.bake("-s", _molecule_file)
|
cmd = ["yamllint", "-s", _molecule_file]
|
||||||
pytest.helpers.run_command(cmd)
|
pytest.helpers.run_command(cmd)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from molecule import config
|
from molecule import config
|
||||||
from molecule_hetznercloud import driver
|
from molecule_hetznercloud import driver
|
||||||
|
|
||||||
@ -15,13 +14,6 @@ def test_hetznercloud_config_gives_config_object(hetznercloud_instance):
|
|||||||
assert isinstance(hetznercloud_instance._config, config.Config)
|
assert isinstance(hetznercloud_instance._config, config.Config)
|
||||||
|
|
||||||
|
|
||||||
def test_hetznercloud_testinfra_options_property(hetznercloud_instance):
|
|
||||||
assert {
|
|
||||||
"connection": "ansible",
|
|
||||||
"ansible-inventory": hetznercloud_instance._config.provisioner.inventory_file,
|
|
||||||
} == hetznercloud_instance.testinfra_options
|
|
||||||
|
|
||||||
|
|
||||||
def test_hetznercloud_name_property(hetznercloud_instance):
|
def test_hetznercloud_name_property(hetznercloud_instance):
|
||||||
assert "hetznercloud" == hetznercloud_instance.name
|
assert "hetznercloud" == hetznercloud_instance.name
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user