本文整理汇总了Python中mongo_orchestration.replica_sets.ReplicaSet类的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet类的具体用法?Python ReplicaSet怎么用?Python ReplicaSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReplicaSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_member_id_to_host
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)
示例2: test_host2id
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']))
示例3: test_len
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']))
示例4: test_member_del_no_reconfig
def test_member_del_no_reconfig(self):
self.repl_cfg = {'members': [{}, {}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
m_count = len(self.repl.config['members'])
self.assertTrue(self.repl.member_del(2, reconfig=False))
self.assertEqual(len(self.repl.config['members']), m_count)
self.repl.server_map.pop(2)
示例5: test_scram_with_ssl
def test_scram_with_ssl(self):
member_params = {'procParams': {'clusterAuthMode': 'x509'}}
self.repl_cfg = {
'login': 'luke',
'password': 'ekul',
'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)
# 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'])
示例6: test_member_info_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)
示例7: test_wait_while_reachable
def test_wait_while_reachable(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
servers = [member['host'] for member in self.repl.members()]
self.assertTrue(self.repl.wait_while_reachable(servers, timeout=10))
self.repl.member_command(1, 'stop')
self.assertFalse(self.repl.wait_while_reachable(servers, timeout=10))
示例8: test_mongodb_auth_uri
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)
示例9: test_repl_member_add
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'])
示例10: test_member_update
def test_member_update(self):
self.repl = ReplicaSet(self.repl_cfg)
member = [item for item in self.repl.config['members'] if item['_id'] == 2][0]
self.assertTrue(member.get('hidden', False))
self.assertTrue(self.repl.member_update(2, {"rsParams": {"priority": 1, "hidden": False}}))
member = [item for item in self.repl.config['members'] if item['_id'] == 2][0]
self.assertFalse(member.get('hidden', False))
示例11: test_member_info
def test_member_info(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
member = [item for item in self.repl.config['members'] if item['_id'] == 1][0]
result = self.repl.member_info(1)
self.assertTrue(result['procInfo']['alive'])
self.assertIn(member['host'], result['mongodb_uri'])
self.assertTrue(len(result['rsInfo']) > 0)
示例12: test_run_command
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)
示例13: test_repl_update
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'])
示例14: test_connection
def test_connection(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
_id = 1
hostname = self.repl.member_id_to_host(_id)
self.assertTrue(self.repl.connection(timeout=5))
self.assertTrue(self.repl.connection(hostname=hostname, timeout=5))
self.repl.member_command(_id, 'stop')
self.assertRaises(pymongo.errors.AutoReconnect, lambda: self.repl.connection(hostname=hostname, timeout=5))
示例15: test_members
def test_members(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
members1 = sorted(self.repl.config['members'], key=lambda item: item['_id'])
members2 = sorted(self.repl.members(), key=lambda item: item['_id'])
self.assertEqual(len(members1), len(members2))
for i in range(len(members1)):
self.assertEqual(members1[i]['host'], members2[i]['host'])
self.assertEqual(members1[i]['_id'], members2[i]['_id'])