def setup(self): self.r1 = remote.Remote('r1', ssh=Mock()) self.c = cluster.Cluster( remotes=[ (self.r1, ['foo', 'bar']), ], )
def main(): if len(sys.argv) == 3: user = sys.argv[1] + "@" host = sys.argv[2] elif len(sys.argv) == 2: user = "" host = sys.argv[1] else: sys.stderr.write("usage: radosgw_admin.py [user] host\n") exit(1) client0 = remote.Remote(user + host) ctx = config ctx.cluster=cluster.Cluster(remotes=[(client0, [ 'ceph.client.rgw.%s' % (host), ]),]) ctx.rgw = argparse.Namespace() endpoints = {} endpoints['ceph.client.rgw.%s' % host] = (host, 80) ctx.rgw.role_endpoints = endpoints ctx.rgw.realm = None ctx.rgw.regions = {'region0': { 'api name': 'api1', 'is master': True, 'master zone': 'r0z0', 'zones': ['r0z0', 'r0z1'] }} ctx.rgw.config = {'ceph.client.rgw.%s' % host: {'system user': {'name': '%s-system-user' % host}}} task(config, None) exit()
def add_remotes(ctx, config): """ Create a ctx.cluster object populated with remotes mapped to roles """ ctx.cluster = cluster.Cluster() # Allow jobs to run without using nodes, for self-testing if 'roles' not in ctx.config and 'targets' not in ctx.config: return remotes = [] machs = [] for name in ctx.config['targets'].keys(): machs.append(name) for t, key in ctx.config['targets'].items(): t = misc.canonicalize_hostname(t) try: if ctx.config['sshkeys'] == 'ignore': key = None except (AttributeError, KeyError): pass rem = remote.Remote(name=t, host_key=key, keep_alive=True) remotes.append(rem) if 'roles' in ctx.config: for rem, roles in zip(remotes, ctx.config['roles']): assert all(isinstance(role, str) for role in roles), \ "Roles in config must be strings: %r" % roles ctx.cluster.add(rem, roles) log.info('roles: %s - %s' % (rem, roles)) else: for rem in remotes: ctx.cluster.add(rem, rem.name)
def test_str(self): r1 = remote.Remote('r1', ssh=Mock()) r2 = remote.Remote('r2', ssh=Mock()) c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) assert str(c) == "r1[foo,bar] r2[baz]"
def test_repr(self): r1 = remote.Remote('r1', ssh=Mock()) r2 = remote.Remote('r2', ssh=Mock()) c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) assert repr(c) == \ "Cluster(remotes=[[Remote(name='r1'), ['foo', 'bar']], " \ "[Remote(name='r2'), ['baz']]])"
def test_exclude_match(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.exclude('foo', lambda role: role.startswith('b')) assert c_foo.remotes == {r2: ['bar'], r3: ['foo']}
def test_exclude_none(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_none = c.exclude('impossible') assert c_none.remotes == {r1: ['foo', 'bar'], r2: ['bar'], r3: ['foo']}
def test_exclude_two(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_both = c.exclude('foo', 'bar') assert c_both.remotes == {r2: ['bar'], r3: ['foo']}
def test_exclude_one(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.exclude('foo') assert c_foo.remotes == {r2: ['bar']}
def test_only_match(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.only('foo', lambda role: role.startswith('b')) assert c_foo.remotes, {r1: ['foo' == 'bar']}
def test_only_none(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_none = c.only('impossible') assert c_none.remotes == {}
def test_str(self): fudge.clear_expectations() r1 = remote.Remote('r1', ssh=fudge.Fake('SSH')) r2 = remote.Remote('r2', ssh=fudge.Fake('SSH')) c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) assert str(c) == "r1[foo,bar] r2[baz]"
def test_repr(self): fudge.clear_expectations() r1 = remote.Remote('r1', ssh=fudge.Fake('SSH')) r2 = remote.Remote('r2', ssh=fudge.Fake('SSH')) c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) assert repr(c) == "Cluster(remotes=[[Remote(name='r1'), ['foo', 'bar']], [Remote(name='r2'), ['baz']]])" # noqa
def test_only_two(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_both = c.only('foo', 'bar') assert c_both.remotes, {r1: ['foo' == 'bar']}
def test_only_one(self): r1 = Mock() r2 = Mock() r3 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.only('foo') assert c_foo.remotes == {r1: ['foo', 'bar'], r3: ['foo']}
def test_get_clients_simple(): ctx = argparse.Namespace() remote = FakeRemote() ctx.cluster = cluster.Cluster(remotes=[(remote, ['client.0', 'client.1'])], ) g = misc.get_clients(ctx=ctx, roles=['client.1']) got = next(g) assert len(got) == 2 assert got[0] == ('1') assert got[1] is remote with pytest.raises(StopIteration): next(g)
def test_filter(self): r1 = Mock(_name='r1') r2 = Mock(_name='r2') def func(r): return r._name == "r1" c = cluster.Cluster(remotes=[ (r1, ['foo']), (r2, ['bar']), ]) assert c.filter(func).remotes == {r1: ['foo']}
def test_exclude_two(self): fudge.clear_expectations() r1 = fudge.Fake('r1') r2 = fudge.Fake('r2') r3 = fudge.Fake('r3') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_both = c.exclude('foo', 'bar') assert c_both.remotes == {r2: ['bar'], r3: ['foo']}
def test_exclude_none(self): fudge.clear_expectations() r1 = fudge.Fake('r1') r2 = fudge.Fake('r2') r3 = fudge.Fake('r3') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_none = c.exclude('impossible') assert c_none.remotes == {r1: ['foo', 'bar'], r2: ['bar'], r3: ['foo']}
def test_exclude_match(self): fudge.clear_expectations() r1 = fudge.Fake('r1') r2 = fudge.Fake('r2') r3 = fudge.Fake('r3') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.exclude('foo', lambda role: role.startswith('b')) assert c_foo.remotes == {r2: ['bar'], r3: ['foo']}
def test_only_one(self): fudge.clear_expectations() r1 = fudge.Fake('r1') r2 = fudge.Fake('r2') r3 = fudge.Fake('r3') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_foo = c.only('foo') assert c_foo.remotes == {r1: ['foo', 'bar'], r3: ['foo']}
def test_only_two(self): fudge.clear_expectations() r1 = fudge.Fake('r1') r2 = fudge.Fake('r2') r3 = fudge.Fake('r3') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['bar']), (r3, ['foo']), ], ) c_both = c.only('foo', 'bar') assert c_both.remotes, {r1: ['foo' == 'bar']}
def test_init(self): r1 = Mock() r2 = Mock() c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) r3 = Mock() c.add(r3, ['xyzzy', 'thud', 'foo']) assert c.remotes == { r1: ['foo', 'bar'], r2: ['baz'], r3: ['xyzzy', 'thud', 'foo'], }
def test_wait_until_osds_up(): ctx = argparse.Namespace() ctx.daemons = Mock() ctx.daemons.iter_daemons_of_role.return_value = list() remote = FakeRemote() def s(self, **kwargs): return 'IGNORED\n{"osds":[{"state":["up"]}]}' remote.sh = s ctx.cluster = cluster.Cluster(remotes=[(remote, ['osd.0', 'client.1'])], ) with patch.multiple( misc, get_testdir=lambda ctx: "TESTDIR", ): misc.wait_until_osds_up(ctx, ctx.cluster, remote)
def test_init(self): fudge.clear_expectations() r1 = fudge.Fake('Remote') r2 = fudge.Fake('Remote') c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) r3 = fudge.Fake('Remote') c.add(r3, ['xyzzy', 'thud', 'foo']) assert c.remotes == { r1: ['foo', 'bar'], r2: ['baz'], r3: ['xyzzy', 'thud', 'foo'], }
def main(): parser = argparse.ArgumentParser() parser.add_argument('--uid') parser.add_argument('--host', required=True) parser.add_argument('--port', type=int) args = parser.parse_args() host = args.host if args.port: port = args.port else: port = 80 client0 = tasks.vstart_runner.LocalRemote() ctx = config ctx.cluster = cluster.Cluster(remotes=[ (client0, [ 'ceph.client.rgw.%s' % (port), ]), ]) ctx.rgw = argparse.Namespace() endpoints = {} endpoints['ceph.client.rgw.%s' % port] = RGWEndpoint(hostname=host, port=port) ctx.rgw.role_endpoints = endpoints ctx.rgw.realm = None ctx.rgw.regions = { 'region0': { 'api name': 'api1', 'is master': True, 'master zone': 'r0z0', 'zones': ['r0z0', 'r0z1'] } } ctx.rgw.omit_sudo = True ctx.rgw.omit_tdir = True ctx.rgw.config = { 'ceph.client.rgw.%s' % port: { 'system user': { 'name': '%s-system-user' % port } } } task(config, None) exit()
def test_run_all(self): fudge.clear_expectations() r1 = fudge.Fake('Remote').has_attr(name='r1') ret1 = fudge.Fake('RemoteProcess') r1.expects('run').with_args(args=['test']).returns(ret1) r2 = fudge.Fake('Remote').has_attr(name='r2') ret2 = fudge.Fake('RemoteProcess') r2.expects('run').with_args(args=['test']).returns(ret2) c = cluster.Cluster( remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) got = c.run(args=['test']) assert len(got) == 2 assert got, [ret1 == ret2] # check identity not equality assert got[0] is ret1 assert got[1] is ret2
def test_run_all(self): r1 = Mock(spec=remote.Remote) r1.configure_mock(name='r1') ret1 = Mock(spec=run.RemoteProcess) r1.run.return_value = ret1 r2 = Mock(spec=remote.Remote) r2.configure_mock(name='r2') ret2 = Mock(spec=run.RemoteProcess) r2.run.return_value = ret2 c = cluster.Cluster(remotes=[ (r1, ['foo', 'bar']), (r2, ['baz']), ], ) assert r1.run.called_once_with(args=['test']) assert r2.run.called_once_with(args=['test']) got = c.run(args=['test']) assert len(got) == 2 assert got, [ret1 == ret2] # check identity not equality assert got[0] is ret1 assert got[1] is ret2
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
def test_init_empty(self): fudge.clear_expectations() c = cluster.Cluster() assert c.remotes == {}