Support dropping `sh` dependency
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Luke Murphy 2021-01-06 13:09:05 +01:00
parent 8e06794f3c
commit 781e7ec7bb
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 49 additions and 70 deletions

View File

@ -5,7 +5,7 @@ Hetzner Cloud plugin installation guide
Requirements
============
* Ansible >= 2.9
* Ansible >= 2.10
* ``HCLOUD_TOKEN`` exposed in your environment
Install

View File

@ -12,13 +12,14 @@ LOG = logger.get_logger(__name__)
@pytest.helpers.register
def run_command(cmd, env=os.environ, log=True):
if log:
cmd = _rebake_command(cmd, env)
cmd = cmd.bake(_truncate_exc=False)
return util.run_command(cmd)
if cmd.__class__.__name__ == "Command":
if log:
cmd = _rebake_command(cmd, env)
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)

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)

View File

@ -1,8 +1,6 @@
import os
import pytest
import sh
from molecule import util
from molecule.command.init import base
from molecule.model import schema_v3
@ -57,5 +55,5 @@ def test_drivers(
assert {} == schema_v3.validate(data)
cmd = sh.yamllint.bake("-s", _molecule_file)
cmd = ["yamllint", "-s", _molecule_file]
pytest.helpers.run_command(cmd)

View File

@ -1,7 +1,6 @@
import os
import pytest
from molecule import config
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)
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):
assert "hetznercloud" == hetznercloud_instance.name