• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sharded_clusters.ShardedCluster类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_members

    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,代码行数:10,代码来源:test_sharded_clusters.py


示例2: test_routers

    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()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:10,代码来源:test_sharded_clusters.py


示例3: test_operations

    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()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:12,代码来源:test_sharded_clusters.py


示例4: test_member_remove

    def test_member_remove(self):
        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()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:28,代码来源:test_sharded_clusters.py


示例5: test_auth_key_without_login

 def test_auth_key_without_login(self):
     self.sh = ShardedCluster({
         'auth_key': 'secret',
         'routers': [{}],
         'shards': [{}]
     })
     self.assertIsNotNone(self.sh.key_file)
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:7,代码来源:test_sharded_clusters.py


示例6: test_scram_with_ssl

    def test_scram_with_ssl(self):
        proc_params = {'procParams': {'clusterAuthMode': 'x509'}}
        config = {
            'login': 'luke',
            'password': 'ekul',
            'configsvrs': [{'clusterAuthMode': 'x509'}],
            'routers': [{'clusterAuthMode': 'x509'}],
            'shards': [{'shardParams': proc_params},
                       {'shardParams': {'members': [proc_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.sh = ShardedCluster(config)
        time.sleep(1)

        # Should create the user we requested. No raise on authenticate.
        host = self.sh.router['hostname']
        client = pymongo.MongoClient(
            host, 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'])
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:31,代码来源:test_sharded_clusters.py


示例7: test_reset

    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)
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:33,代码来源:test_sharded_clusters.py


示例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.")

        shard_params = {
            'shardParams': {
                'procParams': {
                    'clusterAuthMode': 'x509',
                    'setParameter': {'authenticationMechanisms': 'MONGODB-X509'}
                }
            }
        }
        config = {
            'login': TEST_SUBJECT,
            'authSource': '$external',
            'configsvrs': [{'clusterAuthMode': 'x509'}],
            'routers': [{'clusterAuthMode': 'x509'}],
            'shards': [shard_params, shard_params],
            'sslParams': {
                'sslCAFile': certificate('ca.pem'),
                'sslPEMKeyFile': certificate('server.pem'),
                'sslMode': 'requireSSL',
                'sslClusterFile': certificate('cluster_cert.pem'),
                'sslAllowInvalidCertificates': True
            }
        }
        self.sh = ShardedCluster(config)
        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(TEST_SUBJECT, auth_uri)
        self.assertIn('authSource=$external', auth_uri)
        self.assertIn('authMechanism=MONGODB-X509', auth_uri)
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:35,代码来源:test_sharded_clusters.py


示例9: test_router_add

 def test_router_add(self):
     config = {}
     self.sh = ShardedCluster(config)
     self.assertEqual(len(self.sh.routers), 1)
     self.sh.router_add({})
     self.assertEqual(len(self.sh.routers), 2)
     self.sh.router_add({})
     self.assertEqual(len(self.sh.routers), 3)
     self.sh.cleanup()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:9,代码来源:test_sharded_clusters.py


示例10: test_router

    def test_router(self):
        config = {}
        self.sh = ShardedCluster(config)
        self.assertTrue(Servers().info(self.sh.router['id'])['statuses']['mongos'])
        self.sh.cleanup()

        config = {'routers': [{}, {}, {}]}
        self.sh = ShardedCluster(config)
        routers = self.sh.routers
        hostname = routers[1]['hostname']
        _id = routers[1]['id']
        # stop routers 0 and 2
        Servers().command(routers[0]['id'], 'stop')
        Servers().command(routers[2]['id'], 'stop')
        router = self.sh.router
        self.assertEqual(router['id'], _id)
        self.assertEqual(router['hostname'], hostname)
        self.sh.cleanup()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:18,代码来源:test_sharded_clusters.py


示例11: test_len

 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)
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:11,代码来源:test_sharded_clusters.py


示例12: test_sh_new

 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'))
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:12,代码来源:test_sharded_clusters.py


示例13: test_cleanup

 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)
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:13,代码来源:test_sharded_clusters.py


示例14: test_member_info

    def test_member_info(self):
        config = {'shards': [{'id': 'member1'}, {'id': 'sh-rs-01', 'shardParams': {'id': 'rs1', 'members': [{}, {}]}}]}
        self.sh = ShardedCluster(config)
        info = self.sh.member_info('member1')
        self.assertEqual(info['id'], 'member1')
        self.assertTrue(info['isServer'])
        self.assertTrue('_id' in info)

        info = self.sh.member_info('sh-rs-01')
        self.assertEqual(info['id'], 'sh-rs-01')
        self.assertTrue(info['isReplicaSet'])
        self.assertTrue('_id' in info)

        self.sh.cleanup()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:14,代码来源:test_sharded_clusters.py


示例15: test_member_info_with_auth

    def test_member_info_with_auth(self):
        config = {'auth_key': 'secret', 'login': 'admin', 'password': 'adminpass', 'shards': [{'id': 'member1'}, {'id': 'sh-rs-01', 'shardParams': {'id': 'rs1', 'members': [{}, {}]}}]}
        self.sh = ShardedCluster(config)
        info = self.sh.member_info('member1')
        self.assertEqual(info['id'], 'member1')
        self.assertTrue(info['isServer'])
        self.assertTrue('_id' in info)

        info = self.sh.member_info('sh-rs-01')
        self.assertEqual(info['id'], 'sh-rs-01')
        self.assertTrue(info['isReplicaSet'])
        self.assertTrue('_id' in info)

        self.sh.cleanup()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:14,代码来源:test_sharded_clusters.py


示例16: test_member_add

    def test_member_add(self):
        config = {}
        self.sh = ShardedCluster(config)
        self.assertEqual(len(self.sh.members), 0)
        result = self.sh.member_add('test1', {})
        self.assertTrue(result.get('isServer', False))
        self.assertEqual(result['id'], 'test1')
        self.assertEqual(len(self.sh.members), 1)

        result = self.sh.member_add('test2', {'id': 'rs1', 'members': [{}, {}]})
        self.assertFalse(result.get('isServer', False))
        self.assertTrue(result.get('isReplicaSet', False))
        self.assertEqual(result['id'], 'test2')
        self.assertEqual(len(self.sh.members), 2)

        self.sh.cleanup()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:16,代码来源:test_sharded_clusters.py


示例17: test_info

    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()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:17,代码来源:test_sharded_clusters.py


示例18: test_sh_new_with_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'))
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:18,代码来源:test_sharded_clusters.py


示例19: test_ssl_auth

    def test_ssl_auth(self):
        if SERVER_VERSION < (2, 4):
            raise SkipTest("Need to be able to set 'authenticationMechanisms' "
                           "parameter to test.")

        shard_params = {
            'shardParams': {
                'procParams': {
                    'clusterAuthMode': 'x509',
                    'setParameter': {'authenticationMechanisms': 'MONGODB-X509'}
                }
            }
        }
        config = {
            'login': TEST_SUBJECT,
            'authSource': '$external',
            'configsvrs': [{'clusterAuthMode': 'x509'}],
            'routers': [{'clusterAuthMode': 'x509'}],
            'shards': [shard_params, shard_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.sh = ShardedCluster(config)

        # Should create an extra user. No raise on authenticate.
        host = self.sh.router['hostname']
        client = pymongo.MongoClient(
            host, ssl_certfile=DEFAULT_CLIENT_CERT,
            ssl_cert_reqs=ssl.CERT_NONE)
        client['$external'].authenticate(
            DEFAULT_SUBJECT, mechanism='MONGODB-X509')

        # Should create the user we requested. No raise on authenticate.
        client = pymongo.MongoClient(
            host, ssl_certfile=certificate('client.pem'),
            ssl_cert_reqs=ssl.CERT_NONE)
        client['$external'].authenticate(TEST_SUBJECT, mechanism='MONGODB-X509')
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:43,代码来源:test_sharded_clusters.py


示例20: test_tagging

    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()
开发者ID:agilemobiledev,项目名称:mongo-orchestration,代码行数:20,代码来源:test_sharded_clusters.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.Session类代码示例发布时间:2022-05-27
下一篇:
Python servers.Server类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap