How to use min_ansible method in molecule

Best Python code snippet using molecule_python

conftest.py

Source:conftest.py Github

copy

Full Screen

...35 if driver_name == "delegated"36 else "Skipped '{}' not supported"37 )38 support_checks_map = {39 "hetznercloud": lambda: min_ansible("2.8") and supports_hetznercloud()40 }41 try:42 check_func = support_checks_map[driver_name]43 if not check_func():44 pytest.skip(msg_tmpl.format(driver_name))45 except KeyError:46 pass47@pytest.helpers.register48def idempotence(scenario_name):49 cmd = ["molecule", "create", "--scenario-name", scenario_name]50 pytest.helpers.run_command(cmd)51 cmd = ["molecule", "converge", "--scenario_name", scenario_name]52 pytest.helpers.run_command(cmd)53 cmd = ["molecule", "--scenario_name", scenario_name]54 pytest.helpers.run_command(cmd)55@pytest.helpers.register56def init_role(temp_dir, driver_name):57 cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]58 pytest.helpers.run_command(cmd)59 role_directory = os.path.join(temp_dir.strpath, "test-init")60 pytest.helpers.metadata_lint_update(role_directory)61 with change_dir_to(role_directory):62 cmd = ["molecule", "test", "--all"]63 pytest.helpers.run_command(cmd)64@pytest.helpers.register65def init_scenario(temp_dir, driver_name):66 cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]67 pytest.helpers.run_command(cmd)68 role_directory = os.path.join(temp_dir.strpath, "test-init")69 pytest.helpers.metadata_lint_update(role_directory)70 with change_dir_to(role_directory):71 molecule_directory = pytest.helpers.molecule_directory()72 scenario_directory = os.path.join(molecule_directory, "test-scenario")73 cmd = [74 "molecule",75 "init",76 "scenario",77 "test-scenario",78 "--role-name",79 "test-init",80 "--driver-name",81 driver_name,82 ]83 pytest.helpers.run_command(cmd)84 assert os.path.isdir(scenario_directory)85 cmd = ["molecule", "test", "--scenario-name", "test-scenario", "--all"]86 pytest.helpers.run_command(cmd)87@pytest.helpers.register88def metadata_lint_update(role_directory):89 ansible_lint_src = os.path.join(90 os.path.dirname(util.abs_path(__file__)), ".ansible-lint"91 )92 shutil.copy(ansible_lint_src, role_directory)93 with change_dir_to(role_directory):94 cmd = ["ansible-lint", "."]95 pytest.helpers.run_command(cmd)96@pytest.helpers.register97def list(x):98 cmd = ["molecule", "list"]99 out = pytest.helpers.run_command(cmd, log=False)100 out = out.stdout.decode("utf-8")101 out = util.strip_ansi_color(out)102 for l in x.splitlines():103 assert l in out104@pytest.helpers.register105def list_with_format_plain(x):106 cmd = ["molecule", "list", "--format", "plain"]107 result = util.run_command(cmd)108 out = util.strip_ansi_color(result.stdout)109 for l in x.splitlines():110 assert l in out111@pytest.helpers.register112def login(login_args, scenario_name="default"):113 cmd = ["molecule", "destroy", "--scenario-name", scenario_name]114 pytest.helpers.run_command(cmd)115 cmd = ["molecule", "create", "--scenario-name", scenario_name]116 pytest.helpers.run_command(cmd)117 for instance, regexp in login_args:118 if len(login_args) > 1:119 child_cmd = "molecule login --host {} --scenario-name {}".format(120 instance, scenario_name121 )122 else:123 child_cmd = "molecule login --scenario-name {}".format(scenario_name)124 child = pexpect.spawn(child_cmd)125 child.expect(regexp)126 child.sendline("exit")127@pytest.helpers.register128def test(driver_name, scenario_name="default", parallel=False):129 cmd = ["molecule", "test", "--scenario-name", scenario_name]130 if driver_name != "delegated":131 if scenario_name is None:132 cmd.append("--all")133 if parallel:134 cmd.append("--parallel")135 pytest.helpers.run_command(cmd)136@pytest.helpers.register137def verify(scenario_name="default"):138 cmd = ["molecule", "create", "--scenario-name", scenario_name]139 pytest.helpers.run_command(cmd)140 cmd = ["molecule", "converge", "--scenario-name", scenario_name]141 pytest.helpers.run_command(cmd)142 cmd = ["molecule", "verify", "--scenario-name", scenario_name]143 pytest.helpers.run_command(cmd)144def min_ansible(version):145 """Ensure current Ansible is newer than a given a minimal one."""146 try:147 from ansible.release import __version__148 return pkg_resources.parse_version(__version__) >= pkg_resources.parse_version(149 version150 )151 except ImportError as exception:152 LOG.error("Unable to parse Ansible version", exc_info=exception)153 return False154@pytest.helpers.register155def supports_hetznercloud():156 pytest.importorskip("hcloud")157 env_vars = ("HCLOUD_TOKEN",)158 return _env_vars_exposed(env_vars)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful