Fix lvm volume creation in fuel-agent

lvm_utils.lvcreate totally ignores volume group from which volume was
being allocated when checking for volume existance. If another volume
from another volume group has the same name it will fail to create
volume throwing "volume already exists" error.

Change-Id: Ib2e10f558f7de976b72ea75e2cae4ff0c3ed98d3
Closes-Bug: #1412464
This commit is contained in:
Alexander Gordeev 2015-01-19 18:30:23 +03:00
parent 2f6c37569a
commit 64eff72cad
2 changed files with 17 additions and 2 deletions

View File

@ -335,10 +335,24 @@ class TestLvmUtils(test_base.BaseTestCase):
mock_vgdisplay):
mock_vgdisplay.return_value = [{'name': 'vgname', 'free': 2000},
{'name': 'some'}]
mock_lvdisplay.return_value = [{'name': 'lvname'}]
mock_lvdisplay.return_value = [{'name': 'lvname', 'vg': 'vgname'}]
self.assertRaises(errors.LVAlreadyExistsError, lu.lvcreate, 'vgname',
'lvname', 1000)
@mock.patch.object(lu, 'vgdisplay')
@mock.patch.object(lu, 'lvdisplay')
@mock.patch.object(utils, 'execute')
def test_lvcreate_lv_name_collision(self, mock_exec, mock_lvdisplay,
mock_vgdisplay):
# lv lvname already exists in another pv
mock_vgdisplay.return_value = [{'name': 'vgname', 'free': 2000},
{'name': 'some', 'free': 2000}]
mock_lvdisplay.return_value = [{'name': 'lvname', 'vg': 'some'}]
lu.lvcreate('vgname', 'lvname', 1000)
mock_exec.assert_called_once_with('lvcreate', '-L', '1000m', '-n',
'lvname', 'vgname',
check_exit_code=[0])
@mock.patch.object(utils, 'execute')
def test_lvdisplay(self, mock_exec):
mock_exec.return_value = [

View File

@ -208,7 +208,8 @@ def lvcreate(vgname, lvname, size):
'Error while creating lv: vg %s has only %s m of free space, '
'but at least %s m is needed' % (vgname, vg[0]['free'], size))
# check if lv already exists
if filter(lambda x: x['name'] == lvname, lvdisplay()):
if filter(lambda x: x['name'] == lvname and x['vg'] == vgname,
lvdisplay()):
raise errors.LVAlreadyExistsError(
'Error while creating lv: lv %s already exists' % lvname)
utils.execute('lvcreate', '-L', '%sm' % size, '-n', lvname,