feat: refactor add_group and add_host fixtures.

It refactors fixtures: `add_group` and `add_host` to improve fixtures
reusability in further scenarios.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
This commit is contained in:
Javier Cano Cano
2024-05-21 14:50:30 +02:00
parent 65f4ac6602
commit 7abe530e94

View File

@@ -27,7 +27,6 @@ from ansible_collections.kubevirt.core.plugins.inventory import (
kubevirt
)
DEFAULT_NAMESPACE = "default"
DEFAULT_BASE_DOMAIN = "example.com"
@@ -233,6 +232,7 @@ def add_group(monkeypatch, inventory):
def add_group(name):
if name not in groups:
groups.append(name)
return name
monkeypatch.setattr(inventory.inventory, "add_group", add_group)
return groups
@@ -242,9 +242,11 @@ def add_group(monkeypatch, inventory):
def add_host(monkeypatch, inventory):
hosts = []
def add_host(name):
def add_host(name, group=None):
if name not in hosts:
hosts.append(name)
if group is not None and group not in hosts:
hosts.append(group)
monkeypatch.setattr(inventory.inventory, "add_host", add_host)
return hosts