Skip to content

Commit

Permalink
Use hosts.get_all_names() helper within tests, where possible
Browse files Browse the repository at this point in the history
Change-Id: Ib46bc32f2aa5bc82d1e57ac0a59ad27e2abe03d7
  • Loading branch information
MatteoStifano committed Dec 17, 2024
1 parent bc670c2 commit 407e758
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions tests/composition/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ def _connection(
try:
yield
finally:
hostnames = {h["id"] for h in central_site.openapi.hosts.get_all()}
logger.warning("Hosts left: %s", hostnames)
logger.warning("Hosts left: %s", central_site.openapi.hosts.get_all_names())
central_site.openapi.sites.delete(remote_site.id)
central_site.openapi.activate_changes_and_wait_for_completion(
# this seems to be necessary to avoid sporadic CI failures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _test_rename_preserves_registration(
connection_details["remote"]["hostname"] == new_hostname
), f"Checking if controller sees renaming failed!\nStatus:\n{controller_status}"
finally:
hostnames = {_["id"] for _ in central_site.openapi.hosts.get_all()}
hostnames = set(central_site.openapi.hosts.get_all_names())
for hostname_ in hostnames.intersection({hostname, new_hostname}):
central_site.openapi.hosts.delete(hostname_)
central_site.openapi.activate_changes_and_wait_for_completion(force_foreign_changes=True)
Expand Down
6 changes: 3 additions & 3 deletions tests/composition/test_automatic_host_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_automatic_host_removal(
try:

def _host_removal_done() -> bool:
hostnames = {_["id"] for _ in central_site.openapi.hosts.get_all()}
hostnames = set(central_site.openapi.hosts.get_all_names())
return not hostnames.intersection({unresolvable_host_central, unresolvable_host_remote})

logger.info("Waiting for hosts to be removed")
Expand All @@ -77,8 +77,8 @@ def _host_removal_done() -> bool:
raise
finally:
central_site.openapi.rules.delete(rule_id=rule_id)
if unresolvable_host_central in [_.get("id") for _ in central_site.openapi.hosts.get_all()]:
if unresolvable_host_central in central_site.openapi.hosts.get_all_names():
central_site.openapi.hosts.delete(unresolvable_host_central)
if unresolvable_host_remote in [_.get("id") for _ in central_site.openapi.hosts.get_all()]:
if unresolvable_host_remote in central_site.openapi.hosts.get_all_names():
central_site.openapi.hosts.delete(unresolvable_host_remote)
central_site.openapi.activate_changes_and_wait_for_completion(force_foreign_changes=True)
4 changes: 2 additions & 2 deletions tests/plugins_integration/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_host_names(site: Site | None = None, piggyback: bool = False) -> list[st
host_names = []
dump_dir = str(config.dump_dir) + ("/piggyback" if piggyback else "")
if site:
hosts = [_ for _ in site.openapi.hosts.get_all() if _.get("id") not in (None, "", site.id)]
hosts = [_ for _ in site.openapi.hosts.get_all_names() if _ not in (None, "", site.id)]
agent_host_names = [
_.get("id") for _ in hosts if "tag_snmp_ds" not in _.get("attributes", {})
]
Expand Down Expand Up @@ -605,7 +605,7 @@ def cleanup_hosts(site: Site, host_names: list[str]) -> None:


def get_piggyback_hosts(site: Site, source_host: str) -> list[str]:
return [_.get("id") for _ in site.openapi.hosts.get_all() if _.get("id") != source_host]
return [_ for _ in site.openapi.hosts.get_all_names() if _ != source_host]


def _wait_for_piggyback_hosts_discovery(site: Site, source_host: str, strict: bool = True) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/testlib/openapi_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def bulk_create(
ignore_existing: bool = False,
) -> list[dict[str, Any]]:
if ignore_existing:
existing_hosts = [_.get("id") for _ in self.get_all()]
existing_hosts = self.get_all_names()
entries = [_ for _ in entries if _.get("host_name") not in existing_hosts]
query_string = "?bake_agent=1" if bake_agent else ""
response = self.session.post(
Expand Down

0 comments on commit 407e758

Please sign in to comment.