当前位置: 首页>>代码示例>>Python>>正文


Python ShardedCluster.member_add方法代码示例

本文整理汇总了Python中mongo_orchestration.sharded_clusters.ShardedCluster.member_add方法的典型用法代码示例。如果您正苦于以下问题:Python ShardedCluster.member_add方法的具体用法?Python ShardedCluster.member_add怎么用?Python ShardedCluster.member_add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongo_orchestration.sharded_clusters.ShardedCluster的用法示例。


在下文中一共展示了ShardedCluster.member_add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ShardTestCase

# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import member_add [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()

#.........这里部分代码省略.........
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:103,代码来源:test_sharded_clusters.py

示例2: ShardTestCase

# 需要导入模块: from mongo_orchestration.sharded_clusters import ShardedCluster [as 别名]
# 或者: from mongo_orchestration.sharded_clusters.ShardedCluster import member_add [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)
#.........这里部分代码省略.........
开发者ID:jyemin,项目名称:mongo-orchestration,代码行数:103,代码来源:test_sharded_clusters.py


注:本文中的mongo_orchestration.sharded_clusters.ShardedCluster.member_add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。