Beispiel #1
0
def get_test_image_info(context, instance_ref):
    if not context:
        context = get_test_admin_context()

    image_ref = instance_ref['image_ref']
    image_service, image_id = glance.get_remote_image_service(
        context, image_ref)
    return image_service.show(context, image_id)
Beispiel #2
0
def get_test_image_info(context, instance_ref):
    if not context:
        context = get_test_admin_context()

    image_ref = instance_ref['image_ref']
    image_service, image_id = glance.get_remote_image_service(context,
                                                              image_ref)
    return image_service.show(context, image_id)
Beispiel #3
0
 def test_get_remote_service_from_href(self, gcwi_mocked):
     id_or_uri = 'http://127.0.0.1/123'
     _ignored, image_id = glance.get_remote_image_service(
             mock.sentinel.ctx, id_or_uri)
     self.assertEqual('123', image_id)
     gcwi_mocked.assert_called_once_with(context=mock.sentinel.ctx,
                                         host='127.0.0.1',
                                         port=80,
                                         use_ssl=False)
Beispiel #4
0
 def _save_glance_image(self, context, image_id, image_vhd_path):
     (glance_image_service,
      image_id) = glance.get_remote_image_service(context, image_id)
     image_metadata = {"is_public": False,
                       "disk_format": "vhd",
                       "container_format": "bare",
                       "properties": {}}
     with self._pathutils.open(image_vhd_path, 'rb') as f:
         glance_image_service.update(context, image_id, image_metadata, f)
Beispiel #5
0
 def test_get_remote_service_from_href(self, gcwi_mocked):
     id_or_uri = 'http://127.0.0.1/123'
     _ignored, image_id = glance.get_remote_image_service(
         mock.sentinel.ctx, id_or_uri)
     self.assertEqual('123', image_id)
     gcwi_mocked.assert_called_once_with(context=mock.sentinel.ctx,
                                         host='127.0.0.1',
                                         port=80,
                                         use_ssl=False)
Beispiel #6
0
 def _save_glance_image(self, context, image_id, image_vhd_path):
     (glance_image_service,
      image_id) = glance.get_remote_image_service(context, image_id)
     image_metadata = {
         "is_public": False,
         "disk_format": "vhd",
         "container_format": "bare",
         "properties": {}
     }
     with self._pathutils.open(image_vhd_path, 'rb') as f:
         glance_image_service.update(context, image_id, image_metadata, f)
Beispiel #7
0
    def _get_session_and_image_id(self, context, id_or_uri):
        """Returns a tuple of (session, image_id). If the supplied `id_or_uri`
        is an image ID, then the default client session will be returned
        for the context's user, along with the image ID. If the supplied
        `id_or_uri` parameter is a URI, then a client session connecting to
        the URI's image service endpoint will be returned along with a
        parsed image ID from that URI.

        :param context: The `patron.context.Context` object for the request
        :param id_or_uri: A UUID identifier or an image URI to look up image
                          information for.
        """
        return glance.get_remote_image_service(context, id_or_uri)
Beispiel #8
0
 def test_get_remote_service_from_id(self, gcwi_mocked):
     id_or_uri = '123'
     _ignored, image_id = glance.get_remote_image_service(
             mock.sentinel.ctx, id_or_uri)
     self.assertEqual(id_or_uri, image_id)
     gcwi_mocked.assert_called_once_with()
Beispiel #9
0
 def test_get_remote_service_from_id(self, gcwi_mocked):
     id_or_uri = '123'
     _ignored, image_id = glance.get_remote_image_service(
         mock.sentinel.ctx, id_or_uri)
     self.assertEqual(id_or_uri, image_id)
     gcwi_mocked.assert_called_once_with()
Beispiel #10
0
    def setUp(self, mock_register):
        super(ConfigDriveTestCase, self).setUp()
        vm_util.vm_refs_cache_reset()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        cluster_name = 'test_cluster'
        self.flags(cluster_name=[cluster_name],
                   host_ip='test_url',
                   host_username='******',
                   host_password='******',
                   use_linked_clone=False, group='vmware')
        self.flags(vnc_enabled=False)
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        patron.tests.unit.image.fake.stub_out_image_service(self.stubs)
        self.conn = driver.VMwareVCDriver(fake.FakeVirtAPI)
        self.network_info = utils.get_test_network_info()
        self.node_name = '%s(%s)' % (self.conn.dict_mors.keys()[0],
                                     cluster_name)
        image_ref = patron.tests.unit.image.fake.get_valid_image_id()
        instance_values = {
            'vm_state': 'building',
            'project_id': 'fake',
            'user_id': 'fake',
            'name': '1',
            'kernel_id': '1',
            'ramdisk_id': '1',
            'mac_addresses': [{'address': 'de:ad:be:ef:be:ef'}],
            'memory_mb': 8192,
            'flavor': 'm1.large',
            'instance_type_id': 0,
            'vcpus': 4,
            'root_gb': 80,
            'image_ref': image_ref,
            'host': 'fake_host',
            'task_state': 'scheduling',
            'reservation_id': 'r-3t8muvr0',
            'id': 1,
            'uuid': 'fake-uuid',
            'node': self.node_name,
            'metadata': [],
            'expected_attrs': ['system_metadata'],
        }
        self.test_instance = fake_instance.fake_instance_obj(self.context,
                                                             **instance_values)
        self.test_instance.flavor = objects.Flavor(extra_specs={})

        (image_service, image_id) = glance.get_remote_image_service(context,
                                    image_ref)
        metadata = image_service.show(context, image_id)
        self.image = {
            'id': image_ref,
            'disk_format': 'vmdk',
            'size': int(metadata['size']),
        }

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'patron.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        def fake_make_drive(_self, _path):
            pass
        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stubs.Set(patron.virt.configdrive.ConfigDriveBuilder,
                       'make_drive', fake_make_drive)

        def fake_upload_iso_to_datastore(iso_path, instance, **kwargs):
            pass
        self.stubs.Set(images,
                       'upload_iso_to_datastore',
                       fake_upload_iso_to_datastore)