[stable-2.19] service_facts: Handle KeyError while processing service name (#85572) (#85647)

* service_facts: Handle KeyError while processing service name

As a part of follow up review,

* Handle KeyError with exception handling
* Warn user about the missing service name in the given service details
(cherry picked from commit 9ed7164)

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
pull/85697/head
Abhijeet Kasurde 4 months ago committed by GitHub
parent 8d26bbf3f7
commit 8849bd776b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,4 @@
---
minor_changes:
- service_facts - warn user about missing service details instead of ignoring.
- service_facts - handle keyerror exceptions with warning.

@ -232,7 +232,11 @@ class ServiceScanService(BaseService):
if service_name == "*":
continue
service_state = line_data[1]
try:
service_runlevels = all_services_runlevels[service_name]
except KeyError:
self.module.warn(f"Service {service_name} not found in the service list")
continue
service_data = {"name": service_name, "runlevels": service_runlevels, "state": service_state, "source": "openrc"}
services[service_name] = service_data

Loading…
Cancel
Save