def test_create_creates_logical_volume_with_tags(self, lvsystem): lvsystem.add_volume_group('VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7') lvutil.create('volume', ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7', tag='hello') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals('hello', created_lv.tag)
def test_create_creates_logical_volume_with_tags(self, lvsystem): lvsystem.add_volume_group('vgroup') lvutil.create('volume', ONE_MEGABYTE, 'vgroup', tag='hello') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals('hello', created_lv.tag)
def test_create_volume_size(self, lvsystem): lvsystem.add_volume_group('vgroup') lvutil.create('volume', 100 * ONE_MEGABYTE, 'vgroup') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals(100, created_lv.size_mb)
def test_create_percentage_has_precedence_over_size(self, mock_pread2): lvutil.create('volume', ONE_MEGABYTE, 'vgroup', size_in_percentage="10%F") mock_pread2.assert_called_once_with([lvutil.CMD_LVCREATE] + "-n volume -l 10%F vgroup".split())
def create(self, lvName, size, tag = None): lvutil.create(lvName, size, self.vgName, tag) lvInfo = LVInfo(lvName) lvInfo.size = size lvInfo.active = True self.lvs[lvName] = lvInfo if tag: self._addTag(lvName, tag)
def test_create_percentage_has_precedence_over_size(self, mock_pread): lvutil.create('volume', ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7', size_in_percentage="10%F") self.assertEqual(1, mock_pread.call_count) self.assertIn("10%F", mock_pread.call_args[0][0])
def test_create_volume_size(self, lvsystem): lvsystem.add_volume_group('VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7') lvutil.create('volume', 100 * ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals(100, created_lv.size_mb)
def test_create_percentage_has_precedence_over_size(self, mock_pread): lvutil.create('volume', ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7', size_in_percentage="10%F") mock_pread.assert_called_once_with( [os.path.join(lvutil.LVM_BIN,lvutil.CMD_LVCREATE)] + "-n volume -l 10%F VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7".split(), quiet=False)
def create(self, lvName, size, tag=None): lvutil.create(lvName, size, self.vgName, tag) lvInfo = LVInfo(lvName) lvInfo.size = size lvInfo.active = True self.lvs[lvName] = lvInfo if tag: self._addTag(lvName, tag)
def do_trim(session, args): """Attempt to trim the given LVHDSR""" util.SMlog("do_trim: %s" % args) sr_uuid = args["sr_uuid"] os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF if TRIM_CAP not in util.sr_get_capability(sr_uuid): util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid) err_msg = { ERROR_CODE_KEY: 'UnsupportedSRForTrim', ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid } return to_xml(err_msg) # Lock SR, get vg empty space details sr_lock = lock.Lock(vhdutil.LOCK_TYPE_SR, sr_uuid) got_lock = False for i in range(LOCK_RETRY_ATTEMPTS): got_lock = sr_lock.acquireNoblock() if got_lock: break time.sleep(LOCK_RETRY_INTERVAL) if got_lock: try: vg_name = _vg_by_sr_uuid(sr_uuid) lv_name = sr_uuid + TRIM_LV_TAG lv_path = _lvpath_by_vg_lv_name(vg_name, lv_name) # Clean trim LV in case the previous trim attemp failed if lvutil.exists(lv_path): lvutil.remove(lv_path) #Check if VG limits are enough for creating LV. stats = lvutil._getVGstats(vg_name) if (stats['freespace'] < lvutil.LVM_SIZE_INCREMENT): util.SMlog("No space to claim on a full SR %s" % sr_uuid) err_msg = { ERROR_CODE_KEY: 'Trim failed on full SR', ERROR_MSG_KEY: 'No space to claim on a full SR' } result = to_xml(err_msg) else: # Perform a lvcreate, blkdiscard and lvremove to # trigger trim on the array lvutil.create(lv_name, 0, vg_name, size_in_percentage="100%F") cmd = ["/usr/sbin/blkdiscard", "-v", lv_path] stdout = util.pread2(cmd) util.SMlog("Stdout is %s" % stdout) util.SMlog("Trim on SR: %s complete. " % sr_uuid) result = str(True) except util.CommandException, e: err_msg = { ERROR_CODE_KEY: 'TrimException', ERROR_MSG_KEY: e.reason } result = to_xml(err_msg) except:
def do_trim(session, args): """Attempt to trim the given LVHDSR""" util.SMlog("do_trim: %s" % args) sr_uuid = args["sr_uuid"] os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF if TRIM_CAP not in util.sr_get_capability(sr_uuid): util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid) err_msg = {ERROR_CODE_KEY: 'UnsupportedSRForTrim', ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid} return to_xml(err_msg) # Lock SR, get vg empty space details sr_lock = lock.Lock(vhdutil.LOCK_TYPE_SR, sr_uuid) got_lock = False for i in range(LOCK_RETRY_ATTEMPTS): got_lock = sr_lock.acquireNoblock() if got_lock: break time.sleep(LOCK_RETRY_INTERVAL) if got_lock: try: vg_name = _vg_by_sr_uuid(sr_uuid) lv_name = sr_uuid + TRIM_LV_TAG lv_path = _lvpath_by_vg_lv_name(vg_name, lv_name) # Clean trim LV in case the previous trim attemp failed if lvutil.exists(lv_path): lvutil.remove(lv_path) #Check if VG limits are enough for creating LV. stats = lvutil._getVGstats(vg_name) if (stats['freespace'] < lvutil.LVM_SIZE_INCREMENT): util.SMlog("No space to claim on a full SR %s" % sr_uuid) err_msg = {ERROR_CODE_KEY: 'Trim failed on full SR', ERROR_MSG_KEY: 'No space to claim on a full SR'} result = to_xml(err_msg) else: # Perform a lvcreate, blkdiscard and lvremove to # trigger trim on the array lvutil.create(lv_name, 0, vg_name, size_in_percentage="100%F") cmd = ["/usr/sbin/blkdiscard", "-v", lv_path] stdout = util.pread2(cmd) util.SMlog("Stdout is %s" % stdout) util.SMlog("Trim on SR: %s complete. " % sr_uuid) result = str(True) except util.CommandException, e: err_msg = { ERROR_CODE_KEY: 'TrimException', ERROR_MSG_KEY: e.reason } result = to_xml(err_msg) except:
def test_create_percentage_has_precedence_over_size(self, mock_pread): lvutil.create('volume', ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7', size_in_percentage="10%F") mock_pread.assert_called_once_with( [os.path.join(lvutil.LVM_BIN, lvutil.CMD_LVCREATE)] + "-n volume -l 10%F VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7" .split(), quiet=False)
def do_trim(session, args): """Attempt to trim the given LVHDSR""" util.SMlog("do_trim: %s" % args) sr_uuid = args["sr_uuid"] if TRIM_CAP not in util.sr_get_capability(sr_uuid): util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid) err_msg = {ERROR_CODE_KEY: 'UnsupportedSRForTrim', ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid} return to_xml(err_msg) # Lock SR, get vg empty space details sr_lock = lock.Lock(vhdutil.LOCK_TYPE_SR, sr_uuid) got_lock = False for i in range(LOCK_RETRY_ATTEMPTS): got_lock = sr_lock.acquireNoblock() if got_lock: break time.sleep(LOCK_RETRY_INTERVAL) if got_lock: try: vg_name = _vg_by_sr_uuid(sr_uuid) lv_name = sr_uuid + TRIM_LV_TAG lv_path = _lvpath_by_vg_lv_name(vg_name, lv_name) # Clean trim LV in case the previous trim attemp failed if lvutil.exists(lv_path): lvutil.remove(lv_path) # Perform a lvcreate and lvremove to trigger trim on the array lvutil.create(lv_name, 0, vg_name, size_in_percentage="100%F") lvutil.remove(lv_path, config_param="issue_discards=1") util.SMlog("Trim on SR: %s complete. " % sr_uuid) result = str(True) except: err_msg = { ERROR_CODE_KEY: 'UnknownTrimException', ERROR_MSG_KEY: 'Unknown Exception: trim failed on SR [%s]' % sr_uuid } result = to_xml(err_msg) _log_last_triggered(session, sr_uuid) sr_lock.release() return result else: util.SMlog("Could not complete Trim on %s, Lock unavailable !" \ % sr_uuid) err_msg = {ERROR_CODE_KEY: 'SRUnavailable', ERROR_MSG_KEY: 'Unable to get SR lock [%s]' % sr_uuid} return to_xml(err_msg)
def test_create_volume_is_in_the_right_volume_group(self, lvsystem): lvsystem.add_volume_group('vgroup') lvutil.create('volume', 100 * ONE_MEGABYTE, 'vgroup') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals(100, created_lv.size_mb) self.assertEquals('vgroup', created_lv.volume_group.name) self.assertTrue(created_lv.active) self.assertTrue(created_lv.zeroed)
def test_create_volume_is_in_the_right_volume_group(self, lvsystem): lvsystem.add_volume_group('VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7') lvutil.create('volume', 100 * ONE_MEGABYTE, 'VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7') created_lv, = lvsystem.get_logical_volumes_with_name('volume') self.assertEquals(100, created_lv.size_mb) self.assertEquals('VG_XenStorage-b3b18d06-b2ba-5b67-f098-3cdd5087a2a7', created_lv.volume_group.name) self.assertTrue(created_lv.active) self.assertTrue(created_lv.zeroed)
def test_create_percentage_has_precedence_over_size(self, mock_pread2): lvutil.create('volume', ONE_MEGABYTE, 'vgroup', size_in_percentage="10%F") mock_pread2.assert_called_once_with( [lvutil.CMD_LVCREATE] + "-n volume -l 10%F vgroup".split())