def download(self, context, url_parts, dst_file, metadata, **kwargs): self.filesystems = self._get_options() if not self.filesystems: #NOTE(jbresnah) when nothing is configured assume legacy behavior nova_mountpoint = '/' glance_mountpoint = '/' else: self._verify_config() fs_descriptor = self._file_system_lookup(metadata, url_parts) if fs_descriptor is None: msg = (_('No matching ID for the URL %s was found.') % url_parts.geturl()) raise exception.ImageDownloadModuleError(reason=msg, module=str(self)) nova_mountpoint = fs_descriptor['mountpoint'] glance_mountpoint = metadata['mountpoint'] source_file = self._normalize_destination(nova_mountpoint, glance_mountpoint, url_parts.path) lv_utils.copy_image(source_file, dst_file) LOG.info( _('Copied %(source_file)s using %(module_str)s') % { 'source_file': source_file, 'module_str': str(self) })
def test_copy_image_rsync(self, mock_execute): libvirt_utils.copy_image("src", "dest", host="host") mock_execute.assert_has_calls( [self._rsync_call("--dry-run", "src", "host:dest"), self._rsync_call("src", "host:dest")] ) self.assertEqual(2, mock_execute.call_count)
def create_ploop_image(base, target, size): image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) utils.execute('ploop', 'restore-descriptor', '-f', self.pcs_format, target, image_path) if size: self.resize_image(size)
def test_copy_image_remote_rsync(self, mock_rem_fs_remove): self.flags(remote_filesystem_transport='rsync', group='libvirt') libvirt_utils.copy_image('src', 'dest', host='host') mock_rem_fs_remove.assert_called_once_with('src', 'host:dest', on_completion=None, on_execute=None)
def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) if size: # class Raw is misnamed, format may not be 'raw' in all cases image = imgmodel.LocalFileImage(target, self.driver_format) disk.extend(image, size)
def create_ploop_image(base, target, size): image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) utils.execute("ploop", "restore-descriptor", "-f", self.pcs_format, target, image_path) if size: dd_path = os.path.join(self.path, "DiskDescriptor.xml") utils.execute("ploop", "grow", "-s", "%dK" % (size >> 10), dd_path, run_as_root=True)
def _cache_image(fn, target, fname, cow=False, *args, **kwargs): """Wrapper for a method that creates an image that caches the image. This wrapper will save the image into a common store and create a copy for use by the hypervisor. The underlying method should specify a kwarg of target representing where the image will be saved. fname is used as the filename of the base image. The filename needs to be unique to a given image. If cow is True, it will make a CoW image instead of a copy. """ if not os.path.exists(target): base_dir = os.path.join(FLAGS.instances_path, "_base") if not os.path.exists(base_dir): libvirt_utils.ensure_tree(base_dir) base = os.path.join(base_dir, fname) @utils.synchronized(fname) def call_if_not_exists(base, fn, *args, **kwargs): if not os.path.exists(base): fn(target=base, *args, **kwargs) call_if_not_exists(base, fn, *args, **kwargs) if cow: libvirt_utils.create_cow_image(base, target) else: libvirt_utils.copy_image(base, target)
def _cache_image(fn, target, fname, cow=False, *args, **kwargs): """Wrapper for a method that creates an image that caches the image. This wrapper will save the image into a common store and create a copy for use by the hypervisor. The underlying method should specify a kwarg of target representing where the image will be saved. fname is used as the filename of the base image. The filename needs to be unique to a given image. If cow is True, it will make a CoW image instead of a copy. """ if not os.path.exists(target): base_dir = os.path.join(FLAGS.instances_path, '_base') if not os.path.exists(base_dir): libvirt_utils.ensure_tree(base_dir) base = os.path.join(base_dir, fname) @utils.synchronized(fname) def call_if_not_exists(base, fn, *args, **kwargs): if not os.path.exists(base): fn(target=base, *args, **kwargs) call_if_not_exists(base, fn, *args, **kwargs) if cow: libvirt_utils.create_cow_image(base, target) else: libvirt_utils.copy_image(base, target)
def test_copy_image_rsync_ipv6(self, mock_execute): libvirt_utils.copy_image('src', 'dest', host='2600::') mock_execute.assert_has_calls([ self._rsync_call('--dry-run', 'src', '[2600::]:dest'), self._rsync_call('src', '[2600::]:dest'), ]) self.assertEqual(2, mock_execute.call_count)
def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) time_ref = time.time() time_prev = time_ref if size: image = imgmodel.LocalFileImage(target, self.driver_format) disk.extend(image, size) print 'whr [cr im] 0 %0.06f' % (time.time() - time_prev)
def test_copy_image_scp(self, mock_execute): mock_execute.side_effect = [processutils.ProcessExecutionError, mock.DEFAULT] libvirt_utils.copy_image("src", "dest", host="host") mock_execute.assert_has_calls( [self._rsync_call("--dry-run", "src", "host:dest"), mock.call("scp", "src", "host:dest")] ) self.assertEqual(2, mock_execute.call_count)
def create_ploop_image(base, target, size): image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) utils.execute('ploop', 'restore-descriptor', '-f', self.pcs_format, target, image_path) if size: dd_path = os.path.join(self.path, "DiskDescriptor.xml") utils.execute('ploop', 'grow', '-s', '%dK' % (size >> 10), dd_path, run_as_root=True)
def create_image(self, prepare_template, base, size, *args, **kwargs): filename = self._get_lock_name(base) @utils.synchronized(filename, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. #libvirt_utils.create_cow_image(base, target) disk_format = kwargs.get('disk_format', '') if disk_format == 'iso': libvirt_utils.create_image('qcow2', target, size) else: libvirt_utils.create_cow_image(base, target) if size: image = imgmodel.LocalFileImage(target, imgmodel.FORMAT_QCOW2) disk.extend(image, size) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, *args, **kwargs) # NOTE(ankit): Update the mtime of the base file so the image # cache manager knows it is in use. libvirt_utils.update_mtime(base) self.verify_base_size(base, size) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition('_') if backing_file != backing_parts[-1] and \ backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += '_%d' % legacy_backing_size legacy_backing_size *= units.Gi # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) image = imgmodel.LocalFileImage(legacy_base, imgmodel.FORMAT_QCOW2) disk.extend(image, legacy_backing_size) if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def copy_qcow2_image(base, target, size): qcow2_base = base if size: size_gb = size / (1024 * 1024 * 1024) qcow2_base += '_%d' % size_gb if not os.path.exists(qcow2_base): with utils.remove_path_on_error(qcow2_base): libvirt_utils.copy_image(base, qcow2_base) disk.extend(qcow2_base, size) libvirt_utils.create_cow_image(qcow2_base, target)
def _copy_ploop_image(base, target, size): # Ploop disk is a directory with data file(root.hds) and # DiskDescriptor.xml, so create this dir fileutils.ensure_tree(target) image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) nova.privsep.libvirt.ploop_restore_descriptor( target, image_path, self.pcs_format) if size: self.resize_image(size)
def _copy_ploop_image(base, target, size): # Ploop disk is a directory with data file(root.hds) and # DiskDescriptor.xml, so create this dir fileutils.ensure_tree(target) image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) utils.execute('ploop', 'restore-descriptor', '-f', self.pcs_format, target, image_path) if size: self.resize_image(size)
def create_image(self, prepare_template, base, size, *args, **kwargs): @utils.synchronized(base, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. libvirt_utils.create_cow_image(base, target) if size: disk.extend(target, size) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, *args, **kwargs) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition('_') if backing_file != backing_parts[-1] and \ backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += '_%d' % legacy_backing_size legacy_backing_size *= 1024 * 1024 * 1024 # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) disk.extend(legacy_base, legacy_backing_size) # NOTE(cfb): Having a flavor that sets the root size to 0 and having # nova effectively ignore that size and use the size of the # image is considered a feature at this time, not a bug. disk_size = disk.get_disk_size(base) if size and size < disk_size: msg = _('%(base)s virtual size %(disk_size)s' 'larger than flavor root disk size %(size)s') LOG.error(msg % { 'base': base, 'disk_size': disk_size, 'size': size }) raise exception.InstanceTypeDiskTooSmall() if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def _copy_ploop_image(base, target, size): # Ploop disk is a directory with data file(root.hds) and # DiskDescriptor.xml, so create this dir fileutils.ensure_tree(target) image_path = os.path.join(target, "root.hds") libvirt_utils.copy_image(base, image_path) nova.privsep.libvirt.ploop_restore_descriptor(target, image_path, self.pcs_format) if size: self.resize_image(size)
def create_image(self, prepare_template, base, size, *args, **kwargs): @utils.synchronized(base, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. libvirt_utils.create_cow_image(base, target) if size: disk.extend(target, size, use_cow=True) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, *args, **kwargs) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition('_') if backing_file != backing_parts[-1] and \ backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += '_%d' % legacy_backing_size legacy_backing_size *= 1024 * 1024 * 1024 # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) disk.extend(legacy_base, legacy_backing_size, use_cow=True) # NOTE(cfb): Having a flavor that sets the root size to 0 and having # nova effectively ignore that size and use the size of the # image is considered a feature at this time, not a bug. disk_size = disk.get_disk_size(base) if size and size < disk_size: msg = _('%(base)s virtual size %(disk_size)s' 'larger than flavor root disk size %(size)s') LOG.error(msg % {'base': base, 'disk_size': disk_size, 'size': size}) raise exception.InstanceTypeDiskTooSmall() if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def test_copy_image_scp(self, mock_execute): mock_execute.side_effect = [ processutils.ProcessExecutionError, mock.DEFAULT, ] libvirt_utils.copy_image('src', 'dest', host='host') mock_execute.assert_has_calls([ self._rsync_call('--dry-run', 'src', 'host:dest'), mock.call('scp', 'src', 'host:dest'), ]) self.assertEqual(2, mock_execute.call_count)
def create_image(self, prepare_template, base, size, *args, **kwargs): filename = self._get_lock_name(base) @utils.synchronized(filename, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. libvirt_utils.create_cow_image(base, target) if size: image = imgmodel.LocalFileImage(target, imgmodel.FORMAT_QCOW2) disk.extend(image, size) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, max_size=size, *args, **kwargs) # NOTE(ankit): Update the mtime of the base file so the image # cache manager knows it is in use. libvirt_utils.update_mtime(base) self.verify_base_size(base, size) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition('_') if backing_file != backing_parts[-1] and \ backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += '_%d' % legacy_backing_size legacy_backing_size *= units.Gi # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) image = imgmodel.LocalFileImage(legacy_base, imgmodel.FORMAT_QCOW2) disk.extend(image, legacy_backing_size) if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def test_copy_image_scp_ipv6(self, mock_execute): mock_execute.side_effect = [ processutils.ProcessExecutionError, mock.DEFAULT, ] libvirt_utils.copy_image('src', 'dest', host='2600::') mock_execute.assert_has_calls([ self._rsync_call('--dry-run', 'src', '[2600::]:dest'), mock.call('scp', 'src', '[2600::]:dest', on_execute=None, on_completion=None), ]) self.assertEqual(2, mock_execute.call_count)
def test_copy_image(self): dst_fd, dst_path = tempfile.mkstemp() try: os.close(dst_fd) src_fd, src_path = tempfile.mkstemp() try: with os.fdopen(src_fd, 'w') as fp: fp.write('canary') libvirt_utils.copy_image(src_path, dst_path) with open(dst_path, 'r') as fp: self.assertEqual(fp.read(), 'canary') finally: os.unlink(src_path) finally: os.unlink(dst_path)
def create_image(self, prepare_template, base, size, *args, **kwargs): filename = os.path.split(base)[-1] @utils.synchronized(filename, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. libvirt_utils.create_cow_image(base, target) if size: disk.extend(target, size, use_cow=True) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, max_size=size, *args, **kwargs) else: self.verify_base_size(base, size) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition('_') if backing_file != backing_parts[-1] and \ backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += '_%d' % legacy_backing_size legacy_backing_size *= units.Gi # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) disk.extend(legacy_base, legacy_backing_size, use_cow=True) if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def create_image(self, prepare_template, base, size, *args, **kwargs): filename = os.path.split(base)[-1] @utils.synchronized(filename, external=True, lock_path=self.lock_path) def copy_qcow2_image(base, target, size): # TODO(pbrady): Consider copying the cow image here # with preallocation=metadata set for performance reasons. # This would be keyed on a 'preallocate_images' setting. libvirt_utils.create_cow_image(base, target) if size: disk.extend(target, size, use_cow=True) # Download the unmodified base image unless we already have a copy. if not os.path.exists(base): prepare_template(target=base, max_size=size, *args, **kwargs) else: self.verify_base_size(base, size) legacy_backing_size = None legacy_base = base # Determine whether an existing qcow2 disk uses a legacy backing by # actually looking at the image itself and parsing the output of the # backing file it expects to be using. if os.path.exists(self.path): backing_path = libvirt_utils.get_disk_backing_file(self.path) if backing_path is not None: backing_file = os.path.basename(backing_path) backing_parts = backing_file.rpartition("_") if backing_file != backing_parts[-1] and backing_parts[-1].isdigit(): legacy_backing_size = int(backing_parts[-1]) legacy_base += "_%d" % legacy_backing_size legacy_backing_size *= units.Gi # Create the legacy backing file if necessary. if legacy_backing_size: if not os.path.exists(legacy_base): with fileutils.remove_path_on_error(legacy_base): libvirt_utils.copy_image(base, legacy_base) disk.extend(legacy_base, legacy_backing_size, use_cow=True) if not os.path.exists(self.path): with fileutils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size)
def download(self, context, url_parts, dst_file, metadata, **kwargs): self.filesystems = self._get_options() if not self.filesystems: # NOTE(jbresnah) when nothing is configured assume legacy behavior nova_mountpoint = "/" glance_mountpoint = "/" else: self._verify_config() fs_descriptor = self._file_system_lookup(metadata, url_parts) if fs_descriptor is None: msg = _("No matching ID for the URL %s was found.") % url_parts.geturl() raise exception.ImageDownloadModuleError(reason=msg, module=str(self)) nova_mountpoint = fs_descriptor["mountpoint"] glance_mountpoint = metadata["mountpoint"] source_file = self._normalize_destination(nova_mountpoint, glance_mountpoint, url_parts.path) lv_utils.copy_image(source_file, dst_file) LOG.info( _("Copied %(source_file)s using %(module_str)s") % {"source_file": source_file, "module_str": str(self)} )
def test_download_module_filesystem_match(self): mountpoint = '/' fs_id = 'someid' desc = {'id': fs_id, 'mountpoint': mountpoint} class MyGlanceStubClient(glance_stubs.StubGlanceClient): outer_test = self def get(self, image_id): return type( 'GlanceLocations', (object, ), { 'locations': [{ 'url': 'file:///' + os.devnull, 'metadata': desc }] }) def data(self, image_id): self.outer_test.fail('This should not be called because the ' 'transfer module should have intercepted ' 'it.') self.mox.StubOutWithMock(lv_utils, 'copy_image') image_id = 1 # doesn't matter client = MyGlanceStubClient() self.flags(allowed_direct_url_schemes=['file']) self.flags(group='image_file_url', filesystems=['gluster']) service = self._create_image_service(client) #NOTE(Jbresnah) The following options must be added after the module # has added the specific groups. self.flags(group='image_file_url:gluster', id=fs_id) self.flags(group='image_file_url:gluster', mountpoint=mountpoint) dest_file = os.devnull lv_utils.copy_image(mox.IgnoreArg(), dest_file) self.mox.ReplayAll() service.download(self.context, image_id, dst_path=dest_file) self.mox.VerifyAll()
def test_download_module_filesystem_match(self): mountpoint = '/' fs_id = 'someid' desc = {'id': fs_id, 'mountpoint': mountpoint} class MyGlanceStubClient(glance_stubs.StubGlanceClient): outer_test = self def get(self, image_id): return type('GlanceLocations', (object,), {'status': 'active', 'locations': [ {'url': 'file:///' + os.devnull, 'metadata': desc}]}) def data(self, image_id): self.outer_test.fail('This should not be called because the ' 'transfer module should have intercepted ' 'it.') self.mox.StubOutWithMock(lv_utils, 'copy_image') image_id = 1 # doesn't matter client = MyGlanceStubClient() self.flags(allowed_direct_url_schemes=['file'], group='glance') self.flags(group='image_file_url', filesystems=['gluster']) service = self._create_image_service(client) # NOTE(Jbresnah) The following options must be added after the module # has added the specific groups. self.flags(group='image_file_url:gluster', id=fs_id) self.flags(group='image_file_url:gluster', mountpoint=mountpoint) dest_file = os.devnull lv_utils.copy_image(mox.IgnoreArg(), dest_file) self.mox.ReplayAll() service.download(self.context, image_id, dst_path=dest_file) self.mox.VerifyAll()
def test_download_module_filesystem_match(self): mountpoint = "/" fs_id = "someid" desc = {"id": fs_id, "mountpoint": mountpoint} class MyGlanceStubClient(glance_stubs.StubGlanceClient): outer_test = self def get(self, image_id): return type( "GlanceLocations", (object,), {"locations": [{"url": "file:///" + os.devnull, "metadata": desc}]} ) def data(self, image_id): self.outer_test.fail( "This should not be called because the " "transfer module should have intercepted " "it." ) self.mox.StubOutWithMock(lv_utils, "copy_image") image_id = 1 # doesn't matter client = MyGlanceStubClient() self.flags(allowed_direct_url_schemes=["file"]) self.flags(group="image_file_url", filesystems=["gluster"]) service = self._create_image_service(client) # NOTE(Jbresnah) The following options must be added after the module # has added the specific groups. self.flags(group="image_file_url:gluster", id=fs_id) self.flags(group="image_file_url:gluster", mountpoint=mountpoint) dest_file = os.devnull lv_utils.copy_image(mox.IgnoreArg(), dest_file) self.mox.ReplayAll() service.download(self.context, image_id, dst_path=dest_file) self.mox.VerifyAll()
def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) if size: disk.extend(target, size)
def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) if size: image = imgmodel.LocalFileImage(target, self.driver_format) disk.extend(image, size)
def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) if size: # class Raw is misnamed, format may not be 'raw' in all cases use_cow = self.driver_format == 'qcow2' disk.extend(target, size, use_cow=use_cow)
def test_copy_image_remote_rsync(self, mock_rem_fs_remove): self.flags(remote_filesystem_transport='rsync', group='libvirt') libvirt_utils.copy_image('src', 'dest', host='host') mock_rem_fs_remove.assert_called_once_with('src', 'host:dest', on_completion=None, on_execute=None, compression=True)
def test_copy_image_local_cp(self, mock_execute): libvirt_utils.copy_image('src', 'dest') mock_execute.assert_called_once_with('cp', 'src', 'dest')
def test_copy_image_remote_rsync(self, mock_rem_fs_remove): self.flags(remote_filesystem_transport="rsync", group="libvirt") libvirt_utils.copy_image("src", "dest", host="host") mock_rem_fs_remove.assert_called_once_with("src", "host:dest", on_completion=None, on_execute=None)
def _test_copy_image(self, fake_execute, host): self.useFixture(fixtures.MonkeyPatch( 'nova.utils.execute', fake_execute)) src = tempfile.NamedTemporaryFile() dst = tempfile.NamedTemporaryFile() libvirt_utils.copy_image(src.name, dst.name, host)
def test_copy_image_local(self, mock_execute): libvirt_utils.copy_image("src", "dest") mock_execute.assert_called_once_with("cp", "src", "dest")
def _test_copy_image(self, fake_execute, host): self.useFixture( fixtures.MonkeyPatch('nova.utils.execute', fake_execute)) src = tempfile.NamedTemporaryFile() dst = tempfile.NamedTemporaryFile() libvirt_utils.copy_image(src.name, dst.name, host)