コード例 #1
0
    def test_fabricmyqlserver(self):
        attrs = ['uuid', 'group', 'host', 'port', 'mode', 'status', 'weight']
        try:
            nmdtpl = fabric.FabricMySQLServer(*([''] * len(attrs)))
        except TypeError:
            self.fail("Fail creating namedtuple FabricMySQLServer")

        self.check_namedtuple(nmdtpl, attrs)
コード例 #2
0
    def test_get_group_servers(self):
        fab = _MockupFabric(_HOST, _PORT)
        fab.seed()

        exp = [
            # Secondary
            fabric.FabricMySQLServer(
                uuid='a6ac2895-574f-11e3-bc32-bcaec56cc4a7',
                group='testgroup1',
                host='tests.example.com',
                port=3372,
                mode=1,
                status=2,
                weight=1.0),
            # Primary
            fabric.FabricMySQLServer(
                uuid='af1cb1e4-574f-11e3-bc33-bcaec56cc4a7',
                group='testgroup1',
                host='tests.example.com',
                port=3373,
                mode=3,
                status=3,
                weight=1.0),
        ]

        self.assertEqual(exp, fab.get_group_servers('testgroup1'))
        self.assertEqual(exp,
                         fab.get_group_servers('testgroup1', use_cache=False))

        exp_balancers = {
            'testgroup1':
            balancing.WeightedRoundRobin((exp[0].uuid, exp[0].weight))
        }
        self.assertEqual(exp_balancers, fab._group_balancers)

        # No instances available, checking cache
        fab._fabric_instances = {}
        fab.get_group_servers('testgroup1')
        self.assertEqual(exp, fab.get_group_servers('testgroup1'))

        # Force lookup
        self.assertRaises(errors.InterfaceError,
                          fab.get_group_servers,
                          'testgroup1',
                          use_cache=False)
コード例 #3
0
 def test_fabric_uuid(self):
     self.cnx._fabric_mysql_server = fabric.FabricMySQLServer(
         uuid='af1cb1e4-574f-11e3-bc33-bcaec56cc4a7',
         group='testgroup1',
         host='tests.example.com',
         port=3373,
         mode=3,
         status=3,
         weight=1.0)
     exp = 'af1cb1e4-574f-11e3-bc33-bcaec56cc4a7'
     self.assertEqual(exp, self.cnx.fabric_uuid)
コード例 #4
0
    def test_get_shard_server(self):
        fab = _MockupFabric(_HOST, _PORT)
        fab.seed()

        self.assertRaises(ValueError, fab.get_shard_server, 'notlist', 1)
        self.assertRaises(ValueError, fab.get_shard_server, ['not_list'], 1)

        exp_local = [
            # Secondary
            fabric.FabricMySQLServer(
                uuid='a6ac2895-574f-11e3-bc32-bcaec56cc4a7',
                group='testgroup1',
                host='tests.example.com',
                port=3372,
                mode=1,
                status=2,
                weight=1.0),
            # Primary
            fabric.FabricMySQLServer(
                uuid='af1cb1e4-574f-11e3-bc33-bcaec56cc4a7',
                group='testgroup1',
                host='tests.example.com',
                port=3373,
                mode=3,
                status=3,
                weight=1.0),
        ]

        exp_global = [
            fabric.FabricMySQLServer(
                uuid='91f7090e-574f-11e3-bc32-bcaec56cc4a7',
                group='testglobalgroup',
                host='tests.example.com',
                port=3370,
                mode=3,
                status=3,
                weight=1.0),
            fabric.FabricMySQLServer(
                uuid='9c09932d-574f-11e3-bc32-bcaec56cc4a7',
                group='testglobalgroup',
                host='tests.example.com',
                port=3371,
                mode=1,
                status=2,
                weight=1.0),
        ]

        # scope=SCOPE_LOCAL, mode=None
        self.assertEqual(exp_local[0],
                         fab.get_shard_server(['shardtype.range'], 1))

        # scope=SCOPE_GLOBAL, read-only and read-write
        self.assertEqual(
            exp_global[0],
            fab.get_shard_server(['shardtype.range'],
                                 1,
                                 scope=fabric.SCOPE_GLOBAL,
                                 mode=fabric.MODE_READWRITE))
        self.assertEqual(
            exp_global[1],
            fab.get_shard_server(['shardtype.range'],
                                 1,
                                 scope=fabric.SCOPE_GLOBAL,
                                 mode=fabric.MODE_READONLY))

        self.assertRaises(errors.InterfaceError, fab.get_shard_server,
                          ['shardtype.spam'], 1)