Merge "fuel-agent: check if lvcreate supports --yes switch"
This commit is contained in:
commit
ad0b102fca
@ -308,10 +308,41 @@ class TestLvmUtils(unittest2.TestCase):
|
||||
mock_vgdisplay.return_value = [{'name': 'vgname', 'free': 2000},
|
||||
{'name': 'some'}]
|
||||
mock_lvdisplay.return_value = [{'name': 'some'}]
|
||||
mock_exec.side_effect = [
|
||||
# pretend lvcreate supports --yes option
|
||||
('--yes', ''),
|
||||
('', '')
|
||||
]
|
||||
expected_calls = [
|
||||
mock.call('lvcreate', '--help'),
|
||||
mock.call('lvcreate', '--yes', '-L', '1000m',
|
||||
'-n', 'lvname', 'vgname',
|
||||
check_exit_code=[0])
|
||||
]
|
||||
lu.lvcreate('vgname', 'lvname', 1000)
|
||||
mock_exec.assert_called_once_with('lvcreate', '--yes', '-L', '1000m',
|
||||
'-n', 'lvname', 'vgname',
|
||||
check_exit_code=[0])
|
||||
self.assertEqual(mock_exec.call_args_list, expected_calls)
|
||||
|
||||
@mock.patch.object(lu, 'vgdisplay')
|
||||
@mock.patch.object(lu, 'lvdisplay')
|
||||
@mock.patch.object(utils, 'execute')
|
||||
def test_lvcreate_old_lvm(self, mock_exec, mock_lvdisplay, mock_vgdisplay):
|
||||
mock_vgdisplay.return_value = [{'name': 'vgname', 'free': 2000},
|
||||
{'name': 'some'}]
|
||||
mock_lvdisplay.return_value = [{'name': 'some'}]
|
||||
mock_exec.side_effect = [
|
||||
# pretend lvcreate does not support --yes option
|
||||
# (which is the case for Ubuntu 14.04)
|
||||
('--foo', ''),
|
||||
('', '')
|
||||
]
|
||||
expected_calls = [
|
||||
mock.call('lvcreate', '--help'),
|
||||
mock.call('lvcreate', '-L', '1000m',
|
||||
'-n', 'lvname', 'vgname',
|
||||
check_exit_code=[0])
|
||||
]
|
||||
lu.lvcreate('vgname', 'lvname', 1000)
|
||||
self.assertEqual(mock_exec.call_args_list, expected_calls)
|
||||
|
||||
@mock.patch.object(lu, 'vgdisplay')
|
||||
@mock.patch.object(utils, 'execute')
|
||||
@ -348,10 +379,15 @@ class TestLvmUtils(unittest2.TestCase):
|
||||
mock_vgdisplay.return_value = [{'name': 'vgname', 'free': 2000},
|
||||
{'name': 'some', 'free': 2000}]
|
||||
mock_lvdisplay.return_value = [{'name': 'lvname', 'vg': 'some'}]
|
||||
mock_exec.side_effect = [('--yes', ''), ('', '')]
|
||||
expected_calls = [
|
||||
mock.call('lvcreate', '--help'),
|
||||
mock.call('lvcreate', '--yes', '-L', '1000m',
|
||||
'-n', 'lvname', 'vgname',
|
||||
check_exit_code=[0])
|
||||
]
|
||||
lu.lvcreate('vgname', 'lvname', 1000)
|
||||
mock_exec.assert_called_once_with('lvcreate', '--yes', '-L', '1000m',
|
||||
'-n', 'lvname', 'vgname',
|
||||
check_exit_code=[0])
|
||||
self.assertEqual(mock_exec.call_args_list, expected_calls)
|
||||
|
||||
@mock.patch.object(utils, 'execute')
|
||||
def test_lvdisplay(self, mock_exec):
|
||||
|
@ -216,8 +216,14 @@ def lvcreate(vgname, lvname, size):
|
||||
# on allocated volume. '--yes' should be passed to avoid waiting for
|
||||
# user's confirmation:
|
||||
# "WARNING: <signature> signature detected on <device>. Wipe it? [y/n]"
|
||||
utils.execute('lvcreate', '--yes', '-L', '%sm' % size, '-n', lvname,
|
||||
vgname, check_exit_code=[0])
|
||||
# FIXME: the version of lvm2 shipped with Ubuntu 14.04 does not support
|
||||
# --yes option. fuel-agent should properly decomission the storage
|
||||
# (Ubuntu installer does that just fine).
|
||||
stdout, stderr = utils.execute('lvcreate', '--help')
|
||||
force_opt = '--yes' if '--yes' in stdout else ''
|
||||
cmd = 'lvcreate {force_opt} -L {size}m -n {lvname} {vgname}'.format(
|
||||
size=size, lvname=lvname, vgname=vgname, force_opt=force_opt)
|
||||
utils.execute(*cmd.split(), check_exit_code=[0])
|
||||
|
||||
|
||||
def lvremove(lvpath):
|
||||
|
Loading…
Reference in New Issue
Block a user