Fix execution of upload-volume-to-image

While executing the image utils methods, we need to take
care not to use root privileges if the environment is running
in 'secure' mode.

This is a partial back-port of the fix committed in
Iae35c722eb4b6b7d02a95690abbc07a63da77ce7 in ocata.

Change-Id: I8a4912d10797ac8521acc27d02b97b00f8efdb7a
Closes-Bug: #1649209
This commit is contained in:
Goutham Pacha Ravi 2017-02-02 22:50:34 -05:00
parent 79ad4598aa
commit 7d2afb298a
2 changed files with 31 additions and 1 deletions

View File

@ -29,6 +29,35 @@ from cinder import utils
from cinder.volume.drivers import remotefs
@ddt.ddt
class RemoteFsDriverTestCase(test.TestCase):
def setUp(self):
super(RemoteFsDriverTestCase, self).setUp()
self._driver = remotefs.RemoteFSDriver()
self.context = context.get_admin_context()
self._fake_volume = fake_volume.fake_volume_obj(
self.context, provider_location='fake_share')
@ddt.data(True, False)
def test_copy_volume_to_image(self, run_as_root):
self._driver._execute_as_root = run_as_root
image_service = mock.Mock()
image_meta = {'some': 'metadata'}
local_path = '/mnt/cinder/xyzzy/some_volume'
self.mock_object(self._driver, 'local_path', mock.Mock(
return_value=local_path))
self.mock_object(image_utils, 'upload_volume')
self._driver.copy_volume_to_image(
self.context, self._fake_volume, image_service, image_meta)
image_utils.upload_volume.assert_called_once_with(
self.context, image_service, image_meta, local_path,
run_as_root=run_as_root)
@ddt.ddt
class RemoteFsSnapDriverTestCase(test.TestCase):

View File

@ -433,7 +433,8 @@ class RemoteFSDriver(driver.LocalVD, driver.TransferVD, driver.BaseVD):
image_utils.upload_volume(context,
image_service,
image_meta,
self.local_path(volume))
self.local_path(volume),
run_as_root=self._execute_as_root)
def _read_config_file(self, config_file):
# Returns list of lines in file