From 64eff72cad9cd1f6fa9b9946a516bb30ac425d86 Mon Sep 17 00:00:00 2001 From: Alexander Gordeev Date: Mon, 19 Jan 2015 18:30:23 +0300 Subject: [PATCH] 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 --- fuel_agent/tests/test_lvm_utils.py | 16 +++++++++++++++- fuel_agent/utils/lvm_utils.py | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fuel_agent/tests/test_lvm_utils.py b/fuel_agent/tests/test_lvm_utils.py index d33a7be..b1b16b7 100644 --- a/fuel_agent/tests/test_lvm_utils.py +++ b/fuel_agent/tests/test_lvm_utils.py @@ -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 = [ diff --git a/fuel_agent/utils/lvm_utils.py b/fuel_agent/utils/lvm_utils.py index 6d1633e..8dc2a29 100644 --- a/fuel_agent/utils/lvm_utils.py +++ b/fuel_agent/utils/lvm_utils.py @@ -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,