Ejemplo n.º 1
0
 def test_16_make(self):
     num_partitions = 5
     num_replicas = 1
     pt = PartitionTable(num_partitions, num_replicas)
     # add nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1, NodeStates.RUNNING)
     # add not running node
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = StorageNode(Mock(), server2, uuid2)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     # add node without uuid
     server3 = ("127.0.0.3", 19001)
     sn3 = StorageNode(Mock(), server3, None, NodeStates.RUNNING)
     # add clear node
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19001)
     sn4 = StorageNode(Mock(), server4, uuid4, NodeStates.RUNNING)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 1900)
     sn5 = StorageNode(Mock(), server5, uuid5, NodeStates.RUNNING)
     # make the table
     pt.make([sn1, sn2, sn3, sn4, sn5])
     # check it's ok, only running nodes and node with uuid
     # must be present
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 2)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertTrue(node in (sn1, sn4, sn5))
             self.assertTrue(node not in (sn2, sn3))
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
     # create a pt with less nodes
     pt.clear()
     self.assertFalse(pt.filled())
     self.assertFalse(pt.operational())
     pt.make([sn1])
     # check it's ok
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 1)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertEqual(node, sn1)
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
Ejemplo n.º 2
0
 def test_16_make(self):
     num_partitions = 5
     num_replicas = 1
     pt = PartitionTable(num_partitions, num_replicas)
     # add nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = StorageNode(Mock(), server1, uuid1, NodeStates.RUNNING)
     # add not running node
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19001)
     sn2 = StorageNode(Mock(), server2, uuid2)
     sn2.setState(NodeStates.TEMPORARILY_DOWN)
     # add node without uuid
     server3 = ("127.0.0.3", 19001)
     sn3 = StorageNode(Mock(), server3, None, NodeStates.RUNNING)
     # add clear node
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19001)
     sn4 = StorageNode(Mock(), server4, uuid4, NodeStates.RUNNING)
     uuid5 = self.getStorageUUID()
     server5 = ("127.0.0.5", 1900)
     sn5 = StorageNode(Mock(), server5, uuid5, NodeStates.RUNNING)
     # make the table
     pt.make([sn1, sn2, sn3, sn4, sn5])
     # check it's ok, only running nodes and node with uuid
     # must be present
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 2)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertTrue(node in (sn1, sn4, sn5))
             self.assertTrue(node not in (sn2, sn3))
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
     # create a pt with less nodes
     pt.clear()
     self.assertFalse(pt.filled())
     self.assertFalse(pt.operational())
     pt.make([sn1])
     # check it's ok
     for x in xrange(num_partitions):
         cells = pt.getCellList(x)
         self.assertEqual(len(cells), 1)
         nodes = [x.getNode() for x in cells]
         for node in nodes:
             self.assertEqual(node, sn1)
     self.assertTrue(pt.filled())
     self.assertTrue(pt.operational())
Ejemplo n.º 3
0
 def test_16_make(self):
     node_list = [self.createStorage(
             ("127.0.0.1", 19000 + i), self.getStorageUUID(),
             NodeStates.RUNNING)
         for i in xrange(4)]
     for np, nr, expected in (
             (3, 0, 'U..|.U.|..U'),
             (5, 1, 'UU..|..UU|UU..|..UU|UU..'),
             (9, 2, 'UUU.|UU.U|U.UU|.UUU|UUU.|UU.U|U.UU|.UUU|UUU.'),
             ):
         pt = PartitionTable(np, nr)
         pt.make(node_list)
         self.assertPartitionTable(pt, expected)
         self.assertTrue(pt.filled())
         self.assertTrue(pt.operational())
         # create a pt with less nodes
         pt.clear()
         self.assertFalse(pt.filled())
         self.assertFalse(pt.operational())
         pt.make(node_list[:1])
         self.assertPartitionTable(pt, '|'.join('U' * np))
         self.assertTrue(pt.filled())
         self.assertTrue(pt.operational())
