Esempio n. 1
0
 def test_delete_lv(self):
     """Delete an LV; return True."""
     lv_name = 'testlv06'
     lv_size = 1
     lvm = SpokeLVM(self.vg_name)
     lvm.create(lv_name, lv_size)
     self.assertFalse(lvm.delete(lv_name)['data'])
Esempio n. 2
0
 def test_delete_lv(self):
     """Delete an LV; return True."""
     lv_name = 'testlv06'
     lv_size = 1
     lvm = SpokeLVM(self.vg_name)
     lvm.create(lv_name, lv_size)
     self.assertFalse(lvm.delete(lv_name)['data'])
Esempio n. 3
0
File: lvm.py Progetto: mattmb/spoke
def create(vg_name, lv_name, lv_size):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    try:
        result = lv.create(lv_name, lv_size)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Esempio n. 4
0
File: lvm.py Progetto: mattmb/spoke
def search(vg_name, lv_name=None):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    try:
        result = lv.get(lv_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Esempio n. 5
0
File: lvm.py Progetto: mattmb/spoke
def search(vg_name, lv_name=None):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    try:
        result = lv.get(lv_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Esempio n. 6
0
File: lvm.py Progetto: mattmb/spoke
def create(vg_name, lv_name, lv_size):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    try:
        result = lv.create(lv_name, lv_size)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Esempio n. 7
0
 def test_create_lv(self):
     """Create LV; return results object."""
     lv_name = 'testlv03'
     lv_size = 1
     expected_result = [{'lv_size':self.lv_size_fmt,'lv_name':lv_name}]
     lvm = SpokeLVM(self.vg_name)
     result = lvm.create(lv_name, lv_size)['data']
     self.assertEqual(result, expected_result)
     lvm.delete(lv_name)
Esempio n. 8
0
 def test_create_lv(self):
     """Create LV; return results object."""
     lv_name = 'testlv03'
     lv_size = 1
     expected_result = [{'lv_size': self.lv_size_fmt, 'lv_name': lv_name}]
     lvm = SpokeLVM(self.vg_name)
     result = lvm.create(lv_name, lv_size)['data']
     self.assertEqual(result, expected_result)
     lvm.delete(lv_name)
Esempio n. 9
0
def create(lv_name, lv_size, vg_name=None):
    try:
        conf = _spoke_config(_salt_config('config'))
        if not vg_name:
            vg_name = conf.get('LVM', 'lv_def_vg_name')
        lv = SpokeLVM(vg_name)
        result = lv.create(lv_name, lv_size)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Esempio n. 10
0
File: lvm.py Progetto: mattmb/spoke
def delete(vg_name, lv_name, force=False):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    if force is True:
        try:
            result = lv.delete(lv_name)
        except error.SpokeError as e:
            result = common.handle_error(e)
    else:
        result = "Set force=True to delete %s from group %s" % (lv_name,
                                                                vg_name)
    return result
Esempio n. 11
0
File: lvm.py Progetto: mattmb/spoke
def delete(vg_name, lv_name, force=False):
    from spoke.lib.lvm import SpokeLVM
    lv = SpokeLVM(vg_name)
    if force is True:
        try:
            result = lv.delete(lv_name)
        except error.SpokeError as e:
            result = common.handle_error(e)
    else:
        result = "Set force=True to delete %s from group %s" % (lv_name, vg_name)
    return result

    
Esempio n. 12
0
def delete(lv_name, force=False, vg_name=None):
    conf = _spoke_config(_salt_config('config'))
    if not vg_name:
        vg_name = conf.get('LVM', 'lv_def_vg_name')
    if force:
        try:
            lv = SpokeLVM(vg_name)
            result = lv.delete(lv_name)
        except error.SpokeError as e:
            result = common.handle_error(e)
    else:
        result = "Set force=True to delete %s from group %s" %\
            (lv_name, vg_name)
    return result
Esempio n. 13
0
class SpokeLVMTest(unittest.TestCase):
    def __init__(self, methodName):
        """Setup config data."""
        unittest.TestCase.__init__(self, methodName)
        common_config = '../../contrib/spoke.conf'
        custom_config = '/tmp/spoke.conf'
        config_files = (common_config, custom_config)
        self.config = config.setup(config_files)
        self.lv_units = self.config.get('LVM', 'lv_units')
        self.lv_name = 'testlv01'
        self.lv_size = 1
        self.TWOPLACES = decimal.Decimal(10)**-2  # same as Decimal('0.01')
        self.lv_size_dec = str(
            decimal.Decimal(self.lv_size).quantize(self.TWOPLACES))
        self.lv_size_fmt = self.lv_size_dec + self.lv_units.upper()
        self.vg_name = test_vg_name
        # If we don't get an empty volume group here, abort
        try:
            self.lvm = SpokeLVM(self.vg_name)
            lv_list = self.lvm.get()['data']
        except Exception, e:
            print 'Exception'
            print e
            sys.exit(1)
        if lv_list != []:
            print 'Volume group %s is not empty' % self.vg_name
            sys.exit(1)
Esempio n. 14
0
 def test_create_too_large_lv(self):
     """Create an LV with size greater than in VG; raise InsufficientResource."""
     lv_name = 'testlv05'
     lv_size = 100
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.InsufficientResource, lvm.create, lv_name,
                       lv_size)
Esempio n. 15
0
class SpokeLVMTest(unittest.TestCase):
    
    def __init__(self, methodName):
        """Setup config data."""
        unittest.TestCase.__init__(self, methodName)
        common_config = '../../contrib/spoke.conf'
        custom_config = '/tmp/spoke.conf'
        config_files = (common_config, custom_config)
        self.config = config.setup(config_files)
        self.lv_units = self.config.get('LVM', 'lv_units')
        self.lv_name = 'testlv01'
        self.lv_size = 1
        self.TWOPLACES = decimal.Decimal(10) ** -2  # same as Decimal('0.01')
        self.lv_size_dec = str(decimal.Decimal(self.lv_size).quantize(self.TWOPLACES))
        self.lv_size_fmt = self.lv_size_dec + self.lv_units.upper()
        self.vg_name = test_vg_name
        # If we don't get an empty volume group here, abort
        try:
            self.lvm = SpokeLVM(self.vg_name)
            lv_list = self.lvm.get()['data']
        except Exception, e:
            print 'Exception'
            print e
            sys.exit(1)
        if lv_list != []:
            print 'Volume group %s is not empty' % self.vg_name
            sys.exit(1)
Esempio n. 16
0
 def test_get_multiple_lvs(self):
     """Search for all LVs; return list."""
     lv_name = 'testlv02'
     lv_size = 2
     lv_size_dec = str(decimal.Decimal(lv_size).quantize(self.TWOPLACES))
     lv_size_fmt = lv_size_dec + self.lv_units.upper()
     lvm = SpokeLVM(self.vg_name)
     lvm.create(lv_name, lv_size)
     result = lvm.get()['data']
     expected_result = [{
         'lv_size': self.lv_size_fmt,
         'lv_name': self.lv_name
     }, {
         'lv_size': lv_size_fmt,
         'lv_name': lv_name
     }]
     self.assertEqual(result, expected_result)
     lvm.delete(lv_name)
Esempio n. 17
0
 def test_get_multiple_lvs(self):
     """Search for all LVs; return list."""
     lv_name = 'testlv02'
     lv_size = 2
     lv_size_dec = str(decimal.Decimal(lv_size).quantize(self.TWOPLACES))
     lv_size_fmt = lv_size_dec + self.lv_units.upper()
     lvm = SpokeLVM(self.vg_name)
     lvm.create(lv_name, lv_size)
     result = lvm.get()['data']
     expected_result = [{'lv_size':self.lv_size_fmt,
                         'lv_name':self.lv_name},
                        {'lv_size': lv_size_fmt,
                         'lv_name': lv_name}]
     self.assertEqual(result, expected_result)
     lvm.delete(lv_name)
Esempio n. 18
0
 def test_get_invalid_lv(self):
     """Search for an LV with an invalid name; raise InputError."""
     lv_name = 'du$$_lv'
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.InputError, lvm.get, lv_name)
Esempio n. 19
0
 def test_create_invalid_lv(self):
     """Create an LV with an invalid name; raise InputError."""
     lv_name = 'du$$_lv'
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.InputError, lvm.create, lv_name, self.lv_size)
Esempio n. 20
0
 def test_create_existing_lv(self):
     """Create existing LV; raise AlreadyExists."""
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.AlreadyExists, lvm.create, self.lv_name,
                       self.lv_size)
