]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
orchestra/daemon/systemd: fix proc_regex in pid() method 1518/head
authorsunilkumarn417 <sunnagar@redhat.com>
Fri, 19 Jun 2020 08:14:54 +0000 (13:44 +0530)
committersunilkumarn417 <sunnagar@redhat.com>
Wed, 24 Jun 2020 14:14:40 +0000 (19:44 +0530)
Signed-off-by: sunilkumarn417 <sunnagar@redhat.com>
teuthology/orchestra/daemon/systemd.py
teuthology/orchestra/test/files/daemon-systemdstate-pid-ps-ef.output [new file with mode: 0644]
teuthology/orchestra/test/test_systemd.py [new file with mode: 0644]

index c202669fbe2be63c836d1ab581eca909359b0969..d7069a6489aca174e57cfc3591f4c6e240d073d6 100644 (file)
@@ -106,7 +106,7 @@ class SystemDState(DaemonState):
         # process regex to match RADOSGW process command string
         # eg. "/usr/bin/radosgw -f --cluster ceph --name <daemon-id=self.id_>"
         if self.type_ == "rgw":
-            proc_regex = "{}.* --name .*{}".format(self.daemon_type, self.id_)
+            proc_regex = '"{}.*--name.*{}"'.format(self.daemon_type, self.id_)
 
         args = ['ps', '-ef',
                 run.Raw('|'),
diff --git a/teuthology/orchestra/test/files/daemon-systemdstate-pid-ps-ef.output b/teuthology/orchestra/test/files/daemon-systemdstate-pid-ps-ef.output
new file mode 100644 (file)
index 0000000..ddddf57
--- /dev/null
@@ -0,0 +1,5 @@
+ceph       658     1  0 Jun08 ?        00:07:43 /usr/bin/ceph-mgr -f --cluster ceph --id host1 --setuser ceph --setgroup ceph
+ceph      1634     1  0 Jun08 ?        00:02:17 /usr/bin/ceph-mds -f --cluster ceph --id host1 --setuser ceph --setgroup ceph
+ceph     31555     1  0 Jun08 ?        01:13:50 /usr/bin/ceph-mon -f --cluster ceph --id host1 --setuser ceph --setgroup ceph
+ceph     31765     1  0 Jun08 ?        00:48:42 /usr/bin/radosgw -f --cluster ceph --name client.rgw.host1.rgw0 --setuser ceph --setgroup ceph
+ceph     97427     1  0 Jun17 ?        00:41:39 /usr/bin/ceph-osd -f --cluster ceph --id 0 --setuser ceph --setgroup ceph
\ No newline at end of file
diff --git a/teuthology/orchestra/test/test_systemd.py b/teuthology/orchestra/test/test_systemd.py
new file mode 100644 (file)
index 0000000..c7cb342
--- /dev/null
@@ -0,0 +1,54 @@
+import argparse
+import os
+
+from logging import debug
+from teuthology import misc
+from teuthology.orchestra import cluster
+from teuthology.orchestra.run import quote
+from teuthology.orchestra.daemon.group import DaemonGroup
+import subprocess
+
+
+class FakeRemote(object):
+    pass
+
+
+def test_pid():
+    ctx = argparse.Namespace()
+    ctx.daemons = DaemonGroup(use_systemd=True)
+    remote = FakeRemote()
+
+    ps_ef_output_path = os.path.join(
+        os.path.dirname(__file__),
+        "files/daemon-systemdstate-pid-ps-ef.output"
+    )
+
+    # patching ps -ef command output using a file
+    def sh(args):
+        args[0:2] = ["cat", ps_ef_output_path]
+        debug(args)
+        return subprocess.getoutput(quote(args))
+
+    remote.sh = sh
+    remote.init_system = 'systemd'
+    remote.shortname = 'host1'
+
+    ctx.cluster = cluster.Cluster(
+        remotes=[
+            (remote, ['rgw.0', 'mon.a', 'mgr.a', 'mds.a', 'osd.0'])
+        ],
+    )
+
+    for remote, roles in ctx.cluster.remotes.items():
+        for role in roles:
+            _, rol, id_ = misc.split_role(role)
+            if any(rol.startswith(x) for x in ['mon', 'mgr', 'mds']):
+                ctx.daemons.register_daemon(remote, rol, remote.shortname)
+            else:
+                ctx.daemons.register_daemon(remote, rol, id_)
+
+    for _, daemons in ctx.daemons.daemons.items():
+        for daemon in daemons.values():
+            pid = daemon.pid
+            debug(pid)
+            assert pid