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)
def test_initialize_blk(self): """Test service initialization (block device). """ # pylint: disable=W0212 block_dev = '/dev/test' treadmill.lvm.vgactivate.side_effect = \ subproc.CalledProcessError(returncode=5, cmd='lvm') treadmill.lvm.lvsdisplay.return_value = [] localdiskutils.setup_device_lvm(block_dev) treadmill.lvm.vgactivate.assert_called_with(group='treadmill') # If provided, we should try to create the block device self.assertFalse(treadmill.localdiskutils.init_block_dev.called) treadmill.localdiskutils.init_vg.assert_called_with( 'treadmill', '/dev/test', )
def device(device_name): """Set up LVM on device""" try: localdiskutils.setup_device_lvm(device_name, ctx['vg_name']) except subproc.CommandAliasError: _LOGGER.error(_ALIAS_ERROR_MESSAGE)