def initialize(self, service_dir):
        super(LocalDiskResourceService, self).initialize(service_dir)

        # Make sure LVM Volume Group set up
        localdiskutils.setup_device_lvm(self._block_dev, self._vg_name)

        # Finally retrieve the LV info
        lvs_info = lvm.lvsdisplay(group=self._vg_name)

        # Mark all retrived volumes that were created by treadmill as 'stale'
        for lv in lvs_info:
            lv['stale'] = lv['name'].startswith(TREADMILL_LV_PREFIX)
            if lv['open_count']:
                _LOGGER.warning('Logical volume in use: %r', lv['block_dev'])

        # Count the number of extents taken by non-treadmill volumes
        self._extent_reserved = sum(
            [lv['extent_size'] for lv in lvs_info if not lv['stale']])

        volumes = {
            lv['name']: {
                k: lv[k]
                for k in [
                    'name',
                    'block_dev',
                    'dev_major',
                    'dev_minor',
                    'extent_size',
                    'stale',
                ]
            }
            for lv in lvs_info
        }
        self._volumes = volumes
        self._vg_status = localdiskutils.refresh_vg_status(self._vg_name)
Exemple #2
0
    def test_lvsdisplay(self):
        """Test display of list of LVM volumes informations.
        """
        treadmill.subproc.check_output.return_value = (
            '  /dev/test/test-lv:test:3:1:-1:0:24576:'
            '3:-1:0:-1:253:5\n'
            '  /dev/treadmill/oRHxZN5QldMdz:treadmill:3:1:-1:1:10485760:'
            '1280:-1:0:-1:253:0\n'
            '  /dev/treadmill/ESE0g3hyf7nxv:treadmill:3:1:-1:1:2097152:'
            '256:-1:0:-1:253:1\n'
            '  /dev/treadmill/p8my37oRJGcd5:treadmill:3:1:-1:1:204800:'
            '25:-1:0:-1:253:2\n'
            '  /dev/treadmill/njZhRefmf6jQp:treadmill:3:1:-1:1:1024000:'
            '125:-1:0:-1:253:3\n'
            '  /dev/treadmill/yRImNK9cnix2T:treadmill:3:1:-1:1:204800:'
            '25:-1:0:-1:253:4\n')

        lvs = lvm.lvsdisplay()

        treadmill.subproc.check_output.assert_called_with([
            'lvm',
            'lvdisplay',
            '--colon',
        ])
        self.assertEqual(lvs, [
            {
                'block_dev': '/dev/test/test-lv',
                'dev_major': 253,
                'dev_minor': 5,
                'extent_alloc': -1,
                'extent_size': 3,
                'group': 'test',
                'name': 'test-lv',
                'open_count': 0,
            },
            {
                'block_dev': '/dev/treadmill/oRHxZN5QldMdz',
                'dev_major': 253,
                'dev_minor': 0,
                'extent_alloc': -1,
                'extent_size': 1280,
                'group': 'treadmill',
                'name': 'oRHxZN5QldMdz',
                'open_count': 1,
            },
            {
                'block_dev': '/dev/treadmill/ESE0g3hyf7nxv',
                'dev_major': 253,
                'dev_minor': 1,
                'extent_alloc': -1,
                'extent_size': 256,
                'group': 'treadmill',
                'name': 'ESE0g3hyf7nxv',
                'open_count': 1,
            },
            {
                'block_dev': '/dev/treadmill/p8my37oRJGcd5',
                'dev_major': 253,
                'dev_minor': 2,
                'extent_alloc': -1,
                'extent_size': 25,
                'group': 'treadmill',
                'name': 'p8my37oRJGcd5',
                'open_count': 1,
            },
            {
                'block_dev': '/dev/treadmill/njZhRefmf6jQp',
                'dev_major': 253,
                'dev_minor': 3,
                'extent_alloc': -1,
                'extent_size': 125,
                'group': 'treadmill',
                'name': 'njZhRefmf6jQp',
                'open_count': 1,
            },
            {
                'block_dev': '/dev/treadmill/yRImNK9cnix2T',
                'dev_major': 253,
                'dev_minor': 4,
                'extent_alloc': -1,
                'extent_size': 25,
                'group': 'treadmill',
                'name': 'yRImNK9cnix2T',
                'open_count': 1,
            },
        ])