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


Python ReplicaSet.member_freeze方法代码示例

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


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

示例1: ReplicaSetTestCase

# 需要导入模块: from lib.rs import ReplicaSet [as 别名]
# 或者: from lib.rs.ReplicaSet import member_freeze [as 别名]

#.........这里部分代码省略.........
        self.assertTrue(self.repl.member_del(2, reconfig=False))
        self.assertEqual(len(self.repl.config['members']), m_count)
        self.repl.host_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.assertEqual(member['host'], result['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_member_freeze(self):
        self.repl_cfg = {"members": [{"rsParams": {"priority": 19}}, {"rsParams": {"priority": 7}}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)
        primary_next = self.repl.member_info(2)['uri']
        self.assertTrue(self.repl.member_freeze(1, 30))
        self.repl.member_command(0, 'stop')
        self.assertEqual(self.repl.primary(), primary_next)
        time.sleep(40)
        self.assertEqual(self.repl.primary(), self.repl.member_info(1)['uri'])

    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 xrange(len(members1)):
            self.assertEqual(members1[i]['host'], members2[i]['host'])
            self.assertEqual(members1[i]['_id'], members2[i]['_id'])

    def test_stepdown(self):
        self.repl_cfg = {'members': [{}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)
        primary = self.repl.primary()
        self.assertTrue(self.repl.stepdown())
        self.assertNotEqual(primary, self.repl.primary())

    def test_primary(self):
        self.repl_cfg = {'members': [{}, {}]}
        self.repl = ReplicaSet(self.repl_cfg)
        primary = self.repl.primary()
        self.assertTrue(Hosts().info(Hosts().id_by_hostname(primary))['statuses']['primary'])
开发者ID:gjmurakami-10gen,项目名称:mongo-orchestration,代码行数:69,代码来源:test_rs.py


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