Merge "Remove utils.execute() from libvirt remotefs calls."

This commit is contained in:
Zuul 2018-12-08 15:21:35 +00:00 committed by Gerrit Code Review
commit 4cbd7a2ad8
3 changed files with 49 additions and 38 deletions

View File

@ -18341,7 +18341,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
'_is_storage_shared_with'), return_value=False)
@mock.patch('os.rename')
@mock.patch('os.path.exists', return_value=True)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def _test_migrate_disk_and_power_off(
self, ctxt, flavor_obj, mock_execute, mock_exists, mock_rename,
mock_is_shared, mock_get_host_ip, mock_destroy,
@ -18484,7 +18484,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
self.drvr.migrate_disk_and_power_off,
None, instance, '10.0.0.1', flavor_obj, None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
@mock.patch('os.rename')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._destroy')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver'

View File

@ -58,7 +58,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
mock_umount.assert_has_calls(
[mock.call(mock.sentinel.mount_path)])
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_remove_remote_file_rsync(self, mock_execute):
remotefs.RsyncDriver().remove_file('host', 'dest', None, None)
rsync_call_args = mock.call('rsync', '--archive',
@ -76,7 +76,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
'host', 'rm', 'dest',
on_completion=None, on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_remove_remote_dir_rsync(self, mock_execute):
remotefs.RsyncDriver().remove_dir('host', 'dest', None, None)
rsync_call_args = mock.call('rsync', '--archive',
@ -99,7 +99,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
'host', 'rm', '-rf', 'dest', on_completion=None,
on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_create_remote_file_rsync(self, mock_execute):
remotefs.RsyncDriver().create_file('host', 'dest_dir', None, None)
mkdir_call_args = mock.call('mkdir', '-p', mock.ANY,
@ -123,7 +123,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None,
on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_create_remote_dir_rsync(self, mock_execute):
remotefs.RsyncDriver().create_dir('host', 'dest_dir', None, None)
mkdir_call_args = mock.call('mkdir', '-p', mock.ANY,
@ -144,7 +144,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None,
on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_remote_copy_file_rsync(self, mock_execute):
remotefs.RsyncDriver().copy_file('1.2.3.4:/home/star_wars',
'/home/favourite', None, None,
@ -156,7 +156,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None,
on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_remote_copy_file_rsync_without_compression(self, mock_execute):
remotefs.RsyncDriver().copy_file('1.2.3.4:/home/star_wars',
'/home/favourite', None, None,
@ -167,7 +167,7 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None,
on_execute=None)
@mock.patch('nova.utils.execute')
@mock.patch('oslo_concurrency.processutils.execute')
def test_remote_copy_file_ssh(self, mock_execute):
remotefs.SshDriver().copy_file('1.2.3.4:/home/SpaceOdyssey',
'/home/favourite', None, None, True)
@ -178,7 +178,8 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_execute=None)
def test_rsync_driver_ipv6(self):
with mock.patch('nova.utils.execute') as mock_execute:
with mock.patch(
'oslo_concurrency.processutils.execute') as mock_execute:
remotefs.RsyncDriver().create_file('2600::', 'dest_dir', None,
None)
rsync_call_args = mock.call('rsync', '--archive', '--relative',
@ -187,7 +188,8 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None, on_execute=None)
self.assertEqual(mock_execute.mock_calls[2], rsync_call_args)
with mock.patch('nova.utils.execute') as mock_execute:
with mock.patch(
'oslo_concurrency.processutils.execute') as mock_execute:
remotefs.RsyncDriver().create_dir('2600::', 'dest_dir', None, None)
rsync_call_args = mock.call('rsync', '--archive', '--relative',
'--no-implied-dirs',
@ -195,7 +197,8 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None, on_execute=None)
self.assertEqual(mock_execute.mock_calls[1], rsync_call_args)
with mock.patch('nova.utils.execute') as mock_execute:
with mock.patch(
'oslo_concurrency.processutils.execute') as mock_execute:
remotefs.RsyncDriver().remove_file('2600::', 'dest', None, None)
rsync_call_args = mock.call('rsync', '--archive',
'--delete', '--include',
@ -204,7 +207,8 @@ class RemoteFSTestCase(test.NoDBTestCase):
on_completion=None, on_execute=None)
self.assertEqual(mock_execute.mock_calls[0], rsync_call_args)
with mock.patch('nova.utils.execute') as mock_execute:
with mock.patch(
'oslo_concurrency.processutils.execute') as mock_execute:
remotefs.RsyncDriver().remove_dir('2600::', 'dest', None, None)
rsync_call_args = mock.call('rsync', '--archive',
'--delete-excluded', mock.ANY,

View File

@ -190,8 +190,9 @@ class SshDriver(RemoteFilesystemDriver):
def copy_file(self, src, dst, on_execute, on_completion, compression):
# As far as ploop disks are in fact directories we add '-r' argument
utils.execute('scp', '-r', src, dst,
on_execute=on_execute, on_completion=on_completion)
processutils.execute('scp', '-r', src, dst,
on_execute=on_execute,
on_completion=on_completion)
class RsyncDriver(RemoteFilesystemDriver):
@ -203,14 +204,16 @@ class RsyncDriver(RemoteFilesystemDriver):
# Create target dir inside temporary directory
local_tmp_dir = os.path.join(tempdir,
dir_path.strip(os.path.sep))
utils.execute('mkdir', '-p', local_tmp_dir,
on_execute=on_execute, on_completion=on_completion)
processutils.execute('mkdir', '-p', local_tmp_dir,
on_execute=on_execute,
on_completion=on_completion)
# Create file in directory
file_name = os.path.basename(os.path.normpath(dst_path))
local_tmp_file = os.path.join(local_tmp_dir, file_name)
utils.execute('touch', local_tmp_file,
on_execute=on_execute, on_completion=on_completion)
processutils.execute('touch', local_tmp_file,
on_execute=on_execute,
on_completion=on_completion)
RsyncDriver._synchronize_object(tempdir,
host, dst_path,
on_execute=on_execute,
@ -229,8 +232,9 @@ class RsyncDriver(RemoteFilesystemDriver):
# Create target dir inside temporary directory
local_tmp_dir = os.path.join(tempdir,
dir_path.strip(os.path.sep))
utils.execute('mkdir', '-p', local_tmp_dir,
on_execute=on_execute, on_completion=on_completion)
processutils.execute('mkdir', '-p', local_tmp_dir,
on_execute=on_execute,
on_completion=on_completion)
RsyncDriver._synchronize_object(tempdir,
host, dst_path,
on_execute=on_execute,
@ -239,10 +243,11 @@ class RsyncDriver(RemoteFilesystemDriver):
def remove_dir(self, host, dst, on_execute, on_completion):
# Remove remote directory's content
with utils.tempdir() as tempdir:
utils.execute('rsync', '--archive', '--delete-excluded',
tempdir + os.path.sep,
utils.format_remote_path(host, dst),
on_execute=on_execute, on_completion=on_completion)
processutils.execute('rsync', '--archive', '--delete-excluded',
tempdir + os.path.sep,
utils.format_remote_path(host, dst),
on_execute=on_execute,
on_completion=on_completion)
# Delete empty directory
RsyncDriver._remove_object(tempdir, host, dst,
@ -260,13 +265,14 @@ class RsyncDriver(RemoteFilesystemDriver):
:param on_completion: Callback method to remove pid of process from
cache
"""
utils.execute('rsync', '--archive', '--delete',
'--include', os.path.basename(os.path.normpath(dst)),
'--exclude', '*',
os.path.normpath(src) + os.path.sep,
utils.format_remote_path(host,
os.path.dirname(os.path.normpath(dst))),
on_execute=on_execute, on_completion=on_completion)
processutils.execute(
'rsync', '--archive', '--delete',
'--include', os.path.basename(os.path.normpath(dst)),
'--exclude', '*',
os.path.normpath(src) + os.path.sep,
utils.format_remote_path(host,
os.path.dirname(os.path.normpath(dst))),
on_execute=on_execute, on_completion=on_completion)
@staticmethod
def _synchronize_object(src, host, dst, on_execute, on_completion):
@ -293,15 +299,16 @@ class RsyncDriver(RemoteFilesystemDriver):
os.path.normpath(dst).strip(os.path.sep))
# Do relative rsync local directory with remote root directory
utils.execute('rsync', '--archive', '--relative', '--no-implied-dirs',
relative_tmp_file_path,
utils.format_remote_path(host, os.path.sep),
on_execute=on_execute, on_completion=on_completion)
processutils.execute(
'rsync', '--archive', '--relative', '--no-implied-dirs',
relative_tmp_file_path,
utils.format_remote_path(host, os.path.sep),
on_execute=on_execute, on_completion=on_completion)
def copy_file(self, src, dst, on_execute, on_completion, compression):
# As far as ploop disks are in fact directories we add '-r' argument
args = ['rsync', '-r', '--sparse', src, dst]
if compression:
args.append('--compress')
utils.execute(*args,
on_execute=on_execute, on_completion=on_completion)
processutils.execute(
*args, on_execute=on_execute, on_completion=on_completion)