From 572a39889ca08edfcbaad1cdb371ad2cb116de9a Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 13 Apr 2017 11:22:21 -0600 Subject: [PATCH] DaemonState: factor out command generation Signed-off-by: Zack Cerza --- teuthology/orchestra/daemon.py | 48 ++++++++++++++-------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/teuthology/orchestra/daemon.py b/teuthology/orchestra/daemon.py index 045b54d9b0..1f1ffa7baf 100644 --- a/teuthology/orchestra/daemon.py +++ b/teuthology/orchestra/daemon.py @@ -8,21 +8,20 @@ from teuthology.exceptions import CommandFailedError log = logging.getLogger(__name__) -start_mon_cmd = 'sudo systemctl start ceph-mon@' -stop_mon_cmd = 'sudo systemctl stop ceph-mon@' -restart_mon_cmd = 'sudo systemctl restart ceph-mon@' +systemd_cmd_templ = 'sudo systemctl {action} {daemon}@{id_}' -start_osd_cmd = 'sudo systemctl start ceph-osd@' -stop_osd_cmd = 'sudo systemctl stop ceph-osd@' -restart_osd_cmd = 'sudo systemctl restart ceph-osd@' -start_mds_cmd = 'sudo systemctl start ceph-mds@' -stop_mds_cmd = 'sudo systemctl stop ceph-mds@' -restart_mds_cmd = 'sudo systemctl restart ceph-mds@' - -start_rgw_cmd = 'sudo systemctl start ceph-radosgw@rgw.' -stop_rgw_cmd = 'sudo systemctl stop ceph-radosgw@rgw.' -restart_rgw_cmd = 'sudo systemctl restart ceph-radosgw@rgw.' +def get_systemd_cmd(action, daemon, id_): + if daemon == 'rgw': + daemon = 'radosgw' + id_ = 'rgw.%s' % id_ + daemon = 'ceph-%s' % daemon + cmd = systemd_cmd_templ.format( + action=action, + daemon=daemon, + id_=id_, + ) + return cmd class DaemonState(object): @@ -43,6 +42,7 @@ class DaemonState(object): self.command_args = command_args self.command_kwargs = command_kwargs self.role = role + self.type_ = self.role.split('.')[-1] self.id_ = id_ self.use_init = use_init if self.use_init: @@ -63,25 +63,15 @@ class DaemonState(object): 'awk', run.Raw("{'print $2'}")] self.proc_id = None - if (role == 'mon'): - self.start_cmd = start_mon_cmd + self.id - self.stop_cmd = stop_mon_cmd + self.id - self.restart_cmd = restart_mon_cmd + self.id - elif (role == 'osd'): - self.start_cmd = start_osd_cmd + self.id - self.stop_cmd = stop_osd_cmd + self.id - self.restart_cmd = restart_osd_cmd + self.id - elif (role == 'rgw'): - self.start_cmd = start_rgw_cmd + self.id - self.stop_cmd = stop_rgw_cmd + self.id - self. restart_cmd = restart_rgw_cmd + self.id - elif (role == 'mds'): - self.start_cmd = start_mds_cmd + self.id - self.stop_cmd = stop_mds_cmd + self.id - self.restart_cmd = restart_mds_cmd + self.id + self._set_commands() self.log = command_kwargs.get('logger', log) self.proc = None + def _set_commands(self): + self.start_cmd = get_systemd_cmd('start', self.type_, self.id_) + self.stop_cmd = get_systemd_cmd('stop', self.type_, self.id_) + self.restart_cmd = get_systemd_cmd('restart', self.type_, self.id_) + def stop(self, timeout=300): """ Stop this daemon instance. -- 2.39.5