Ejemplo n.º 4
0
    def test_17_tweak(self):
        sn = [StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
              for i in xrange(5)]
        pt = PartitionTable(5, 2)
        # part 0
        pt.setCell(0, sn[0], CellStates.DISCARDED)
        pt.setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt.setCell(1, sn[0], CellStates.FEEDING)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt.setCell(2, sn[0], CellStates.FEEDING)
        pt.setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt.setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt.setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        change_list = self.tweak(pt)
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(count_dict, {CellStates.DISCARDED: 3,
                                      CellStates.OUT_OF_DATE: 5,
                                      CellStates.UP_TO_DATE: 3})
        self.update(pt, change_list)
        self.checkPT(pt)

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        change_list = self.tweak(pt)
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)
        self.checkPT(pt)

        for np, i in (12, 0), (12, 1), (13, 2):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
                self.checkPT(pt)
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.checkPT(pt)

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.update(pt, self.tweak(pt, sn[:1]))
        self.checkPT(pt, True)
Ejemplo n.º 5
0
 def test_19_topology(self):
     sn_count = 16
     sn = [self.createStorage(None, i + 1, NodeStates.RUNNING)
           for i in xrange(sn_count)]
     pt = PartitionTable(48, 2)
     pt.make(sn)
     pt.log()
     for i, s in enumerate(sn, sn_count):
         s.extra = {'devpath': tuple(bin(i)[3:-1])}
     self.assertEqual(Counter(x[2] for x in self.tweak(pt)), {
         CellStates.OUT_OF_DATE: 96,
         CellStates.FEEDING: 96,
     })
     self.update(pt)
     x = lambda n, *x: ('|'.join(x[:1]*n), '|'.join(x[1:]*n))
     for even, np, i, topo, expected in (
         ## Optimal topology.
         # All nodes have same number of cells.
         (1, 2, 2, ("00", "01", "02", "10", "11", "12"), ('UU...U|..UUU.',
                                                          'UU.U..|..U.UU')),
         (1, 7, 1, "0001122", (
             'U.....U|.U.U...|..U.U..|U....U.|.U....U|..UU...|....UU.',
             'U..U...|.U...U.|..U.U..|U.....U|.U.U...|..U..U.|....U.U')),
         (1, 4, 1, "00011122", ('U......U|.U.U....|..U.U...|.....UU.',
                                'U..U....|.U..U...|..U...U.|.....U.U')),
         (1, 9, 1, "000111222", ('U.......U|.U.U.....|..U.U....|'
                                 '.....UU..|U......U.|.U......U|'
                                 '..UU.....|....U.U..|.....U.U.',
                                 'U..U.....|.U....U..|..U.U....|'
                                 '.....U.U.|U.......U|.U.U.....|'
                                 '..U...U..|....U..U.|.....U..U')),
         # Some nodes have a extra cell.
         (0, 8, 1, "0001122", ('U.....U|.U.U...|..U.U..|U....U.|'
                               '.U....U|..UU...|....UU.|U.....U',
                               'U..U...|.U...U.|..U.U..|U.....U|'
                               '.U.U...|..U..U.|....U.U|U..U...')),
         ## Topology ignored.
         (1, 6, 1, ("00", "01", "1"), 'UU.|U.U|.UU|UU.|U.U|.UU'),
         (1, 5, 2, "01233", 'UUU..|U..UU|.UUU.|UU..U|..UUU'),
     ):
         assert len(topo) <= sn_count
         sn2 = sn[:len(topo)]
         for s in sn2:
             s.extra = {}
         k = (1,7)[even]
         pt = PartitionTable(np*k, i)
         pt.make(sn2)
         for devpath, s in zip(topo, sn2):
             s.extra = {'devpath': tuple(devpath)}
         if type(expected) is tuple:
             self.assertTrue(self.tweak(pt))
             self.update(pt)
             self.assertPartitionTable(pt, '|'.join(expected[:1]*k))
             pt.clear()
             pt.make(sn2)
             self.assertPartitionTable(pt, '|'.join(expected[1:]*k))
             self.assertFalse(pt.tweak())
         else:
             expected = '|'.join((expected,)*k)
             self.assertFalse(pt.tweak())
             self.assertPartitionTable(pt, expected)
             pt.clear()
             pt.make(sn2)
             self.assertPartitionTable(pt, expected)
