From 9ea875661052d7dde014db06b941c947cea52dde Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 14 Feb 2025 10:04:48 -0600 Subject: [PATCH] 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. --- plugins/inventory/pyrocufflink.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/inventory/pyrocufflink.py b/plugins/inventory/pyrocufflink.py index 26b778a..82b62f9 100644 --- a/plugins/inventory/pyrocufflink.py +++ b/plugins/inventory/pyrocufflink.py @@ -44,6 +44,12 @@ options: description: Exclude domains running specified operating systems type: list default: [] + exclude_test: + description: Exclude domains whose name implies they are testing machines + type: boolean + default: true + env: + - name: PYROCUFFLINK_EXCLUDE_TEST log_excluded: description: 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') exclude_off = cast(bool, self.get_option('exclude_off')) 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')) assert self.inventory @@ -117,6 +124,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable): host.os_id, ) 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: inventory_hostname = host.title else: @@ -154,6 +168,10 @@ class Host: def groups(self) -> list[str]: return list(self._groups()) + @functools.cached_property + def is_test_host(self) -> bool: + return self.name.startswith('test-') + @functools.cached_property def libosinfo(self) -> Optional[etree.Element]: try: