Merge "Change sudo to run_as_root in LVM driver"
This commit is contained in:
commit
0a354c7c6e
@ -47,7 +47,8 @@ lvextend: CommandFilter, lvextend, root
|
|||||||
# manila/share/drivers/lvm.py: 'lvcreate', '-L', %s, '-n', %s
|
# manila/share/drivers/lvm.py: 'lvcreate', '-L', %s, '-n', %s
|
||||||
lvcreate: CommandFilter, lvcreate, root
|
lvcreate: CommandFilter, lvcreate, root
|
||||||
|
|
||||||
# manila/share/drivers/lvm.py: 'vgs', %s, '--rows'
|
# manila/share/drivers/lvm.py: 'vgs', '--noheadings', '-o', 'name'
|
||||||
|
# manila/share/drivers/lvm.py: 'vgs', %s, '--rows', '--units', 'g'
|
||||||
vgs: CommandFilter, vgs, root
|
vgs: CommandFilter, vgs, root
|
||||||
|
|
||||||
# manila/share/drivers/glusterfs.py: 'mkdir', '%s'
|
# manila/share/drivers/glusterfs.py: 'mkdir', '%s'
|
||||||
|
@ -67,7 +67,8 @@ CONF.register_opts(generic.share_opts)
|
|||||||
class LVMMixin(driver.ExecuteMixin):
|
class LVMMixin(driver.ExecuteMixin):
|
||||||
def check_for_setup_error(self):
|
def check_for_setup_error(self):
|
||||||
"""Returns an error if prerequisites aren't met."""
|
"""Returns an error if prerequisites aren't met."""
|
||||||
out, err = self._execute('sudo', 'vgs', '--noheadings', '-o', 'name')
|
out, err = self._execute('vgs', '--noheadings', '-o', 'name',
|
||||||
|
run_as_root=True)
|
||||||
volume_groups = out.split()
|
volume_groups = out.split()
|
||||||
if self.configuration.lvm_share_volume_group not in volume_groups:
|
if self.configuration.lvm_share_volume_group not in volume_groups:
|
||||||
msg = (_("share volume group %s doesn't exist")
|
msg = (_("share volume group %s doesn't exist")
|
||||||
@ -190,9 +191,10 @@ class LVMShareDriver(LVMMixin, driver.ShareDriver):
|
|||||||
super(LVMShareDriver, self)._update_share_stats(data)
|
super(LVMShareDriver, self)._update_share_stats(data)
|
||||||
|
|
||||||
def get_share_server_pools(self, share_server=None):
|
def get_share_server_pools(self, share_server=None):
|
||||||
out, err = self._execute('sudo', 'vgs',
|
out, err = self._execute('vgs',
|
||||||
self.configuration.lvm_share_volume_group,
|
self.configuration.lvm_share_volume_group,
|
||||||
'--rows', '--units', 'g')
|
'--rows', '--units', 'g',
|
||||||
|
run_as_root=True)
|
||||||
total_size = re.findall("VSize\s[0-9.]+g", out)[0][6:-1]
|
total_size = re.findall("VSize\s[0-9.]+g", out)[0][6:-1]
|
||||||
free_size = re.findall("VFree\s[0-9.]+g", out)[0][6:-1]
|
free_size = re.findall("VFree\s[0-9.]+g", out)[0][6:-1]
|
||||||
return [{
|
return [{
|
||||||
|
@ -124,9 +124,7 @@ class LVMShareDriverTestCase(test.TestCase):
|
|||||||
def exec_runner(*ignore_args, **ignore_kwargs):
|
def exec_runner(*ignore_args, **ignore_kwargs):
|
||||||
return '\n fake1\n fakevg\n fake2\n', ''
|
return '\n fake1\n fakevg\n fake2\n', ''
|
||||||
|
|
||||||
expected_exec = [
|
expected_exec = ['vgs --noheadings -o name']
|
||||||
'sudo vgs --noheadings -o name',
|
|
||||||
]
|
|
||||||
fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)])
|
fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)])
|
||||||
self._driver.check_for_setup_error()
|
self._driver.check_for_setup_error()
|
||||||
self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
|
self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
|
||||||
@ -135,7 +133,7 @@ class LVMShareDriverTestCase(test.TestCase):
|
|||||||
def exec_runner(*ignore_args, **ignore_kwargs):
|
def exec_runner(*ignore_args, **ignore_kwargs):
|
||||||
return '\n fake0\n fake1\n fake2\n', ''
|
return '\n fake0\n fake1\n fake2\n', ''
|
||||||
|
|
||||||
fake_utils.fake_execute_set_repliers([('sudo vgs --noheadings -o name',
|
fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name',
|
||||||
exec_runner)])
|
exec_runner)])
|
||||||
self.assertRaises(exception.InvalidParameterValue,
|
self.assertRaises(exception.InvalidParameterValue,
|
||||||
self._driver.check_for_setup_error)
|
self._driver.check_for_setup_error)
|
||||||
@ -144,7 +142,7 @@ class LVMShareDriverTestCase(test.TestCase):
|
|||||||
def exec_runner(*ignore_args, **ignore_kwargs):
|
def exec_runner(*ignore_args, **ignore_kwargs):
|
||||||
return '\n fake1\n fakevg\n fake2\n', ''
|
return '\n fake1\n fakevg\n fake2\n', ''
|
||||||
|
|
||||||
fake_utils.fake_execute_set_repliers([('sudo vgs --noheadings -o name',
|
fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name',
|
||||||
exec_runner)])
|
exec_runner)])
|
||||||
CONF.set_default('lvm_share_export_ip', None)
|
CONF.set_default('lvm_share_export_ip', None)
|
||||||
self.assertRaises(exception.InvalidParameterValue,
|
self.assertRaises(exception.InvalidParameterValue,
|
||||||
@ -485,7 +483,7 @@ class LVMShareDriverTestCase(test.TestCase):
|
|||||||
self.assertEqual(expected_result,
|
self.assertEqual(expected_result,
|
||||||
self._driver.get_share_server_pools())
|
self._driver.get_share_server_pools())
|
||||||
self._driver._execute.assert_called_once_with(
|
self._driver._execute.assert_called_once_with(
|
||||||
'sudo', 'vgs', 'fakevg', '--rows', '--units', 'g')
|
'vgs', 'fakevg', '--rows', '--units', 'g', run_as_root=True)
|
||||||
|
|
||||||
def test_copy_volume_error(self):
|
def test_copy_volume_error(self):
|
||||||
def _fake_exec(*args, **kwargs):
|
def _fake_exec(*args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user