本文整理汇总了Python中mongo_orchestration.sharded_clusters.ShardedCluster.reset方法的典型用法代码示例。如果您正苦于以下问题:Python ShardedCluster.reset方法的具体用法?Python ShardedCluster.reset怎么用?Python ShardedCluster.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_orchestration.sharded_clusters.ShardedCluster
的用法示例。
在下文中一共展示了ShardedCluster.reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ShardTestCase
# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import reset [as 别名]
#.........这里部分代码省略.........
result = self.sh.member_remove('sh-rs-01')
self.assertEqual(result['state'], 'completed')
self.assertEqual(len(self.sh.members), 1)
self.assertEqual(result['shard'], 'sh-rs-01')
self.sh.cleanup()
def test_info(self):
config = {
'configsvrs': [{}, {}, {}],
'routers': [{}, {}, {}],
'shards': [{}, {}]
}
self.sh = ShardedCluster(config)
info = self.sh.info()
self.assertTrue('shards' in info)
self.assertTrue('configsvrs' in info)
self.assertTrue('routers' in info)
self.assertEqual(len(info['shards']), 2)
self.assertEqual(len(info['configsvrs']), 3)
self.assertEqual(len(info['routers']), 3)
self.sh.cleanup()
def test_tagging(self):
if SERVER_VERSION < (2, 2, 0):
raise SkipTest("mongodb v{version} doesn't support shard tagging"
.format(version='.'.join(map(str, SERVER_VERSION))))
tags = ['tag1', 'tag2']
tags_repl = ['replTag']
config = {
'configsvrs': [{}], 'routers': [{}],
'shards': [{'id': 'sh01', 'shardParams': {'tags': tags}},
{'id': 'sh02'},
{'id': 'sh03', 'shardParams': {'tags': tags_repl, 'members': [{}, {}]}}
]
}
self.sh = ShardedCluster(config)
self.assertEqual(tags, self.sh.member_info('sh01')['tags'])
self.assertEqual([], self.sh.member_info('sh02')['tags'])
self.assertEqual(tags_repl, self.sh.member_info('sh03')['tags'])
self.sh.cleanup()
def test_reset(self):
all_hosts = []
# Start a ShardedCluster with 1 router and 1 config server.
self.sh = ShardedCluster({})
# Add 1 Server shard and 1 ReplicaSet shard.
server_id = self.sh.member_add(params={})['_id']
all_hosts.append(Servers().hostname(server_id))
repl_id = self.sh.member_add(params={'members': [{}, {}, {}]})['_id']
# Shut down the standalone.
Servers().command(server_id, 'stop')
# Shut down each member of the replica set.
server_ids = [m['server_id'] for m in ReplicaSets().members(repl_id)]
for s_id in server_ids:
Servers().command(s_id, 'stop')
all_hosts.append(Servers().hostname(s_id))
# Shut down config server and router.
config_id = self.sh.configsvrs[0]['id']
print("config_id=%r" % config_id)
all_hosts.append(Servers().hostname(config_id))
router_id = self.sh.routers[0]['id']
print("router_id=%r" % router_id)
all_hosts.append(Servers().hostname(router_id))
Servers().command(config_id, 'stop')
Servers().command(router_id, 'stop')
# Reset the ShardedCluster.
self.sh.reset()
# Everything is up.
for host in all_hosts:
# No ConnectionFailure/AutoReconnect.
pymongo.MongoClient(host)
def test_mongodb_auth_uri(self):
self.sh = ShardedCluster({
'login': 'luke', 'password': 'ekul',
'routers': [{}, {}],
'shards': [{}]
})
self.assertIn('mongodb_auth_uri', self.sh.info())
auth_uri = self.sh.info()['mongodb_auth_uri']
hosts = ','.join(r['hostname'] for r in self.sh.routers)
self.assertIn(hosts, auth_uri)
self.assertIn('luke:ekul', auth_uri)
self.assertIn('authSource=admin', auth_uri)
def test_auth_key_without_login(self):
self.sh = ShardedCluster({
'auth_key': 'secret',
'routers': [{}],
'shards': [{}]
})
self.assertIsNotNone(self.sh.key_file)
示例2: ShardTestCase
# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import reset [as 别名]
#.........这里部分代码省略.........
config = {'shards': [{'id': 'member1'}, {'id': 'member2'}, {'id': 'sh-rs-01', 'shardParams': {'id': 'rs1', 'members': [{}, {}]}}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.members), 3)
# remove member-host
result = self.sh.member_remove('member1')
self.assertEqual(len(self.sh.members), 3)
self.assertEqual(result['state'], 'started')
self.assertEqual(result['shard'], 'member1')
time.sleep(5)
result = self.sh.member_remove('member1')
self.assertEqual(result['state'], 'completed')
self.assertEqual(len(self.sh.members), 2)
self.assertEqual(result['shard'], 'member1')
# remove member-replicaset
result = self.sh.member_remove('sh-rs-01')
self.assertEqual(len(self.sh.members), 2)
self.assertEqual(result['state'], 'started')
self.assertEqual(result['shard'], 'sh-rs-01')
time.sleep(7)
result = self.sh.member_remove('sh-rs-01')
self.assertEqual(result['state'], 'completed')
self.assertEqual(len(self.sh.members), 1)
self.assertEqual(result['shard'], 'sh-rs-01')
self.sh.cleanup()
def test_info(self):
config = {
'configsvrs': [{}, {}, {}],
'routers': [{}, {}, {}],
'shards': [{}, {}]
}
self.sh = ShardedCluster(config)
info = self.sh.info()
self.assertTrue('shards' in info)
self.assertTrue('configsvrs' in info)
self.assertTrue('routers' in info)
self.assertEqual(len(info['shards']), 2)
self.assertEqual(len(info['configsvrs']), 3)
self.assertEqual(len(info['routers']), 3)
self.sh.cleanup()
def test_tagging(self):
version = self.mongod_version()
if version and version < ('2', '2', '0'):
raise SkipTest("mongodb v{version} doesn't support shard tagging".format(version='.'.join(version)))
tags = ['tag1', 'tag2']
tags_repl = ['replTag']
config = {
'configsvrs': [{}], 'routers': [{}],
'shards': [{'id': 'sh01', 'shardParams': {'tags': tags}},
{'id': 'sh02'},
{'id': 'sh03', 'shardParams': {'tags': tags_repl, 'members': [{}, {}]}}
]
}
self.sh = ShardedCluster(config)
self.assertEqual(tags, self.sh.member_info('sh01')['tags'])
self.assertEqual([], self.sh.member_info('sh02')['tags'])
self.assertEqual(tags_repl, self.sh.member_info('sh03')['tags'])
self.sh.cleanup()
def test_reset(self):
all_hosts = []
# Start a ShardedCluster with 1 router and 1 config server.
self.sh = ShardedCluster({})
# Add 1 Server shard and 1 ReplicaSet shard.
server_id = self.sh.member_add(params={})['_id']
all_hosts.append(Servers().hostname(server_id))
repl_id = self.sh.member_add(params={'members': [{}, {}, {}]})['_id']
# Shut down the standalone.
Servers().command(server_id, 'stop')
# Shut down each member of the replica set.
server_ids = [m['server_id'] for m in ReplicaSets().members(repl_id)]
for s_id in server_ids:
Servers().command(s_id, 'stop')
all_hosts.append(Servers().hostname(s_id))
# Shut down config server and router.
config_id = self.sh.configsvrs[0]['id']
print("config_id=%r" % config_id)
all_hosts.append(Servers().hostname(config_id))
router_id = self.sh.routers[0]['id']
print("router_id=%r" % router_id)
all_hosts.append(Servers().hostname(router_id))
Servers().command(config_id, 'stop')
Servers().command(router_id, 'stop')
# Reset the ShardedCluster.
self.sh.reset()
# Everything is up.
for host in all_hosts:
# No ConnectionFailure/AutoReconnect.
pymongo.MongoClient(host)