def test_initctl_version_says_something_else(self, monkeypatch): fake_conn = Mock() fake_conn.remote_module.grep = Mock(return_value=False) fake_conn.remote_module.which = Mock(return_value="/bin/initctl") fake_stdout = ([b"nosh", b"version", b"1.14"], [], 0) fake_check = Mock(return_value=fake_stdout) monkeypatch.setattr("ceph_deploy.util.system.remoto.process.check", lambda *a: fake_check()) result = system.is_upstart(fake_conn) assert result is False
def test_initctl_version_says_upstart(self, monkeypatch): fake_conn = Mock() fake_conn.remote_module.grep = Mock(return_value=False) fake_conn.remote_module.which = Mock(return_value='/bin/initctl') fake_stdout = (['init', '(upstart 1.12.1)'], [], 0) fake_check = Mock(return_value=fake_stdout) monkeypatch.setattr("ceph_deploy.util.system.remoto.process.check", lambda *a: fake_check()) result = system.is_upstart(fake_conn) assert result is True
def test_initctl_version_says_something_else(self, monkeypatch): fake_conn = Mock() fake_conn.remote_module.grep = Mock(return_value=False) fake_conn.remote_module.which = Mock(return_value='/bin/initctl') fake_stdout = (['nosh', 'version', '1.14'], [], 0) fake_check = Mock(return_value=fake_stdout) monkeypatch.setattr("ceph_deploy.util.system.remoto.process.check", lambda *a: fake_check()) result = system.is_upstart(fake_conn) assert result is False
def choose_init(module): """ Select a init system Returns the name of a init system (upstart, sysvinit ...). """ if is_systemd(module.conn) or module.conn.remote_module.path_exists( "/lib/systemd/system/ceph.target"): return 'systemd' if is_upstart(module.conn): return 'upstart' return 'sysvinit'
def choose_init(module): """ Select a init system Returns the name of a init system (upstart, sysvinit ...). """ # Upstart checks first because when installing ceph, the # `/lib/systemd/system/ceph.target` file may be created, fooling this # detection mechanism. if is_upstart(module.conn): return 'upstart' if is_systemd(module.conn) or module.conn.remote_module.path_exists( "/lib/systemd/system/ceph.target"): return 'systemd' return 'sysvinit'
def test_no_initctl(self): fake_conn = Mock() fake_conn.remote_module.grep = Mock(return_value=False) fake_conn.remote_module.which = Mock(return_value=None) result = system.is_upstart(fake_conn) assert result is False
def test_it_is_actually_systemd(self): fake_conn = Mock() fake_conn.remote_module.grep = Mock(return_value=True) result = system.is_upstart(fake_conn) assert result is False
def destroy_mon(conn, cluster, hostname): import datetime import time retries = 5 # mon的目录,比如/var/lib/ceph/mon/ceph-node1 path = paths.mon.path(cluster, hostname) if conn.remote_module.path_exists(path): # remove from cluster # 从集群中删除mon remoto.process.run( conn, [ 'ceph', '--cluster={cluster}'.format(cluster=cluster), '-n', 'mon.', '-k', '{path}/keyring'.format(path=path), 'mon', 'remove', hostname, ], timeout=7, ) # stop if conn.remote_module.path_exists(os.path.join(path, 'upstart')) or system.is_upstart(conn): status_args = [ 'initctl', 'status', 'ceph-mon', 'cluster={cluster}'.format(cluster=cluster), 'id={hostname}'.format(hostname=hostname), ] elif conn.remote_module.path_exists(os.path.join(path, 'sysvinit')): status_args = [ 'service', 'ceph', 'status', 'mon.{hostname}'.format(hostname=hostname), ] elif system.is_systemd(conn): # 停止mon服务 status_args = [ 'systemctl', 'stop', 'ceph-mon@{hostname}.service'.format(hostname=hostname), ] else: raise RuntimeError('could not detect a supported init system, cannot continue') while retries: conn.logger.info('polling the daemon to verify it stopped') if is_running(conn, status_args): time.sleep(5) retries -= 1 if retries <= 0: raise RuntimeError('ceph-mon deamon did not stop') else: break # archive old monitor directory fn = '{cluster}-{hostname}-{stamp}'.format( hostname=hostname, cluster=cluster, stamp=datetime.datetime.utcnow().strftime("%Y-%m-%dZ%H:%M:%S"), ) # 创建/var/lib/ceph/mon-removed目录 remoto.process.run( conn, [ 'mkdir', '-p', '/var/lib/ceph/mon-removed', ], ) # 将mon数据文件移动到/var/lib/ceph/mon-removed目录归档文件 conn.remote_module.make_mon_removed_dir(path, fn)
def destroy_mon(conn, cluster, hostname): import datetime import time retries = 5 path = paths.mon.path(cluster, hostname) if conn.remote_module.path_exists(path): # remove from cluster remoto.process.run( conn, [ 'ceph', '--cluster={cluster}'.format(cluster=cluster), '-n', 'mon.', '-k', '{path}/keyring'.format(path=path), 'mon', 'remove', hostname, ], timeout=7, ) # stop if conn.remote_module.path_exists(os.path.join(path, 'upstart')) or system.is_upstart(conn): status_args = [ 'initctl', 'status', 'ceph-mon', 'cluster={cluster}'.format(cluster=cluster), 'id={hostname}'.format(hostname=hostname), ] elif conn.remote_module.path_exists(os.path.join(path, 'sysvinit')): status_args = [ 'service', 'ceph', 'status', 'mon.{hostname}'.format(hostname=hostname), ] elif system.is_systemd(conn): status_args = [ 'systemctl', 'stop', 'ceph-mon@{hostname}.service'.format(hostname=hostname), ] else: raise RuntimeError('could not detect a supported init system, cannot continue') while retries: conn.logger.info('polling the daemon to verify it stopped') if is_running(conn, status_args): time.sleep(5) retries -= 1 if retries <= 0: raise RuntimeError('ceph-mon deamon did not stop') else: break # archive old monitor directory fn = '{cluster}-{hostname}-{stamp}'.format( hostname=hostname, cluster=cluster, stamp=datetime.datetime.utcnow().strftime("%Y-%m-%dZ%H:%M:%S"), ) remoto.process.run( conn, [ 'mkdir', '-p', '/var/lib/ceph/mon-removed', ], ) conn.remote_module.make_mon_removed_dir(path, fn)