aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2019-03-22 15:19:44 -0400
committerBryn M. Reeves <bmr@redhat.com>2019-09-24 15:07:13 +0100
commit2308f01de979a90fcfeed0d9ef799e82e76c392c (patch)
tree152de528e712a569d06babb1babe57a99866bf88
parenta895bf4096f1dbd71c9dbd4defb47783f4ef9840 (diff)
downloadsos-2308f01de979a90fcfeed0d9ef799e82e76c392c.tar.gz
[InitSystem] Cache service status information
With the addition of predicates, there is the very real possibility that plugins can end up gating multiple add_cmd_output() or similar calls around the same predicate, such as service enablement. Previously, this meant every single check of the predicate resulted in a new InitSystem._query_service() call was made. Now, we only call _query_service() once and save the results, since status is unlikely to change during the course of plugin execution. Resolves: #1629 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/__init__.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 07e07970..bd9ea4b1 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -124,17 +124,22 @@ class InitSystem(object):
"""Returns the status for the given service name along with the output
of the query command
"""
+ _default = {
+ 'name': name,
+ 'status': 'missing',
+ 'output': ''
+ }
+ if name not in self.services:
+ return _default
+ if 'status' in self.services[name]:
+ # service status has been queried before, return existing info
+ return self.services[name]
svc = self._query_service(name)
if svc is not None:
- return {'name': name,
- 'status': self.parse_query(svc['output']),
- 'output': svc['output']
- }
- else:
- return {'name': name,
- 'status': 'missing',
- 'output': ''
- }
+ self.services[name]['status'] = self.parse_query(svc['output'])
+ self.services[name]['output'] = svc['output']
+ return self.services[name]
+ return _default
class SystemdInit(InitSystem):