Ejemplo n.º 6
0
    def test_17_tweak(self):
        sn = [self.createStorage(None, i + 1, NodeStates.RUNNING)
              for i in xrange(5)]
        pt = PartitionTable(5, 2)
        pt.setID(1)
        # part 0
        pt._setCell(0, sn[0], CellStates.DISCARDED)
        pt._setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt._setCell(1, sn[0], CellStates.FEEDING)
        pt._setCell(1, sn[1], CellStates.FEEDING)
        pt._setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt._setCell(2, sn[0], CellStates.FEEDING)
        pt._setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt._setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt._setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt._setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt._setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        self.assertPartitionTable(pt, (
            '.U...',
            'FFO..',
            'FUU..',
            'UUUU.',
            'U...U'))
        change_list = self.tweak(pt)
        self.assertPartitionTable(pt, (
            '.UO.O',
            'UU.O.',
            'UFU.O',
            '.UUU.',
            'U..OU'))
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(count_dict, {CellStates.DISCARDED: 2,
                                      CellStates.FEEDING: 1,
                                      CellStates.OUT_OF_DATE: 5,
                                      CellStates.UP_TO_DATE: 3})
        self.update(pt)
        self.assertPartitionTable(pt, (
            '.UU.U',
            'UU.U.',
            'U.U.U',
            '.UUU.',
            'U..UU'))
        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        self.assertPartitionTable(pt, (
            '..U.U',
            'U..U.',
            'U.U.U',
            '..UU.',
            'U..UU'))
        change_list = self.tweak(pt)
        self.assertPartitionTable(pt, (
            '.OU.U',
            'UO.U.',
            'U.U.U',
            '.OUU.',
            'U..UU'))
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)

        for np, i, expected in (
                (12, 0, ('U...|.U..|..U.|...U|'
                         'U...|.U..|..U.|...U|'
                         'U...|.U..|..U.|...U',)),
                (12, 1, ('UU...|..UU.|U...U|.UU..|...UU|'
                         'UU...|..UU.|U...U|.UU..|...UU|'
                         'UU...|..UU.',)),
                (13, 2, ('U.UU.|.U.UU|UUU..|..UUU|UU..U|'
                         'U.UU.|.U.UU|UUU..|..UUU|UU..U|'
                         'U.UU.|.U.UU|UUU..',
                         'UUU..|U..UU|.UUU.|UU..U|..UUU|'
                         'UUU..|U..UU|.UUU.|UU..U|..UUU|'
                         'UUU..|U..UU|.UUU.')),
                ):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            pt.log()
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
            self.assertPartitionTable(pt, expected[0])
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.assertPartitionTable(pt, expected[-1])

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.assertPartitionTable(pt, 'U..|U..|U..|U..|U..|U..|U..')
        self.update(pt, self.tweak(pt, sn[:1]))
        # See note in PartitionTable.tweak() about drop_list.
        #self.assertPartitionTable(pt,'.U.|..U|.U.|..U|.U.|..U|.U.')
        self.assertPartitionTable(pt, 'UU.|U.U|UU.|U.U|UU.|U.U|UU.')
Ejemplo n.º 7
0
    def test_17_tweak(self):
        sn = [
            StorageNode(Mock(), None, i + 1, NodeStates.RUNNING)
            for i in xrange(5)
        ]
        pt = PartitionTable(5, 2)
        # part 0
        pt.setCell(0, sn[0], CellStates.DISCARDED)
        pt.setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt.setCell(1, sn[0], CellStates.FEEDING)
        pt.setCell(1, sn[1], CellStates.FEEDING)
        pt.setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt.setCell(2, sn[0], CellStates.FEEDING)
        pt.setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt.setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt.setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt.setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt.setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        change_list = self.tweak(pt)
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(
            count_dict, {
                CellStates.DISCARDED: 3,
                CellStates.OUT_OF_DATE: 5,
                CellStates.UP_TO_DATE: 3
            })
        self.update(pt, change_list)
        self.checkPT(pt)

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        change_list = self.tweak(pt)
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)
        self.checkPT(pt)

        for np, i in (12, 0), (12, 1), (13, 2):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            for n in sn[i:i + 3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
                self.checkPT(pt)
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i + 3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.checkPT(pt)

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.update(pt, self.tweak(pt, sn[:1]))
        self.checkPT(pt, True)