From e45613ce8cf70ca5bbe5ef2a0b2ce9bac090a776 Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 5 Oct 2016 17:38:22 +0300 Subject: [PATCH] Change method of getting PIDs of running processes Change-Id: I669cd6f4fd52d04de9ed6087719e8910d570505e --- stacklight_tests/helpers/remote_ops.py | 13 +++++++------ stacklight_tests/lma_collector/api.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/stacklight_tests/helpers/remote_ops.py b/stacklight_tests/helpers/remote_ops.py index f170604..bfc1ea1 100644 --- a/stacklight_tests/helpers/remote_ops.py +++ b/stacklight_tests/helpers/remote_ops.py @@ -66,17 +66,18 @@ def simulate_network_interrupt_on_node(remote, interval=30): remote.execute(cmd) -def get_pids_of_process(remote, name): - """Get PIDs of process by its name. +def get_pids_of_process(remote, cmd_pattern): + """Get PIDS of process by its pattern. :param remote: SSH connection to the node. :type remote: SSHClient - :param name: process name. - :type name: str - :returns: list of PIDs. + :param cmd_pattern: command. + :type cmd_pattern: str + :returns: list of PIDS. :rtype: list """ - cmd = "pidof {}".format(name) + + cmd = "pgrep -f '{}'".format(cmd_pattern) result = remote.execute(cmd) if result['exit_code'] != 0: return [] diff --git a/stacklight_tests/lma_collector/api.py b/stacklight_tests/lma_collector/api.py index 8c6173f..9207b0a 100644 --- a/stacklight_tests/lma_collector/api.py +++ b/stacklight_tests/lma_collector/api.py @@ -37,18 +37,22 @@ class LMACollectorPluginApi(base_test.PluginApi): :returns: list of process IDs indexed by node and process :rtype: dict """ + services = ["metric_collector", "log_collector"] + service_version_9 = ["lma_collector"] pids = {} processes_count = { - "collectd": 1, - "collectdmon": 1 + "collectd ": 1, + "collectdmon ": 1 } if self.settings.version.startswith("0.9"): - processes_count["hekad"] = 1 + processes_count[ + "hekad -config[= ]/etc/{}".format(service_version_9)] = 1 else: # Starting with 0.10, there are one collector for logs and one for # metrics - processes_count["hekad"] = 2 + for service in services: + processes_count["hekad -config[= ]/etc/{}".format(service)] = 1 online_nodes = [node for node in self.helpers.get_all_ready_nodes() if node["online"]] for node in online_nodes: