inventory: Exclude test machines by default

We don't want Jenkins attemptying to manage test VMs.  I thought of
various ways to exclude them, but in the end, I think a simple name
match will work fine.

The host provisioner _should_ manage test VMs, though, so it will need
to be configured to set the `PYROCUFFLINK_EXCLUDE_TEST` environment
variable to `false` to override the default behavior.
unifi-restore
Dustin 2025-02-14 10:04:48 -06:00
parent 6ae3404b3a
commit 9ea8756610
1 changed files with 18 additions and 0 deletions

View File

@ -44,6 +44,12 @@ options:
description: Exclude domains running specified operating systems description: Exclude domains running specified operating systems
type: list type: list
default: [] default: []
exclude_test:
description: Exclude domains whose name implies they are testing machines
type: boolean
default: true
env:
- name: PYROCUFFLINK_EXCLUDE_TEST
log_excluded: log_excluded:
description: description:
Print a log message about excluded domains, useful for troubleshooting Print a log message about excluded domains, useful for troubleshooting
@ -90,6 +96,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
dns_domain = self.get_option('dns_domain') dns_domain = self.get_option('dns_domain')
exclude_off = cast(bool, self.get_option('exclude_off')) exclude_off = cast(bool, self.get_option('exclude_off'))
exclude_os = cast(list[str], self.get_option('exclude_os')) exclude_os = cast(list[str], self.get_option('exclude_os'))
exclude_test = cast(list[str], self.get_option('exclude_test'))
log_excluded = cast(bool, self.get_option('log_excluded')) log_excluded = cast(bool, self.get_option('log_excluded'))
assert self.inventory assert self.inventory
@ -117,6 +124,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
host.os_id, host.os_id,
) )
continue continue
if exclude_test and host.is_test_host:
if log_excluded:
log.warning(
'Excluding libvirt domain %s (test machine)',
host.name,
)
continue
if host.title: if host.title:
inventory_hostname = host.title inventory_hostname = host.title
else: else:
@ -154,6 +168,10 @@ class Host:
def groups(self) -> list[str]: def groups(self) -> list[str]:
return list(self._groups()) return list(self._groups())
@functools.cached_property
def is_test_host(self) -> bool:
return self.name.startswith('test-')
@functools.cached_property @functools.cached_property
def libosinfo(self) -> Optional[etree.Element]: def libosinfo(self) -> Optional[etree.Element]:
try: try: