Support dropping sh dependency
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Luke Murphy
2021-01-06 13:09:05 +01:00
parent 8e06794f3c
commit 781e7ec7bb
5 changed files with 49 additions and 70 deletions

View File

@ -1,13 +1,10 @@
import os
import pkg_resources
import shutil
import pexpect
import pkg_resources
import pytest
import sh
from molecule import logger
from molecule import util
from molecule import logger, util
from ..conftest import change_dir_to
@ -37,9 +34,8 @@ def with_scenario(request, scenario_to_test, driver_name, scenario_name, skip_te
yield
if scenario_name:
msg = "CLEANUP: Destroying instances for all scenario(s)"
LOG.out(msg)
options = {"driver_name": driver_name, "all": True}
cmd = sh.molecule.bake("destroy", **options)
LOG.info(msg)
cmd = ["molecule", "destroy", "--driver-name", driver_name, "--all"]
pytest.helpers.run_command(cmd)
@ -63,56 +59,56 @@ def skip_test(request, driver_name):
@pytest.helpers.register
def idempotence(scenario_name):
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("create", **options)
cmd = ["molecule", "create", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("converge", **options)
cmd = ["molecule", "converge", "--scenario_name", scenario_name]
pytest.helpers.run_command(cmd)
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("idempotence", **options)
cmd = ["molecule", "--scenario_name", scenario_name]
pytest.helpers.run_command(cmd)
@pytest.helpers.register
def init_role(temp_dir, driver_name):
role_directory = os.path.join(temp_dir.strpath, "test-init")
cmd = sh.molecule.bake(
"init", "role", {"driver-name": driver_name, "role-name": "test-init"}
)
cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]
pytest.helpers.run_command(cmd)
role_directory = os.path.join(temp_dir.strpath, "test-init")
pytest.helpers.metadata_lint_update(role_directory)
with change_dir_to(role_directory):
options = {"all": True}
cmd = sh.molecule.bake("test", **options)
cmd = ["molecule", "test", "--all"]
pytest.helpers.run_command(cmd)
@pytest.helpers.register
def init_scenario(temp_dir, driver_name):
role_directory = os.path.join(temp_dir.strpath, "test-init")
cmd = sh.molecule.bake(
"init", "role", {"driver-name": driver_name, "role-name": "test-init"}
)
cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]
pytest.helpers.run_command(cmd)
role_directory = os.path.join(temp_dir.strpath, "test-init")
pytest.helpers.metadata_lint_update(role_directory)
with change_dir_to(role_directory):
molecule_directory = pytest.helpers.molecule_directory()
scenario_directory = os.path.join(molecule_directory, "test-scenario")
options = {"scenario_name": "test-scenario", "role_name": "test-init"}
cmd = sh.molecule.bake("init", "scenario", **options)
cmd = [
"molecule",
"init",
"scenario",
"test-scenario",
"--role-name",
"test-init",
"--driver-name",
driver_name,
]
pytest.helpers.run_command(cmd)
assert os.path.isdir(scenario_directory)
options = {"scenario_name": "test-scenario", "all": True}
cmd = sh.molecule.bake("test", **options)
cmd = ["molecule", "test", "--scenario-name", "test-scenario", "--all"]
pytest.helpers.run_command(cmd)
@ -125,13 +121,13 @@ def metadata_lint_update(role_directory):
shutil.copy(ansible_lint_src, role_directory)
with change_dir_to(role_directory):
cmd = sh.ansible_lint.bake(".")
cmd = ["ansible-lint", "."]
pytest.helpers.run_command(cmd)
@pytest.helpers.register
def list(x):
cmd = sh.molecule.bake("list")
cmd = ["molecule", "list"]
out = pytest.helpers.run_command(cmd, log=False)
out = out.stdout.decode("utf-8")
out = util.strip_ansi_color(out)
@ -142,10 +138,9 @@ def list(x):
@pytest.helpers.register
def list_with_format_plain(x):
cmd = sh.molecule.bake("list", {"format": "plain"})
out = pytest.helpers.run_command(cmd, log=False)
out = out.stdout.decode("utf-8")
out = util.strip_ansi_color(out)
cmd = ["molecule", "list", "--format", "plain"]
result = util.run_command(cmd)
out = util.strip_ansi_color(result.stdout)
for l in x.splitlines():
assert l in out
@ -153,12 +148,10 @@ def list_with_format_plain(x):
@pytest.helpers.register
def login(login_args, scenario_name="default"):
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("destroy", **options)
cmd = ["molecule", "destroy", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("create", **options)
cmd = ["molecule", "create", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)
for instance, regexp in login_args:
@ -175,31 +168,26 @@ def login(login_args, scenario_name="default"):
@pytest.helpers.register
def test(driver_name, scenario_name="default", parallel=False):
options = {
"scenario_name": scenario_name,
"all": scenario_name is None,
"parallel": parallel,
}
cmd = ["molecule", "test", "--scenario-name", scenario_name]
if driver_name == "delegated":
options = {"scenario_name": scenario_name}
if driver_name != "delegated":
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.register
def verify(scenario_name="default"):
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("create", **options)
cmd = ["molecule", "create", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("converge", **options)
cmd = ["molecule", "converge", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)
options = {"scenario_name": scenario_name}
cmd = sh.molecule.bake("verify", **options)
cmd = ["molecule", "verify", "--scenario-name", scenario_name]
pytest.helpers.run_command(cmd)