本文整理汇总了Python中mongo_orchestration.sharded_clusters.ShardedCluster.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python ShardedCluster.cleanup方法的具体用法?Python ShardedCluster.cleanup怎么用?Python ShardedCluster.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_orchestration.sharded_clusters.ShardedCluster
的用法示例。
在下文中一共展示了ShardedCluster.cleanup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_operations
# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import cleanup [as 别名]
def test_operations(self):
config = {'shards': [{}, {}, {}]}
cluster = ShardedCluster(config)
self.assertEqual(len(self.sh), 0)
operator.setitem(self.sh, 1, cluster)
self.assertEqual(len(self.sh), 1)
self.assertEqual(operator.getitem(self.sh, 1)['id'], cluster.id)
operator.delitem(self.sh, 1)
self.assertEqual(len(self.sh), 0)
self.assertRaises(KeyError, operator.getitem, self.sh, 1)
cluster.cleanup()
示例2: ShardTestCase
# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import cleanup [as 别名]
class ShardTestCase(unittest.TestCase):
def setUp(self):
PortPool().change_range()
def tearDown(self):
if hasattr(self, 'sh') and self.sh is not None:
self.sh.cleanup()
def test_len(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh), 0)
self.sh.member_add('test01', {})
self.assertEqual(len(self.sh), 1)
self.sh.member_add('test02', {})
self.assertEqual(len(self.sh), 2)
while self.sh.member_remove('test01')['state'] != 'completed':
time.sleep(1)
self.assertEqual(len(self.sh), 1)
def test_sh_new(self):
port = PortPool().port(check=True)
config = {
'id': 'shard_cluster_1',
'configsvrs': [{}],
'routers': [{"port": port}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'}]
}
self.sh = ShardedCluster(config)
c = pymongo.MongoClient(self.sh.router['hostname'])
for item in c.admin.command("listShards")['shards']:
self.assertTrue(item['_id'] in ('sh01', 'sh02'))
def test_sh_new_with_auth(self):
port = PortPool().port(check=True)
config = {
'id': 'shard_cluster_1',
'auth_key': 'secret',
'login': 'admin',
'password': 'adminpass',
'configsvrs': [{}],
'routers': [{"port": port}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'}]
}
self.sh = ShardedCluster(config)
c = pymongo.MongoClient(self.sh.router['hostname'])
self.assertRaises(pymongo.errors.OperationFailure, c.admin.command, "listShards")
c.admin.authenticate('admin', 'adminpass')
self.assertTrue(isinstance(c.admin.command("listShards"), dict))
for item in c.admin.command("listShards")['shards']:
self.assertTrue(item['_id'] in ('sh01', 'sh02'))
def test_cleanup(self):
config = {
'id': 'shard_cluster_1',
'configsvrs': [{}],
'routers': [{}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'},
{'id': 'sh-rs-01', 'shardParams': {'id': 'rs1', 'members': [{}, {}]}},
]
}
self.sh = ShardedCluster(config)
self.assertTrue(len(self.sh) == len(config['shards']))
self.sh.cleanup()
self.assertTrue(len(self.sh) == 0)
def test_configsvrs(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.configsvrs), 1)
self.sh.cleanup()
config = {'configsvrs': [{}, {}, {}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.configsvrs), 3)
self.sh.cleanup()
def test_routers(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.routers), 1)
self.sh.cleanup()
config = {'routers': [{}, {}, {}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.routers), 3)
self.sh.cleanup()
def test_members(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.members), 0)
self.sh.cleanup()
config = {'shards': [{}, {}, {}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.members), 3)
self.sh.cleanup()
#.........这里部分代码省略.........
示例3: ShardTestCase
# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import cleanup [as 别名]
class ShardTestCase(unittest.TestCase):
def mongod_version(self):
proc = subprocess.Popen(
[os.path.join(self.bin_path, 'mongod'), '--version'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
version_raw = str(proc.stdout.read())
m = MONGODB_VERSION.match(version_raw)
if m:
return m.groups()
def setUp(self):
self.bin_path = os.environ.get('MONGOBIN', '')
set_releases({'default-release': self.bin_path},
'default-release')
PortPool().change_range()
def tearDown(self):
if hasattr(self, 'sh') and self.sh is not None:
self.sh.cleanup()
def test_len(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh), 0)
self.sh.member_add('test01', {})
self.assertEqual(len(self.sh), 1)
self.sh.member_add('test02', {})
self.assertEqual(len(self.sh), 2)
while self.sh.member_remove('test01')['state'] != 'completed':
time.sleep(1)
self.assertEqual(len(self.sh), 1)
def test_sh_new(self):
port = PortPool().port(check=True)
config = {
'id': 'shard_cluster_1',
'configsvrs': [{}],
'routers': [{"port": port}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'}]
}
self.sh = ShardedCluster(config)
c = pymongo.MongoClient(self.sh.router['hostname'])
for item in c.admin.command("listShards")['shards']:
self.assertTrue(item['_id'] in ('sh01', 'sh02'))
@attr('auth')
def test_sh_new_with_auth(self):
port = PortPool().port(check=True)
config = {
'id': 'shard_cluster_1',
'auth_key': 'secret',
'login': 'admin',
'password': 'adminpass',
'configsvrs': [{}],
'routers': [{"port": port}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'}]
}
self.sh = ShardedCluster(config)
c = pymongo.MongoClient(self.sh.router['hostname'])
self.assertRaises(pymongo.errors.OperationFailure, c.admin.command, "listShards")
c.admin.authenticate('admin', 'adminpass')
self.assertTrue(isinstance(c.admin.command("listShards"), dict))
for item in c.admin.command("listShards")['shards']:
self.assertTrue(item['_id'] in ('sh01', 'sh02'))
def test_cleanup(self):
config = {
'id': 'shard_cluster_1',
'configsvrs': [{}],
'routers': [{}],
'shards': [{'id': 'sh01'}, {'id': 'sh02'},
{'id': 'sh-rs-01', 'shardParams': {'id': 'rs1', 'members': [{}, {}]}},
]
}
self.sh = ShardedCluster(config)
self.assertTrue(len(self.sh) == len(config['shards']))
self.sh.cleanup()
self.assertTrue(len(self.sh) == 0)
def test_configsvrs(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.configsvrs), 1)
self.sh.cleanup()
config = {'configsvrs': [{}, {}, {}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.configsvrs), 3)
self.sh.cleanup()
def test_routers(self):
config = {}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.routers), 1)
self.sh.cleanup()
config = {'routers': [{}, {}, {}]}
self.sh = ShardedCluster(config)
self.assertEqual(len(self.sh.routers), 3)
#.........这里部分代码省略.........