Beispiel #1
0
    def list_parts():
        """
swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
    Returns a 2 column list of all the partitions that are assigned to any of
    the devices matching the search values given. The first column is the
    assigned partition number and the second column is the number of device
    matches for that partition. The list is ordered from most number of matches
    to least. If there are a lot of devices to match against, this command
    could take a while to run.
        """
        if len(argv) < 4:
            print Commands.list_parts.__doc__.strip()
            print
            print parse_search_value.__doc__.strip()
            exit(EXIT_ERROR)

        if not builder._replica2part2dev:
            print('Specified builder file \"%s\" is not rebalanced yet. '
                  'Please rebalance first.' % argv[1])
            exit(EXIT_ERROR)

        sorted_partition_count = find_parts(builder, argv)

        if not sorted_partition_count:
            print 'No matching devices found'
            exit(EXIT_ERROR)

        print 'Partition   Matches'
        for partition, count in sorted_partition_count:
            print '%9d   %7d' % (partition, count)
        exit(EXIT_SUCCESS)
Beispiel #2
0
    def list_parts():
        """
swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
    Returns a 2 column list of all the partitions that are assigned to any of
    the devices matching the search values given. The first column is the
    assigned partition number and the second column is the number of device
    matches for that partition. The list is ordered from most number of matches
    to least. If there are a lot of devices to match against, this command
    could take a while to run.
        """
        if len(argv) < 4:
            print Commands.list_parts.__doc__.strip()
            print
            print parse_search_value.__doc__.strip()
            exit(EXIT_ERROR)

        if not builder._replica2part2dev:
            print(
                'Specified builder file \"%s\" is not rebalanced yet. '
                'Please rebalance first.' % argv[1])
            exit(EXIT_ERROR)

        sorted_partition_count = find_parts(builder, argv)

        if not sorted_partition_count:
            print 'No matching devices found'
            exit(EXIT_ERROR)

        print 'Partition   Matches'
        for partition, count in sorted_partition_count:
            print '%9d   %7d' % (partition, count)
        exit(EXIT_SUCCESS)
Beispiel #3
0
    def test_find_parts(self):
        rb = ring.RingBuilder(8, 3, 0)
        rb.add_dev({'id': 0, 'region': 1, 'zone': 0, 'weight': 100,
                    'ip': '127.0.0.1', 'port': 10000, 'device': 'sda1'})
        rb.add_dev({'id': 1, 'region': 1, 'zone': 1, 'weight': 100,
                    'ip': '127.0.0.1', 'port': 10001, 'device': 'sda1'})
        rb.add_dev({'id': 2, 'region': 1, 'zone': 2, 'weight': 100,
                    'ip': '127.0.0.1', 'port': 10002, 'device': 'sda1'})
        rb.rebalance()

        rb.add_dev({'id': 3, 'region': 2, 'zone': 1, 'weight': 10,
                    'ip': '127.0.0.1', 'port': 10004, 'device': 'sda1'})
        rb.pretend_min_part_hours_passed()
        rb.rebalance()

        argv = ['swift-ring-builder', 'object.builder',
                'list_parts', '127.0.0.1']
        sorted_partition_count = find_parts(rb, argv)

        # Expect 256 partitions in the output
        self.assertEqual(256, len(sorted_partition_count))

        # Each partitions should have 3 replicas
        for partition, count in sorted_partition_count:
            self.assertEqual(
                3, count, "Partition %d has only %d replicas" %
                (partition, count))
Beispiel #4
0
    def test_find_parts(self):
        rb = ring.RingBuilder(8, 3, 0)
        rb.add_dev({
            'id': 0,
            'region': 1,
            'zone': 0,
            'weight': 100,
            'ip': '127.0.0.1',
            'port': 10000,
            'device': 'sda1'
        })
        rb.add_dev({
            'id': 1,
            'region': 1,
            'zone': 1,
            'weight': 100,
            'ip': '127.0.0.1',
            'port': 10001,
            'device': 'sda1'
        })
        rb.add_dev({
            'id': 2,
            'region': 1,
            'zone': 2,
            'weight': 100,
            'ip': '127.0.0.1',
            'port': 10002,
            'device': 'sda1'
        })
        rb.rebalance()

        rb.add_dev({
            'id': 3,
            'region': 2,
            'zone': 1,
            'weight': 10,
            'ip': '127.0.0.1',
            'port': 10004,
            'device': 'sda1'
        })
        rb.pretend_min_part_hours_passed()
        rb.rebalance()

        argv = [
            'swift-ring-builder', 'object.builder', 'list_parts', '127.0.0.1'
        ]
        sorted_partition_count = find_parts(rb, argv)

        # Expect 256 partitions in the output
        self.assertEqual(256, len(sorted_partition_count))

        # Each partitions should have 3 replicas
        for partition, count in sorted_partition_count:
            self.assertEqual(
                3, count,
                "Partition %d has only %d replicas" % (partition, count))