本文整理汇总了Python中mongo_orchestration.replica_sets.ReplicaSet.info方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet.info方法的具体用法?Python ReplicaSet.info怎么用?Python ReplicaSet.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_orchestration.replica_sets.ReplicaSet
的用法示例。
在下文中一共展示了ReplicaSet.info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReplicaSetSSLTestCase
# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import info [as 别名]
#.........这里部分代码省略.........
# Should not raise an Exception.
self.repl = ReplicaSet(self.repl_cfg)
# Should create the user we requested. No raise on authenticate.
client = pymongo.MongoClient(
self.repl.primary(), ssl_certfile=certificate('client.pem'),
ssl_cert_reqs=ssl.CERT_NONE)
client.admin.authenticate('luke', 'ekul')
# This should be the only user.
self.assertEqual(len(client.admin.command('usersInfo')['users']), 1)
self.assertFalse(client['$external'].command('usersInfo')['users'])
def test_ssl(self):
member_params = {}
self.repl_cfg = {
'members': [member_params, member_params],
'sslParams': {
'sslCAFile': certificate('ca.pem'),
'sslPEMKeyFile': certificate('server.pem'),
'sslMode': 'requireSSL',
'sslClusterFile': certificate('cluster_cert.pem'),
'sslAllowInvalidCertificates': True
}
}
# Should not raise an Exception.
self.repl = ReplicaSet(self.repl_cfg)
# Server should require SSL.
with self.assertRaises(pymongo.errors.ConnectionFailure):
connected(pymongo.MongoClient(self.repl.primary()))
# This shouldn't raise.
connected(pymongo.MongoClient(
self.repl.primary(), ssl_certfile=certificate('client.pem'),
ssl_cert_reqs=ssl.CERT_NONE))
def test_mongodb_auth_uri(self):
if SERVER_VERSION < (2, 4):
raise SkipTest("Need to be able to set 'authenticationMechanisms' "
"parameter to test.")
member_params = {
'procParams': {
'clusterAuthMode': 'x509',
'setParameter': {'authenticationMechanisms': 'MONGODB-X509'}
}
}
self.repl_cfg = {
'login': TEST_SUBJECT,
'authSource': '$external',
'members': [member_params, member_params],
'sslParams': {
'sslCAFile': certificate('ca.pem'),
'sslPEMKeyFile': certificate('server.pem'),
'sslMode': 'requireSSL',
'sslClusterFile': certificate('cluster_cert.pem'),
'sslAllowInvalidCertificates': True
}
}
self.repl = ReplicaSet(self.repl_cfg)
self.assertIn('mongodb_auth_uri', self.repl.info())
repl_auth_uri = self.repl.info()['mongodb_auth_uri']
hosts = ','.join(m['host'] for m in self.repl.members())
self.assertIn(hosts, repl_auth_uri)
self.assertIn(TEST_SUBJECT, repl_auth_uri)
self.assertIn('authSource=$external', repl_auth_uri)
self.assertIn('authMechanism=MONGODB-X509', repl_auth_uri)
replset_param = 'replicaSet=' + self.repl.repl_id
self.assertIn(replset_param, repl_auth_uri)
def test_member_info_auth_uri(self):
member_params = {
'procParams': {
'clusterAuthMode': 'x509',
'setParameter': {'authenticationMechanisms': 'MONGODB-X509'}
}
}
self.repl_cfg = {
'login': TEST_SUBJECT,
'authSource': '$external',
'members': [member_params, member_params],
'sslParams': {
'sslCAFile': certificate('ca.pem'),
'sslPEMKeyFile': certificate('server.pem'),
'sslMode': 'requireSSL',
'sslClusterFile': certificate('cluster_cert.pem'),
'sslAllowInvalidCertificates': True
}
}
self.repl = ReplicaSet(self.repl_cfg)
for i in range(len(self.repl)):
member = self.repl.member_info(i)
self.assertIn('mongodb_auth_uri', member)
uri = member['mongodb_auth_uri']
host = Servers().hostname(member['server_id'])
self.assertIn(host, uri)
self.assertIn(TEST_SUBJECT, uri)
self.assertIn('authSource=$external', uri)
self.assertIn('authMechanism=MONGODB-X509', uri)
示例2: ReplicaSetAuthTestCase
# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import info [as 别名]
class ReplicaSetAuthTestCase(unittest.TestCase):
def setUp(self):
PortPool().change_range()
self.servers = Servers()
self.servers.set_settings(*TEST_RELEASES)
self.repl_cfg = {'auth_key': 'secret', 'login': 'admin', 'password': 'admin', 'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
def tearDown(self):
if len(self.repl) > 0:
self.repl.cleanup()
def test_auth_connection(self):
self.assertTrue(isinstance(self.repl.connection().admin.collection_names(), list))
c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
def test_auth_admin(self):
c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
self.assertTrue(c.admin.authenticate('admin', 'admin'))
self.assertTrue(isinstance(c.admin.collection_names(), list))
self.assertTrue(c.admin.logout() is None)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
def test_auth_collection(self):
c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
self.assertTrue(c.admin.authenticate('admin', 'admin'))
db = c.test_auth
db.add_user('user', 'userpass', roles=['readWrite'])
c.admin.logout()
self.assertTrue(db.authenticate('user', 'userpass'))
self.assertTrue(db.foo.insert({'foo': 'bar'}, w=2, wtimeout=10000))
self.assertTrue(isinstance(db.foo.find_one(), dict))
db.logout()
self.assertRaises(pymongo.errors.OperationFailure, db.foo.find_one)
def test_auth_arbiter_member_info(self):
self.repl.cleanup()
self.repl = ReplicaSet({'members': [
{}, {'rsParams': {'arbiterOnly': True}}]})
info = self.repl.member_info(1)
for key in ('procInfo', 'mongodb_uri', 'statuses', 'rsInfo'):
self.assertIn(key, info)
rs_info = info['rsInfo']
for key in ('primary', 'secondary', 'arbiterOnly'):
self.assertIn(key, rs_info)
self.assertFalse(rs_info['primary'])
self.assertFalse(rs_info['secondary'])
self.assertTrue(rs_info['arbiterOnly'])
def test_mongodb_auth_uri(self):
self.assertIn('mongodb_auth_uri', self.repl.info())
rs_auth_uri = self.repl.info()['mongodb_auth_uri']
hosts = ','.join(m['host'] for m in self.repl.members())
self.assertIn(hosts, rs_auth_uri)
self.assertIn('admin:admin', rs_auth_uri)
self.assertIn('authSource=admin', rs_auth_uri)
replset_param = 'replicaSet=' + self.repl.repl_id
self.assertIn(replset_param, rs_auth_uri)
def test_member_info_auth_uri(self):
for i in range(len(self.repl)):
member = self.repl.member_info(i)
self.assertIn('mongodb_auth_uri', member)
uri = member['mongodb_auth_uri']
host = Servers().hostname(member['server_id'])
self.assertIn(host, uri)
self.assertIn('admin:admin', uri)
self.assertIn('authSource=admin', uri)
示例3: ReplicaSetTestCase
# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import info [as 别名]
class ReplicaSetTestCase(unittest.TestCase):
def setUp(self):
PortPool().change_range()
self.servers = Servers()
self.servers.set_settings(*TEST_RELEASES)
self.repl_cfg = {'members': [{}, {}, {'rsParams': {'priority': 0, 'hidden': True}}, {'rsParams': {'arbiterOnly': True}}]}
# self.repl = ReplicaSet(self.repl_cfg)
def tearDown(self):
if hasattr(self, 'repl'):
self.repl.cleanup()
def test_len(self):
self.repl = ReplicaSet(self.repl_cfg)
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']))
self.repl.member_del(3)
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']) - 1)
self.repl.repl_member_add({'rsParams': {'arbiterOnly': True}})
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']))
def test_cleanup(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']))
self.repl.cleanup()
self.assertTrue(len(self.repl) == 0)
def test_member_id_to_host(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
members = self.repl.config['members']
for member in members:
host = self.repl.member_id_to_host(member['_id'])
self.assertEqual(member['host'], host)
def test_host2id(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
members = self.repl.config['members']
for member in members:
self.assertEqual(member['_id'],
self.repl.host2id(member['host']))
def test_update_server_map(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
origin = self.repl.server_map.copy()
self.repl.update_server_map(self.repl.config)
self.assertEqual(self.repl.server_map, origin)
def test_repl_update(self):
self.repl_cfg = {'members': [{}, {}, {'rsParams': {'priority': 0, 'hidden': True}}]}
self.repl = ReplicaSet(self.repl_cfg)
config = self.repl.config
config['members'][1]['priority'] = 0
config['members'][1]['hidden'] = True
self.assertTrue(self.repl.repl_update(config))
self.assertTrue(self.repl.config['members'][1]['hidden'])
def test_info(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
cfg = self.repl.config
info = self.repl.info()
self.assertEqual(info['auth_key'], self.repl.auth_key)
self.assertEqual(info['id'], self.repl.repl_id)
self.assertEqual(len(info['members']), len(cfg['members']))
members1 = sorted(cfg['members'], key=lambda item: item['_id'])
members2 = sorted(info['members'], key=lambda item: item['_id'])
for i in range(len(members1)):
self.assertEqual(members1[i]['_id'], members2[i]['_id'])
self.assertEqual(members1[i]['host'], members2[i]['host'])
def test_repl_member_add(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
member_id = self.repl.repl_member_add({"rsParams": {"priority": 0, "hidden": True}})
self.assertTrue(member_id >= 0)
member = [item for item in self.repl.config['members'] if item['_id'] == member_id][0]
self.assertTrue(member['hidden'])
def test_run_command(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
self.assertEqual(self.repl.run_command("rs.status()", is_eval=True)['ok'], 1)
result = self.repl.run_command('serverStatus', arg=None, is_eval=False, member_id=0)['repl']
for key in ('me', 'ismaster', 'setName', 'primary', 'hosts'):
self.assertTrue(key in result)
self.assertEqual(self.repl.run_command(command="replSetGetStatus", is_eval=False)['ok'], 1)
def test_config(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
config = self.repl.config
self.assertTrue('_id' in config)
self.assertTrue('members' in config)
def test_member_create(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
#.........这里部分代码省略.........