Esempio n. 21
0
 def test_create_invalid_size_lv(self):
     """Create an LV with an invalid size; raise InputError."""
     lv_name = 'testlv04'
     lv_size = 1000
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.InputError, lvm.create, lv_name, lv_size)
Esempio n. 22
0
 def test_delete_missing_lv(self):
     """Delete a missing LV; raise NotFound."""
     lv_name = 'testlv07'
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.NotFound, lvm.delete, lv_name)
Esempio n. 23
0
 def test_delete_invalid_lv(self):
     lv_name = 'du$$_lv'
     lvm = SpokeLVM(self.vg_name)
     self.assertRaises(error.InputError, lvm.delete, lv_name)
Esempio n. 24
0
 def test_get_missing_vg(self):
     """Search for an LV in a missing VG; raise MissingLVGroup."""
     vg_name = 'missing_vg'
     lvm = SpokeLVM(vg_name)
     self.assertRaises(error.NotFound, lvm.get, self.lv_name)
Esempio n. 25
0
config = config.setup(config_file)
    
if __name__ == '__main__':
    mc = mc.MCollectiveAction()
    log = logger.setup('main', verbose=False, quiet=True)
    request = mc.request()
    try:
        vg_name = config.get('LVM', 'lv_def_vg_name')
    except error.SpokeError:
        mc.fail("Failed to retrieve lv_def_vg_name value from config", 2)

    if request['action'] == 'create':
        lv_name = request['data']['lv_name']
        lv_size = request['data']['lv_size']
        try:
            mc.data = SpokeLVM(vg_name).create(lv_name, lv_size)
        except error.SpokeError as e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'search':
        try:
            lv_name = request['data']['lv_name']
        except KeyError:
            lv_name = None
        try:
            mc.data = SpokeLVM(vg_name).get(lv_name)
        except error.SpokeError as e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'delete':
        try:
            lv_name = request['data']['lv_name']
        except KeyError: