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


Python ReplicaSet.member_info方法代码示例

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


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

示例1: ReplicaSetAuthTestCase

# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import member_info [as 别名]
class ReplicaSetAuthTestCase(unittest.TestCase):
    def setUp(self):
        PortPool().change_range()
        self.servers = Servers()
        self.servers.set_settings(os.environ.get('MONGOBIN', None))
        self.repl_cfg = {'auth_key': 'secret', 'login': 'admin', 'password': 'admin', 'members': [{}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)

    def tearDown(self):
        if len(self.repl) > 0:
            self.repl.cleanup()

    def test_auth_connection(self):
        self.assertTrue(isinstance(self.repl.connection().admin.collection_names(), list))
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)

    def test_auth_admin(self):
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        self.assertTrue(isinstance(c.admin.collection_names(), list))
        self.assertTrue(c.admin.logout() is None)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)

    def test_auth_collection(self):
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        db = c.test_auth
        db.add_user('user', 'userpass', roles=['readWrite'])
        c.admin.logout()

        self.assertTrue(db.authenticate('user', 'userpass'))
        self.assertTrue(db.foo.insert({'foo': 'bar'}, w=2, wtimeout=1000))
        self.assertTrue(isinstance(db.foo.find_one(), dict))
        db.logout()
        self.assertRaises(pymongo.errors.OperationFailure, db.foo.find_one)

    def test_auth_arbiter_member_info(self):
        self.repl = ReplicaSet({'members': [
            {}, {'rsParams': {'arbiterOnly': True}}]})
        info = self.repl.member_info(1)
        for key in ('procInfo', 'mongodb_uri', 'statuses', 'rsInfo'):
            self.assertIn(key, info)
        rs_info = info['rsInfo']
        for key in ('primary', 'secondary', 'arbiterOnly'):
            self.assertIn(key, rs_info)
        self.assertFalse(rs_info['primary'])
        self.assertFalse(rs_info['secondary'])
        self.assertTrue(rs_info['arbiterOnly'])
开发者ID:TylerBrock,项目名称:mongo-orchestration,代码行数:52,代码来源:test_replica_sets.py

示例2: ReplicaSetAuthTestCase

# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import member_info [as 别名]
class ReplicaSetAuthTestCase(unittest.TestCase):
    def setUp(self):
        PortPool().change_range()
        self.servers = Servers()
        self.servers.set_settings(*TEST_RELEASES)
        self.repl_cfg = {'auth_key': 'secret', 'login': 'admin', 'password': 'admin', 'members': [{}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)

    def tearDown(self):
        if len(self.repl) > 0:
            self.repl.cleanup()

    def test_auth_connection(self):
        self.assertTrue(isinstance(self.repl.connection().admin.collection_names(), list))
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)

    def test_auth_admin(self):
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        self.assertTrue(isinstance(c.admin.collection_names(), list))
        self.assertTrue(c.admin.logout() is None)
        self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)

    def test_auth_collection(self):
        c = pymongo.MongoReplicaSetClient(self.repl.primary(), replicaSet=self.repl.repl_id)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        db = c.test_auth
        db.add_user('user', 'userpass', roles=['readWrite'])
        c.admin.logout()

        self.assertTrue(db.authenticate('user', 'userpass'))
        self.assertTrue(db.foo.insert({'foo': 'bar'}, w=2, wtimeout=10000))
        self.assertTrue(isinstance(db.foo.find_one(), dict))
        db.logout()
        self.assertRaises(pymongo.errors.OperationFailure, db.foo.find_one)

    def test_auth_arbiter_member_info(self):
        self.repl.cleanup()
        self.repl = ReplicaSet({'members': [
            {}, {'rsParams': {'arbiterOnly': True}}]})
        info = self.repl.member_info(1)
        for key in ('procInfo', 'mongodb_uri', 'statuses', 'rsInfo'):
            self.assertIn(key, info)
        rs_info = info['rsInfo']
        for key in ('primary', 'secondary', 'arbiterOnly'):
            self.assertIn(key, rs_info)
        self.assertFalse(rs_info['primary'])
        self.assertFalse(rs_info['secondary'])
        self.assertTrue(rs_info['arbiterOnly'])

    def test_mongodb_auth_uri(self):
        self.assertIn('mongodb_auth_uri', self.repl.info())
        rs_auth_uri = self.repl.info()['mongodb_auth_uri']
        hosts = ','.join(m['host'] for m in self.repl.members())
        self.assertIn(hosts, rs_auth_uri)
        self.assertIn('admin:admin', rs_auth_uri)
        self.assertIn('authSource=admin', rs_auth_uri)
        replset_param = 'replicaSet=' + self.repl.repl_id
        self.assertIn(replset_param, rs_auth_uri)

    def test_member_info_auth_uri(self):
        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('admin:admin', uri)
            self.assertIn('authSource=admin', uri)
开发者ID:10gen,项目名称:mongo-orchestration,代码行数:73,代码来源:test_replica_sets.py

示例3: ReplicaSetSSLTestCase

# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import member_info [as 别名]

#.........这里部分代码省略.........
        # 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'])

    def test_ssl(self):
        member_params = {}
        self.repl_cfg = {
            '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)

        # Server should require SSL.
        with self.assertRaises(pymongo.errors.ConnectionFailure):
            connected(pymongo.MongoClient(self.repl.primary()))

        # This shouldn't raise.
        connected(pymongo.MongoClient(
            self.repl.primary(), ssl_certfile=certificate('client.pem'),
            ssl_cert_reqs=ssl.CERT_NONE))

    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)

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

示例4: ReplicaSetTestCase

# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import member_info [as 别名]

#.........这里部分代码省略.........
        self.repl = ReplicaSet(self.repl_cfg)
        result = self.repl.member_create({}, 13)
        self.assertTrue('host' in result)
        self.assertTrue('_id' in result)
        h_id = Servers().host_to_server_id(result['host'])
        h_info = Servers().info(h_id)
        self.assertIn(result['host'], h_info['mongodb_uri'])
        self.assertTrue(h_info['procInfo']['alive'])
        Servers().remove(h_id)

    def test_member_del(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))
        self.assertEqual(len(self.repl.config['members']), m_count - 1)

    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)

    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))

    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)

    def test_member_command(self):
        self.repl_cfg = {'members': [{}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)
        _id = 1
        self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])
        self.repl.member_command(_id, 'stop')
        self.assertFalse(self.repl.member_info(_id)['procInfo']['alive'])
        self.repl.member_command(_id, 'start')
        self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])
        self.repl.member_command(_id, 'restart')
        self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])

    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'])

    def test_primary(self):
        self.repl_cfg = {'members': [{}, {}]}
开发者ID:10gen,项目名称:mongo-orchestration,代码行数:70,代码来源:test_replica_sets.py


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