예제 #1
0
파일: vmops.py 프로젝트: nicoleLiu/nova
 def _fetch_image_on_esx_datastore():
     """Fetch image from Glance to ESX datastore."""
     LOG.debug(
         _("Downloading image file data %(image_ref)s to the ESX "
           "data store %(data_store_name)s") %
         ({
             'image_ref': instance.image_ref,
             'data_store_name': data_store_name
         }))
     # Upload the -flat.vmdk file whose meta-data file we just created
     # above
     vmware_images.fetch_image(
         context,
         instance.image_ref,
         instance,
         host=self._session._host_ip,
         data_center_name=self._get_datacenter_name_and_ref()[1],
         datastore_name=data_store_name,
         cookies=cookies,
         file_path=flat_uploaded_vmdk_name)
     LOG.debug(
         _("Downloaded image file data %(image_ref)s to the ESX "
           "data store %(data_store_name)s") %
         ({
             'image_ref': instance.image_ref,
             'data_store_name': data_store_name
         }))
예제 #2
0
    def test_fetch_image(self):
        """Test fetching images."""

        dc_name = 'fake-dc'
        file_path = 'fake_file'
        ds_name = 'ds1'
        host = mock.MagicMock()
        context = mock.MagicMock()

        image_data = {
                'id': nova.tests.image.fake.get_valid_image_id(),
                'disk_format': 'vmdk',
                'size': 512,
            }
        read_file_handle = mock.MagicMock()
        write_file_handle = mock.MagicMock()
        read_iter = mock.MagicMock()
        instance = {}
        instance['image_ref'] = image_data['id']
        instance['uuid'] = 'fake-uuid'

        def fake_read_handle(read_iter):
            return read_file_handle

        def fake_write_handle(host, dc_name, ds_name, cookies,
                              file_path, file_size):
            return write_file_handle

        def fake_download(context, image_id):
            return read_iter

        def fake_image_show(context, image_id):
            return image_data

        with contextlib.nested(
             mock.patch.object(read_write_util, 'GlanceFileRead',
                               side_effect=fake_read_handle),
             mock.patch.object(read_write_util, 'VMwareHTTPWriteFile',
                               side_effect=fake_write_handle),
             mock.patch.object(vmware_images, 'start_transfer'),
             mock.patch.object(nova.image.glance.GlanceImageService, 'show',
                side_effect=fake_image_show),
             mock.patch.object(nova.image.glance.GlanceImageService,
                     'download', side_effect=fake_download),
        ) as (glance_read, http_write, start_transfer, image_show,
                image_download):
            vmware_images.fetch_image(context, instance,
                                      host, dc_name,
                                      ds_name, file_path)

        glance_read.assert_called_once_with(read_iter)
        http_write.assert_called_once_with(host, dc_name, ds_name, None,
                                           file_path, image_data['size'])
        start_transfer.assert_called_once_with(
                context, read_file_handle,
                image_data['size'],
                write_file_handle=write_file_handle)
        image_download.assert_called_once_with(context, instance['image_ref'])
        image_show.assert_called_once_with(context, instance['image_ref'])
예제 #3
0
파일: vmops.py 프로젝트: superstack/nova
 def _fetch_image_on_esx_datastore():
     """Fetch image from Glance to ESX datastore."""
     LOG.debug(_("Downloading image file data %(image_id)s to the ESX "
                 "data store %(data_store_name)s") %
                 ({'image_id': instance.image_id,
                   'data_store_name': data_store_name}))
     # Upload the -flat.vmdk file whose meta-data file we just created
     # above
     vmware_images.fetch_image(
         instance.image_id,
         instance,
         host=self._session._host_ip,
         data_center_name=self._get_datacenter_name_and_ref()[1],
         datastore_name=data_store_name,
         cookies=cookies,
         file_path=flat_uploaded_vmdk_name)
     LOG.debug(_("Downloaded image file data %(image_id)s to the ESX "
                 "data store %(data_store_name)s") %
                 ({'image_id': instance.image_id,
                  'data_store_name': data_store_name}))