Files
kubespray/roles/adduser/molecule/default/tests/test_default.py
Arthur Outhenin-Chalandre edc73bc3c8 project: upgrade test dependencies and drop ansible-core 2.11 (#10034)
Molecule 5.0 require ansible-core 2.12.10.
So this commit we update ansible-core from 2.12.5 to 2.12.10.
We also drop supporting two ansible-core version. Also we now use the "oldest"
still supported ansible-core version as both 2.11 is EOL and not
supported by molecule.



tests/molecule: remove linting in molecule to support molecule 5



tests/molecule: remove role name check for molecule 5 support

Kubespray doesn't use ansible galaxy style naming so we have to disable
that check.



contrib/inventory_builder: fix tox.ini for tox4



tests/molecule: fix get_playbook in testinfra tests



tests: upgrade most tests requirements

Exclude ansible-lint for now, I will do that in a separate PR.



tests/molecule: force kvm driver option

If we don't do this it fallbacks to qemu emulated on our CI for some
reasons.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
2023-06-02 20:40:40 -07:00

44 lines
1.4 KiB
Python

import os
from pathlib import Path
import testinfra.utils.ansible_runner
import yaml
from ansible.cli.playbook import PlaybookCLI
from ansible.playbook import Playbook
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def read_playbook(playbook):
cli_args = [os.path.realpath(playbook), testinfra_hosts]
cli = PlaybookCLI(cli_args)
cli.parse()
loader, inventory, variable_manager = cli._play_prereqs()
pb = Playbook.load(cli.args[0], variable_manager, loader)
for play in pb.get_plays():
yield variable_manager.get_vars(play)
def get_playbook():
playbooks_path = Path(__file__).parent.parent
with open(os.path.join(playbooks_path, "molecule.yml"), "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
if "playbooks" in data["provisioner"].keys():
if "converge" in data["provisioner"]["playbooks"].keys():
return data["provisioner"]["playbooks"]["converge"]
else:
return os.path.join(playbooks_path, "converge.yml")
def test_user(host):
for vars in read_playbook(get_playbook()):
assert host.user(vars["user"]["name"]).exists
if "group" in vars["user"].keys():
assert host.group(vars["user"]["group"]).exists
else:
assert host.group(vars["user"]["name"]).exists