Example #1
0
 def test_notify_about_instance_usage(self):
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     extra_usage_info = {'image_name': 'fake_name'}
     compute_utils.notify_about_instance_usage(
         rpc.get_notifier('compute'),
         self.context, instance, 'create.start',
         extra_usage_info=extra_usage_info)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.create.start')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEqual(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
Example #2
0
 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = instance_obj.Instance.get_by_id(self.context, instance_id,
             expected_attrs=['metadata', 'system_metadata', 'info_cache'])
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(
         rpc.get_notifier('compute'), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
Example #3
0
 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     extra_usage_info = {'image_name': 'fake_name'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     compute_utils.notify_about_instance_usage(self.context, instance,
     'create.start', extra_usage_info=extra_usage_info)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
     msg = test_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.create.start')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEquals(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance)
Example #4
0
 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     extra_usage_info = {"image_name": "fake_name"}
     db.instance_system_metadata_update(self.context, instance["uuid"], sys_metadata, False)
     # NOTE(russellb) Make sure our instance has the latest system_metadata
     # in it.
     instance = db.instance_get(self.context, instance_id)
     compute_utils.notify_about_instance_usage(
         notify.get_notifier("compute"), self.context, instance, "create.start", extra_usage_info=extra_usage_info
     )
     self.assertEquals(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg.priority, "INFO")
     self.assertEquals(msg.event_type, "compute.instance.create.start")
     payload = msg.payload
     self.assertEquals(payload["tenant_id"], self.project_id)
     self.assertEquals(payload["user_id"], self.user_id)
     self.assertEquals(payload["instance_id"], instance["uuid"])
     self.assertEquals(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEquals(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEquals(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in ("display_name", "created_at", "launched_at", "state", "state_description", "image_meta"):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEquals(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     self.assertEquals(payload["image_name"], "fake_name")
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, jsonutils.to_primitive(instance))
Example #5
0
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific image id."""
     glance_url = glance.generate_glance_url()
     glance_url = self._update_glance_link_prefix(glance_url)
     return '/'.join([glance_url,
                      self._collection_name,
                      str(identifier)])
Example #6
0
 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance = create_instance(self.context)
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(rpc.get_notifier("compute"), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.exists")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
Example #7
0
 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(
         rpc.get_notifier('compute'), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     image_ref_url = "%s/images/%s" % (glance.generate_glance_url(),
                                       uuids.fake_image_ref)
     self.assertEqual(payload['image_ref_url'], image_ref_url)
Example #8
0
 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     self.compute.terminate_instance(self.context, instance)
     instance = db.instance_get(self.context.elevated(read_deleted='yes'),
                                instance_id)
     compute_utils.notify_usage_exists(self.context, instance)
     msg = test_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.exists')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Example #9
0
 def test_notify_about_instance_usage(self):
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     extra_usage_info = {"image_name": "fake_name"}
     compute_utils.notify_about_instance_usage(
         rpc.get_notifier("compute"), self.context, instance, "create.start", extra_usage_info=extra_usage_info
     )
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.create.start")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in ("display_name", "created_at", "launched_at", "state", "state_description", "image_meta"):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     self.assertEqual(payload["image_name"], "fake_name")
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific image id."""
     glance_url = glance.generate_glance_url()
     glance_url = self._update_glance_link_prefix(glance_url)
     return os.path.join(
         glance_url, request.environ["nova.context"].project_id, self._collection_name, str(identifier)
     )
Example #11
0
 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     self.compute.terminate_instance(self.context, instance)
     compute_utils.notify_usage_exists(self.context, instance)
     msg = test_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.exists')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Example #12
0
 def test_generate_glance_http_url(self):
     generated_url = glance.generate_glance_url()
     glance_host = CONF.glance_host
     # ipv6 address, need to wrap it with '[]'
     if utils.is_valid_ipv6(glance_host):
         glance_host = "[%s]" % glance_host
     http_url = "http://%s:%d" % (glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
Example #13
0
 def test_generate_glance_https_url(self):
     self.flags(protocol="https", group='glance')
     generated_url = glance.generate_glance_url()
     glance_host = CONF.glance.host
     # ipv6 address, need to wrap it with '[]'
     if netutils.is_valid_ipv6(glance_host):
         glance_host = '[%s]' % glance_host
     https_url = "https://%s:%d" % (glance_host, CONF.glance.port)
     self.assertEqual(generated_url, https_url)
    def test_get_image(self):
        fake_req = fakes.HTTPRequestV3.blank('/os-images/123')
        actual_image = self.controller.show(fake_req, '124')

        href = "http://localhost/v3/images/124"
        bookmark = "http://localhost/images/124"
        alternate = "%s/fake/images/124" % glance.generate_glance_url()
        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v3/servers/" + server_uuid
        server_bookmark = "http://localhost/servers/" + server_uuid

        expected_image = {
            "image": {
                "id": "124",
                "name": "queued snapshot",
                "updated": NOW_API_FORMAT,
                "created": NOW_API_FORMAT,
                "status": "SAVING",
                "progress": 25,
                "size": 25165824,
                "minDisk": 0,
                "minRam": 0,
                'server': {
                    'id': server_uuid,
                    "links": [{
                        "rel": "self",
                        "href": server_href,
                    },
                    {
                        "rel": "bookmark",
                        "href": server_bookmark,
                    }],
                },
                "metadata": {
                    "instance_uuid": server_uuid,
                    "user_id": "fake",
                },
                "links": [{
                    "rel": "self",
                    "href": href,
                },
                {
                    "rel": "bookmark",
                    "href": bookmark,
                },
                {
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image",
                    "href": alternate
                }],
            },
        }

        self.assertThat(actual_image, matchers.DictMatches(expected_image))
Example #15
0
 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = instance_obj.Instance.get_by_id(
         self.context, instance_id, expected_attrs=["metadata", "system_metadata", "info_cache"]
     )
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     self.compute.terminate_instance(self.context, instance, [], [])
     instance = instance_obj.Instance.get_by_id(
         self.context.elevated(read_deleted="yes"), instance_id, expected_attrs=["system_metadata"]
     )
     compute_utils.notify_usage_exists(rpc.get_notifier("compute"), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.exists")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
Example #16
0
 def test_notify_about_instance_usage(self):
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {
         'image_md_key1': 'val1',
         'image_md_key2': 'val2',
         'other_data': 'meow'
     }
     instance.system_metadata.update(sys_metadata)
     instance.save()
     extra_usage_info = {'image_name': 'fake_name'}
     compute_utils.notify_about_instance_usage(
         rpc.get_notifier('compute'),
         self.context,
         instance,
         'create.start',
         extra_usage_info=extra_usage_info)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.create.start')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at', 'state',
                  'state_description', 'image_meta'):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'], {
         'md_key1': 'val1',
         'md_key2': 'val2'
     })
     self.assertEqual(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
Example #17
0
 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     extra_usage_info = {'image_name': 'fake_name'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     # NOTE(russellb) Make sure our instance has the latest system_metadata
     # in it.
     instance = db.instance_get(self.context, instance_id)
     compute_utils.notify_about_instance_usage(
         notify.get_notifier('compute'),
         self.context, instance, 'create.start',
         extra_usage_info=extra_usage_info)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.create.start')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEqual(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context,
                                     jsonutils.to_primitive(instance))
Example #18
0
 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {
         'image_md_key1': 'val1',
         'image_md_key2': 'val2',
         'other_data': 'meow'
     }
     db.instance_system_metadata_update(self.context, instance['uuid'],
                                        sys_metadata, False)
     self.compute.terminate_instance(self.context,
                                     jsonutils.to_primitive(instance))
     instance = db.instance_get(self.context.elevated(read_deleted='yes'),
                                instance_id)
     compute_utils.notify_usage_exists(notify.get_notifier('compute'),
                                       self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg.priority, 'INFO')
     self.assertEquals(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at', 'state',
                  'state_description', 'bandwidth',
                  'audit_period_beginning', 'audit_period_ending',
                  'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'], {
         'md_key1': 'val1',
         'md_key2': 'val2'
     })
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Example #19
0
 def test_notify_usage_exists(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = instance_obj.Instance.get_by_id(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {
         'image_md_key1': 'val1',
         'image_md_key2': 'val2',
         'other_data': 'meow'
     }
     instance.system_metadata.update(sys_metadata)
     instance.save()
     compute_utils.notify_usage_exists(rpc.get_notifier('compute'),
                                       self.context, instance)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at', 'state',
                  'state_description', 'bandwidth',
                  'audit_period_beginning', 'audit_period_ending',
                  'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'], {
         'md_key1': 'val1',
         'md_key2': 'val2'
     })
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
Example #20
0
 def test_notify_usage_exists(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     db.instance_system_metadata_update(self.context, instance["uuid"], sys_metadata, False)
     instance = db.instance_get(self.context, instance_id)
     compute_utils.notify_usage_exists(notify.get_notifier("compute"), self.context, instance)
     self.assertEquals(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg.priority, "INFO")
     self.assertEquals(msg.event_type, "compute.instance.exists")
     payload = msg.payload
     self.assertEquals(payload["tenant_id"], self.project_id)
     self.assertEquals(payload["user_id"], self.user_id)
     self.assertEquals(payload["instance_id"], instance["uuid"])
     self.assertEquals(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEquals(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEquals(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEquals(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, jsonutils.to_primitive(instance))
Example #21
0
    def test_get_image_details(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail')
        response = self.controller.detail(request)
        response_list = response["images"]

        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v2/fake/servers/" + server_uuid
        server_bookmark = "http://localhost/fake/servers/" + server_uuid
        alternate = "%s/fake/images/%s"

        expected = [{
            'id': '123',
            'name': 'public image',
            'metadata': {'key1': 'value1'},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 10,
            'minRam': 128,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/123",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/123",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 123),
            }],
        },
        {
            'id': '124',
            'name': 'queued snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'progress': 25,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/124",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/124",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 124),
            }],
        },
        {
            'id': '125',
            'name': 'saving snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'progress': 50,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/125",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/125",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/125" % glance.generate_glance_url()
            }],
        },
        {
            'id': '126',
            'name': 'active snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/126",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/126",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/126" % glance.generate_glance_url()
            }],
        },
        {
            'id': '127',
            'name': 'killed snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ERROR',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/127",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/127",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/127" % glance.generate_glance_url()
            }],
        },
        {
            'id': '128',
            'name': 'deleted snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'DELETED',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/128",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/128",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/128" % glance.generate_glance_url()
            }],
        },
        {
            'id': '129',
            'name': 'pending_delete snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'DELETED',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/129",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/129",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/129" % glance.generate_glance_url()
            }],
        },
        {
            'id': '130',
            'name': None,
            'metadata': {},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 0,
            'minRam': 0,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/130",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/130",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/130" % glance.generate_glance_url()
            }],
        },
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #22
0
    def test_get_image_details(self, get_all_mocked):
        request = self.http_request.blank(self.url_base + "images/detail")
        response = self.controller.detail(request)

        get_all_mocked.assert_called_once_with(mock.ANY, filters={})
        response_list = response["images"]

        image_125 = copy.deepcopy(self.expected_image_124["image"])
        image_125["id"] = "125"
        image_125["name"] = "saving snapshot"
        image_125["progress"] = 50
        image_125["links"][0]["href"] = "%s/125" % self.url_prefix
        image_125["links"][1]["href"] = "%s/125" % self.bookmark_prefix
        image_125["links"][2]["href"] = "%s/images/125" % glance.generate_glance_url()

        image_126 = copy.deepcopy(self.expected_image_124["image"])
        image_126["id"] = "126"
        image_126["name"] = "active snapshot"
        image_126["status"] = "ACTIVE"
        image_126["progress"] = 100
        image_126["links"][0]["href"] = "%s/126" % self.url_prefix
        image_126["links"][1]["href"] = "%s/126" % self.bookmark_prefix
        image_126["links"][2]["href"] = "%s/images/126" % glance.generate_glance_url()

        image_127 = copy.deepcopy(self.expected_image_124["image"])
        image_127["id"] = "127"
        image_127["name"] = "killed snapshot"
        image_127["status"] = "ERROR"
        image_127["progress"] = 0
        image_127["links"][0]["href"] = "%s/127" % self.url_prefix
        image_127["links"][1]["href"] = "%s/127" % self.bookmark_prefix
        image_127["links"][2]["href"] = "%s/images/127" % glance.generate_glance_url()

        image_128 = copy.deepcopy(self.expected_image_124["image"])
        image_128["id"] = "128"
        image_128["name"] = "deleted snapshot"
        image_128["status"] = "DELETED"
        image_128["progress"] = 0
        image_128["links"][0]["href"] = "%s/128" % self.url_prefix
        image_128["links"][1]["href"] = "%s/128" % self.bookmark_prefix
        image_128["links"][2]["href"] = "%s/images/128" % glance.generate_glance_url()

        image_129 = copy.deepcopy(self.expected_image_124["image"])
        image_129["id"] = "129"
        image_129["name"] = "pending_delete snapshot"
        image_129["status"] = "DELETED"
        image_129["progress"] = 0
        image_129["links"][0]["href"] = "%s/129" % self.url_prefix
        image_129["links"][1]["href"] = "%s/129" % self.bookmark_prefix
        image_129["links"][2]["href"] = "%s/images/129" % glance.generate_glance_url()

        image_130 = copy.deepcopy(self.expected_image_123["image"])
        image_130["id"] = "130"
        image_130["name"] = None
        image_130["metadata"] = {}
        image_130["minDisk"] = 0
        image_130["minRam"] = 0
        image_130["links"][0]["href"] = "%s/130" % self.url_prefix
        image_130["links"][1]["href"] = "%s/130" % self.bookmark_prefix
        image_130["links"][2]["href"] = "%s/images/130" % glance.generate_glance_url()

        image_131 = copy.deepcopy(self.expected_image_123["image"])
        image_131["id"] = "131"
        image_131["name"] = None
        image_131["metadata"] = {}
        image_131["minDisk"] = 0
        image_131["minRam"] = 0
        image_131["links"][0]["href"] = "%s/131" % self.url_prefix
        image_131["links"][1]["href"] = "%s/131" % self.bookmark_prefix
        image_131["links"][2]["href"] = "%s/images/131" % glance.generate_glance_url()

        expected = [
            self.expected_image_123["image"],
            self.expected_image_124["image"],
            image_125,
            image_126,
            image_127,
            image_128,
            image_129,
            image_130,
            image_131,
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #23
0
    def test_get_image_details_with_limit(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail?limit=2')
        response = self.controller.detail(request)
        response_list = response["images"]
        response_links = response["images_links"]

        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v2/fake/servers/" + server_uuid
        server_bookmark = "http://localhost/fake/servers/" + server_uuid
        alternate = "%s/fake/images/%s"

        expected = [{
            'id': '123',
            'name': 'public image',
            'metadata': {'key1': 'value1'},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'minDisk': 10,
            'progress': 100,
            'minRam': 128,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/123",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/123",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 123),
            }],
        },
        {
            'id': '124',
            'name': 'queued snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'minDisk': 0,
            'progress': 25,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/124",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/124",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 124),
            }],
        }]

        self.assertThat(expected, matchers.DictListMatches(response_list))

        href_parts = urlparse.urlparse(response_links[0]['href'])
        self.assertEqual('/v2/fake/images', href_parts.path)
        params = urlparse.parse_qs(href_parts.query)

        self.assertThat({'limit': ['2'], 'marker': ['124']},
                        matchers.DictMatches(params))
Example #24
0
 def test_generate_alternate_link(self):
     view = images_view.ViewBuilder()
     request = fakes.HTTPRequest.blank('/v2/fake/images/1')
     generated_url = view._get_alternate_link(request, 1)
     actual_url = "%s/fake/images/1" % glance.generate_glance_url()
     self.assertEqual(generated_url, actual_url)
Example #25
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTestV21, self).setUp()
        self.flags(api_servers=["http://localhost:9292"], group="glance")
        fakes.stub_out_networking(self)
        fakes.stub_out_key_pair_funcs(self)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)

        self.controller = self.image_controller_class()
        self.url_prefix = "http://localhost%s/images" % self.url_base
        self.bookmark_prefix = "http://localhost%s/images" % self.bookmark_base
        self.uuid = "fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf"
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = "http://localhost%s/servers/%s" % (self.url_base, self.server_uuid)
        self.server_bookmark = "http://localhost%s/servers/%s" % (self.bookmark_base, self.server_uuid)
        self.alternate = "%s/images/%s"

        self.expected_image_123 = {
            "image": {
                "id": "123",
                "name": "public image",
                "metadata": {"key1": "value1"},
                "updated": NOW_API_FORMAT,
                "created": NOW_API_FORMAT,
                "status": "ACTIVE",
                "minDisk": 10,
                "progress": 100,
                "minRam": 128,
                "links": [
                    {"rel": "self", "href": "%s/123" % self.url_prefix},
                    {"rel": "bookmark", "href": "%s/123" % self.bookmark_prefix},
                    {
                        "rel": "alternate",
                        "type": "application/vnd.openstack.image",
                        "href": self.alternate % (glance.generate_glance_url(), 123),
                    },
                ],
            }
        }

        self.expected_image_124 = {
            "image": {
                "id": "124",
                "name": "queued snapshot",
                "metadata": {u"instance_uuid": self.server_uuid, u"user_id": u"fake"},
                "updated": NOW_API_FORMAT,
                "created": NOW_API_FORMAT,
                "status": "SAVING",
                "progress": 25,
                "minDisk": 0,
                "minRam": 0,
                "server": {
                    "id": self.server_uuid,
                    "links": [
                        {"rel": "self", "href": self.server_href},
                        {"rel": "bookmark", "href": self.server_bookmark},
                    ],
                },
                "links": [
                    {"rel": "self", "href": "%s/124" % self.url_prefix},
                    {"rel": "bookmark", "href": "%s/124" % self.bookmark_prefix},
                    {
                        "rel": "alternate",
                        "type": "application/vnd.openstack.image",
                        "href": self.alternate % (glance.generate_glance_url(), 124),
                    },
                ],
            }
        }
Example #26
0
 def test_generate_alternate_link(self):
     view = images_view.ViewBuilder()
     request = self.http_request.blank(self.url_base + 'images/1')
     generated_url = view._get_alternate_link(request, 1)
     actual_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(generated_url, actual_url)
Example #27
0
    def test_get_image_details(self, get_all_mocked):
        request = self.http_request.blank(self.url_base + 'images/detail')
        response = self.controller.detail(request)

        get_all_mocked.assert_called_once_with(mock.ANY, filters={})
        response_list = response["images"]

        image_125 = copy.deepcopy(self.expected_image_124["image"])
        image_125['id'] = '125'
        image_125['name'] = 'saving snapshot'
        image_125['progress'] = 50
        image_125["links"][0]["href"] = "%s/125" % self.url_prefix
        image_125["links"][1]["href"] = "%s/125" % self.bookmark_prefix
        image_125["links"][2]["href"] = ("%s/images/125" %
                                         glance.generate_glance_url())

        image_126 = copy.deepcopy(self.expected_image_124["image"])
        image_126['id'] = '126'
        image_126['name'] = 'active snapshot'
        image_126['status'] = 'ACTIVE'
        image_126['progress'] = 100
        image_126["links"][0]["href"] = "%s/126" % self.url_prefix
        image_126["links"][1]["href"] = "%s/126" % self.bookmark_prefix
        image_126["links"][2]["href"] = ("%s/images/126" %
                                         glance.generate_glance_url())

        image_127 = copy.deepcopy(self.expected_image_124["image"])
        image_127['id'] = '127'
        image_127['name'] = 'killed snapshot'
        image_127['status'] = 'ERROR'
        image_127['progress'] = 0
        image_127["links"][0]["href"] = "%s/127" % self.url_prefix
        image_127["links"][1]["href"] = "%s/127" % self.bookmark_prefix
        image_127["links"][2]["href"] = ("%s/images/127" %
                                         glance.generate_glance_url())

        image_128 = copy.deepcopy(self.expected_image_124["image"])
        image_128['id'] = '128'
        image_128['name'] = 'deleted snapshot'
        image_128['status'] = 'DELETED'
        image_128['progress'] = 0
        image_128["links"][0]["href"] = "%s/128" % self.url_prefix
        image_128["links"][1]["href"] = "%s/128" % self.bookmark_prefix
        image_128["links"][2]["href"] = ("%s/images/128" %
                                         glance.generate_glance_url())

        image_129 = copy.deepcopy(self.expected_image_124["image"])
        image_129['id'] = '129'
        image_129['name'] = 'pending_delete snapshot'
        image_129['status'] = 'DELETED'
        image_129['progress'] = 0
        image_129["links"][0]["href"] = "%s/129" % self.url_prefix
        image_129["links"][1]["href"] = "%s/129" % self.bookmark_prefix
        image_129["links"][2]["href"] = ("%s/images/129" %
                                         glance.generate_glance_url())

        image_130 = copy.deepcopy(self.expected_image_123["image"])
        image_130['id'] = '130'
        image_130['name'] = None
        image_130['metadata'] = {}
        image_130['minDisk'] = 0
        image_130['minRam'] = 0
        image_130["links"][0]["href"] = "%s/130" % self.url_prefix
        image_130["links"][1]["href"] = "%s/130" % self.bookmark_prefix
        image_130["links"][2]["href"] = ("%s/images/130" %
                                         glance.generate_glance_url())

        image_131 = copy.deepcopy(self.expected_image_123["image"])
        image_131['id'] = '131'
        image_131['name'] = None
        image_131['metadata'] = {}
        image_131['minDisk'] = 0
        image_131['minRam'] = 0
        image_131["links"][0]["href"] = "%s/131" % self.url_prefix
        image_131["links"][1]["href"] = "%s/131" % self.bookmark_prefix
        image_131["links"][2]["href"] = ("%s/images/131" %
                                         glance.generate_glance_url())

        expected = [
            self.expected_image_123["image"], self.expected_image_124["image"],
            image_125, image_126, image_127, image_128, image_129, image_130,
            image_131
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #28
0
 def test_generate_glance_https_url(self):
     self.flags(glance_protocol="https")
     generated_url = glance.generate_glance_url()
     https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, https_url)
Example #29
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTest, self).setUp()
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)
        fakes.stub_out_glance(self.stubs)

        self.controller = images.Controller()
        self.uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
        self.url = '/v2/fake/images/detail?server=' + self.uuid
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = (
            "http://localhost/v2/fake/servers/" + self.server_uuid)
        self.server_bookmark = (
            "http://localhost/fake/servers/" + self.server_uuid)
        self.alternate = "%s/fake/images/%s"
        self.fake_req = fakes.HTTPRequest.blank('/v2/fake/images/123')
        self.actual_image = self.controller.show(self.fake_req, '124')

        self.expected_image_123 = {
            "image": {'id': '123',
                      'name': 'public image',
                      'metadata': {'key1': 'value1'},
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'ACTIVE',
                      'minDisk': 10,
                      'progress': 100,
                      'minRam': 128,
                      "links": [{
                                    "rel": "self",
                                    "href":
                                        "http://localhost/v2/fake/images/123",
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "http://localhost/fake/images/123",
                                },
                                {
                                    "rel": "alternate",
                                    "type": "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             123),
                                }],
            },
        }

        self.expected_image_124 = {
            "image": {'id': '124',
                      'name': 'queued snapshot',
                      'metadata': {
                          u'instance_uuid': self.server_uuid,
                          u'user_id': u'fake',
                      },
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'SAVING',
                      'progress': 25,
                      'minDisk': 0,
                      'minRam': 0,
                      'server': {
                          'id': self.server_uuid,
                          "links": [{
                                        "rel": "self",
                                        "href": self.server_href,
                                    },
                                    {
                                        "rel": "bookmark",
                                        "href": self.server_bookmark,
                                    }],
                      },
                      "links": [{
                                    "rel": "self",
                                    "href":
                                        "http://localhost/v2/fake/images/124",
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "http://localhost/fake/images/124",
                                },
                                {
                                    "rel": "alternate",
                                    "type":
                                        "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             124),
                                }],
            },
        }

        self.image_service = self.mox.CreateMockAnything()
Example #30
0
 def test_generate_alternate_link(self):
     view = images_view.ViewBuilder()
     request = fakes.HTTPRequest.blank('/v2/fake/images/1')
     generated_url = view._get_alternate_link(request, 1)
     actual_url = "%s/fake/images/1" % glance.generate_glance_url()
     self.assertEqual(generated_url, actual_url)
Example #31
0
 def test_generate_glance_http_url(self):
     generated_url = glance.generate_glance_url()
     http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
Example #32
0
    def test_get_image_details_with_limit(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail?limit=2')
        response = self.controller.detail(request)
        response_list = response["images"]
        response_links = response["images_links"]

        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v2/fake/servers/" + server_uuid
        server_bookmark = "http://localhost/fake/servers/" + server_uuid
        alternate = "%s/fake/images/%s"

        expected = [{
            'id': '123',
            'name': 'public image',
            'metadata': {'key1': 'value1'},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'minDisk': 10,
            'progress': 100,
            'minRam': 128,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/123",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/123",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 123),
            }],
        },
        {
            'id': '124',
            'name': 'queued snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'minDisk': 0,
            'progress': 25,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/124",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/124",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 124),
            }],
        }]

        self.assertThat(expected, matchers.DictListMatches(response_list))

        href_parts = urlparse.urlparse(response_links[0]['href'])
        self.assertEqual('/v2/fake/images', href_parts.path)
        params = urlparse.parse_qs(href_parts.query)

        self.assertThat({'limit': ['2'], 'marker': ['124']},
                        matchers.DictMatches(params))
Example #33
0
    def test_get_image_details(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail')
        response = self.controller.detail(request)
        response_list = response["images"]

        image_125 = copy.deepcopy(self.expected_image_124["image"])
        image_125['id'] = '125'
        image_125['name'] = 'saving snapshot'
        image_125['progress'] = 50
        image_125["links"][0]["href"] = "http://localhost/v2/fake/images/125"
        image_125["links"][1]["href"] = "http://localhost/fake/images/125"
        image_125["links"][2]["href"] = ("%s/fake/images/125" %
                                         glance.generate_glance_url())

        image_126 = copy.deepcopy(self.expected_image_124["image"])
        image_126['id'] = '126'
        image_126['name'] = 'active snapshot'
        image_126['status'] = 'ACTIVE'
        image_126['progress'] = 100
        image_126["links"][0]["href"] = "http://localhost/v2/fake/images/126"
        image_126["links"][1]["href"] = "http://localhost/fake/images/126"
        image_126["links"][2]["href"] = ("%s/fake/images/126" %
                                         glance.generate_glance_url())

        image_127 = copy.deepcopy(self.expected_image_124["image"])
        image_127['id'] = '127'
        image_127['name'] = 'killed snapshot'
        image_127['status'] = 'ERROR'
        image_127['progress'] = 0
        image_127["links"][0]["href"] = "http://localhost/v2/fake/images/127"
        image_127["links"][1]["href"] = "http://localhost/fake/images/127"
        image_127["links"][2]["href"] = ("%s/fake/images/127" %
                                         glance.generate_glance_url())

        image_128 = copy.deepcopy(self.expected_image_124["image"])
        image_128['id'] = '128'
        image_128['name'] = 'deleted snapshot'
        image_128['status'] = 'DELETED'
        image_128['progress'] = 0
        image_128["links"][0]["href"] = "http://localhost/v2/fake/images/128"
        image_128["links"][1]["href"] = "http://localhost/fake/images/128"
        image_128["links"][2]["href"] = ("%s/fake/images/128" %
                                         glance.generate_glance_url())

        image_129 = copy.deepcopy(self.expected_image_124["image"])
        image_129['id'] = '129'
        image_129['name'] = 'pending_delete snapshot'
        image_129['status'] = 'DELETED'
        image_129['progress'] = 0
        image_129["links"][0]["href"] = "http://localhost/v2/fake/images/129"
        image_129["links"][1]["href"] = "http://localhost/fake/images/129"
        image_129["links"][2]["href"] = ("%s/fake/images/129" %
                                         glance.generate_glance_url())

        image_130 = copy.deepcopy(self.expected_image_123["image"])
        image_130['id'] = '130'
        image_130['name'] = None
        image_130['metadata'] = {}
        image_130['minDisk'] = 0
        image_130['minRam'] = 0
        image_130["links"][0]["href"] = "http://localhost/v2/fake/images/130"
        image_130["links"][1]["href"] = "http://localhost/fake/images/130"
        image_130["links"][2]["href"] = ("%s/fake/images/130" %
                                         glance.generate_glance_url())

        image_131 = copy.deepcopy(self.expected_image_123["image"])
        image_131['id'] = '131'
        image_131['name'] = None
        image_131['metadata'] = {}
        image_131['minDisk'] = 0
        image_131['minRam'] = 0
        image_131["links"][0]["href"] = "http://localhost/v2/fake/images/131"
        image_131["links"][1]["href"] = "http://localhost/fake/images/131"
        image_131["links"][2]["href"] = ("%s/fake/images/131" %
                                         glance.generate_glance_url())

        expected = [
            self.expected_image_123["image"], self.expected_image_124["image"],
            image_125, image_126, image_127, image_128, image_129, image_130,
            image_131
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #34
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTestV21, self).setUp()
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)

        self.controller = self.image_controller_class()
        self.url_prefix = "http://localhost%s/images" % self.url_base
        self.bookmark_prefix = "http://localhost%s/images" % self.bookmark_base
        self.uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = ("http://localhost%s/servers/%s" %
                            (self.url_base, self.server_uuid))
        self.server_bookmark = ("http://localhost%s/servers/%s" %
                                (self.bookmark_base, self.server_uuid))
        self.alternate = "%s/images/%s"

        self.expected_image_123 = {
            "image": {
                'id':
                '123',
                'name':
                'public image',
                'metadata': {
                    'key1': 'value1'
                },
                'updated':
                NOW_API_FORMAT,
                'created':
                NOW_API_FORMAT,
                'status':
                'ACTIVE',
                'minDisk':
                10,
                'progress':
                100,
                'minRam':
                128,
                "links": [{
                    "rel": "self",
                    "href": "%s/123" % self.url_prefix
                }, {
                    "rel": "bookmark",
                    "href": "%s/123" % self.bookmark_prefix
                }, {
                    "rel":
                    "alternate",
                    "type":
                    "application/vnd.openstack.image",
                    "href":
                    self.alternate % (glance.generate_glance_url(), 123),
                }],
            },
        }

        self.expected_image_124 = {
            "image": {
                'id':
                '124',
                'name':
                'queued snapshot',
                'metadata': {
                    u'instance_uuid': self.server_uuid,
                    u'user_id': u'fake',
                },
                'updated':
                NOW_API_FORMAT,
                'created':
                NOW_API_FORMAT,
                'status':
                'SAVING',
                'progress':
                25,
                'minDisk':
                0,
                'minRam':
                0,
                'server': {
                    'id':
                    self.server_uuid,
                    "links": [{
                        "rel": "self",
                        "href": self.server_href,
                    }, {
                        "rel": "bookmark",
                        "href": self.server_bookmark,
                    }],
                },
                "links": [{
                    "rel": "self",
                    "href": "%s/124" % self.url_prefix
                }, {
                    "rel": "bookmark",
                    "href": "%s/124" % self.bookmark_prefix
                }, {
                    "rel":
                    "alternate",
                    "type":
                    "application/vnd.openstack.image",
                    "href":
                    self.alternate % (glance.generate_glance_url(), 124),
                }],
            },
        }
Example #35
0
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific image id."""
     glance_url = glance.generate_glance_url(
         request.environ['nova.context'])
     glance_url = self._update_glance_link_prefix(glance_url)
     return '/'.join([glance_url, self._collection_name, str(identifier)])
Example #36
0
    def test_get_image_details(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail')
        response = self.controller.detail(request)
        response_list = response["images"]

        image_125 = copy.deepcopy(self.expected_image_124["image"])
        image_125['id'] = '125'
        image_125['name'] = 'saving snapshot'
        image_125['progress'] = 50
        image_125["links"][0]["href"] = "http://localhost/v2/fake/images/125"
        image_125["links"][1]["href"] = "http://localhost/fake/images/125"
        image_125["links"][2]["href"] = (
            "%s/fake/images/125" % glance.generate_glance_url())

        image_126 = copy.deepcopy(self.expected_image_124["image"])
        image_126['id'] = '126'
        image_126['name'] = 'active snapshot'
        image_126['status'] = 'ACTIVE'
        image_126['progress'] = 100
        image_126["links"][0]["href"] = "http://localhost/v2/fake/images/126"
        image_126["links"][1]["href"] = "http://localhost/fake/images/126"
        image_126["links"][2]["href"] = (
            "%s/fake/images/126" % glance.generate_glance_url())

        image_127 = copy.deepcopy(self.expected_image_124["image"])
        image_127['id'] = '127'
        image_127['name'] = 'killed snapshot'
        image_127['status'] = 'ERROR'
        image_127['progress'] = 0
        image_127["links"][0]["href"] = "http://localhost/v2/fake/images/127"
        image_127["links"][1]["href"] = "http://localhost/fake/images/127"
        image_127["links"][2]["href"] = (
            "%s/fake/images/127" % glance.generate_glance_url())

        image_128 = copy.deepcopy(self.expected_image_124["image"])
        image_128['id'] = '128'
        image_128['name'] = 'deleted snapshot'
        image_128['status'] = 'DELETED'
        image_128['progress'] = 0
        image_128["links"][0]["href"] = "http://localhost/v2/fake/images/128"
        image_128["links"][1]["href"] = "http://localhost/fake/images/128"
        image_128["links"][2]["href"] = (
            "%s/fake/images/128" % glance.generate_glance_url())

        image_129 = copy.deepcopy(self.expected_image_124["image"])
        image_129['id'] = '129'
        image_129['name'] = 'pending_delete snapshot'
        image_129['status'] = 'DELETED'
        image_129['progress'] = 0
        image_129["links"][0]["href"] = "http://localhost/v2/fake/images/129"
        image_129["links"][1]["href"] = "http://localhost/fake/images/129"
        image_129["links"][2]["href"] = (
            "%s/fake/images/129" % glance.generate_glance_url())

        image_130 = copy.deepcopy(self.expected_image_123["image"])
        image_130['id'] = '130'
        image_130['name'] = None
        image_130['metadata'] = {}
        image_130['minDisk'] = 0
        image_130['minRam'] = 0
        image_130["links"][0]["href"] = "http://localhost/v2/fake/images/130"
        image_130["links"][1]["href"] = "http://localhost/fake/images/130"
        image_130["links"][2]["href"] = (
            "%s/fake/images/130" % glance.generate_glance_url())

        image_131 = copy.deepcopy(self.expected_image_123["image"])
        image_131['id'] = '131'
        image_131['name'] = None
        image_131['metadata'] = {}
        image_131['minDisk'] = 0
        image_131['minRam'] = 0
        image_131["links"][0]["href"] = "http://localhost/v2/fake/images/131"
        image_131["links"][1]["href"] = "http://localhost/fake/images/131"
        image_131["links"][2]["href"] = (
            "%s/fake/images/131" % glance.generate_glance_url())

        expected = [self.expected_image_123["image"],
                    self.expected_image_124["image"],
                    image_125, image_126, image_127,
                    image_128, image_129, image_130,
                    image_131]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #37
0
    def test_get_image_details(self, get_all_mocked):
        request = self.http_request.blank(self.url_base + 'images/detail')
        response = self.controller.detail(request)

        get_all_mocked.assert_called_once_with(mock.ANY, filters={})
        response_list = response["images"]

        image_125 = copy.deepcopy(self.expected_image_124["image"])
        image_125['id'] = '125'
        image_125['name'] = 'saving snapshot'
        image_125['progress'] = 50
        image_125["links"][0]["href"] = "%s/125" % self.url_prefix
        image_125["links"][1]["href"] = "%s/125" % self.bookmark_prefix
        image_125["links"][2]["href"] = (
            "%s/images/125" % glance.generate_glance_url())

        image_126 = copy.deepcopy(self.expected_image_124["image"])
        image_126['id'] = '126'
        image_126['name'] = 'active snapshot'
        image_126['status'] = 'ACTIVE'
        image_126['progress'] = 100
        image_126["links"][0]["href"] = "%s/126" % self.url_prefix
        image_126["links"][1]["href"] = "%s/126" % self.bookmark_prefix
        image_126["links"][2]["href"] = (
            "%s/images/126" % glance.generate_glance_url())

        image_127 = copy.deepcopy(self.expected_image_124["image"])
        image_127['id'] = '127'
        image_127['name'] = 'killed snapshot'
        image_127['status'] = 'ERROR'
        image_127['progress'] = 0
        image_127["links"][0]["href"] = "%s/127" % self.url_prefix
        image_127["links"][1]["href"] = "%s/127" % self.bookmark_prefix
        image_127["links"][2]["href"] = (
            "%s/images/127" % glance.generate_glance_url())

        image_128 = copy.deepcopy(self.expected_image_124["image"])
        image_128['id'] = '128'
        image_128['name'] = 'deleted snapshot'
        image_128['status'] = 'DELETED'
        image_128['progress'] = 0
        image_128["links"][0]["href"] = "%s/128" % self.url_prefix
        image_128["links"][1]["href"] = "%s/128" % self.bookmark_prefix
        image_128["links"][2]["href"] = (
            "%s/images/128" % glance.generate_glance_url())

        image_129 = copy.deepcopy(self.expected_image_124["image"])
        image_129['id'] = '129'
        image_129['name'] = 'pending_delete snapshot'
        image_129['status'] = 'DELETED'
        image_129['progress'] = 0
        image_129["links"][0]["href"] = "%s/129" % self.url_prefix
        image_129["links"][1]["href"] = "%s/129" % self.bookmark_prefix
        image_129["links"][2]["href"] = (
            "%s/images/129" % glance.generate_glance_url())

        image_130 = copy.deepcopy(self.expected_image_123["image"])
        image_130['id'] = '130'
        image_130['name'] = None
        image_130['metadata'] = {}
        image_130['minDisk'] = 0
        image_130['minRam'] = 0
        image_130["links"][0]["href"] = "%s/130" % self.url_prefix
        image_130["links"][1]["href"] = "%s/130" % self.bookmark_prefix
        image_130["links"][2]["href"] = (
            "%s/images/130" % glance.generate_glance_url())

        image_131 = copy.deepcopy(self.expected_image_123["image"])
        image_131['id'] = '131'
        image_131['name'] = None
        image_131['metadata'] = {}
        image_131['minDisk'] = 0
        image_131['minRam'] = 0
        image_131["links"][0]["href"] = "%s/131" % self.url_prefix
        image_131["links"][1]["href"] = "%s/131" % self.bookmark_prefix
        image_131["links"][2]["href"] = (
            "%s/images/131" % glance.generate_glance_url())

        expected = [self.expected_image_123["image"],
                    self.expected_image_124["image"],
                    image_125, image_126, image_127,
                    image_128, image_129, image_130,
                    image_131]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Example #38
0
 def test_generate_glance_http_url(self):
     generated_url = glance.generate_glance_url()
     http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
Example #39
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTestV21, self).setUp()
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)

        self.controller = self.image_controller_class()
        self.url_prefix = "http://localhost%s/images" % self.url_base
        self.bookmark_prefix = "http://localhost%s/images" % self.bookmark_base
        self.uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = (
            "http://localhost%s/servers/%s" % (self.url_base,
                                               self.server_uuid))
        self.server_bookmark = (
             "http://localhost%s/servers/%s" % (self.bookmark_base,
                                                self.server_uuid))
        self.alternate = "%s/images/%s"

        self.expected_image_123 = {
            "image": {'id': '123',
                      'name': 'public image',
                      'metadata': {'key1': 'value1'},
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'ACTIVE',
                      'minDisk': 10,
                      'progress': 100,
                      'minRam': 128,
                      "links": [{
                                    "rel": "self",
                                    "href": "%s/123" % self.url_prefix
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "%s/123" % self.bookmark_prefix
                                },
                                {
                                    "rel": "alternate",
                                    "type": "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             123),
                                }],
            },
        }

        self.expected_image_124 = {
            "image": {'id': '124',
                      'name': 'queued snapshot',
                      'metadata': {
                          u'instance_uuid': self.server_uuid,
                          u'user_id': u'fake',
                      },
                      'updated': NOW_API_FORMAT,
                      'created': NOW_API_FORMAT,
                      'status': 'SAVING',
                      'progress': 25,
                      'minDisk': 0,
                      'minRam': 0,
                      'server': {
                          'id': self.server_uuid,
                          "links": [{
                                        "rel": "self",
                                        "href": self.server_href,
                                    },
                                    {
                                        "rel": "bookmark",
                                        "href": self.server_bookmark,
                                    }],
                      },
                      "links": [{
                                    "rel": "self",
                                    "href": "%s/124" % self.url_prefix
                                },
                                {
                                    "rel": "bookmark",
                                    "href":
                                        "%s/124" % self.bookmark_prefix
                                },
                                {
                                    "rel": "alternate",
                                    "type":
                                        "application/vnd.openstack.image",
                                    "href": self.alternate %
                                            (glance.generate_glance_url(),
                                             124),
                                }],
            },
        }
Example #40
0
 def test_generate_glance_https_url(self):
     self.flags(glance_protocol="https")
     generated_url = glance.generate_glance_url()
     https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, https_url)
Example #41
0
 def test_generate_alternate_link(self):
     view = images_view.ViewBuilder()
     request = self.http_request.blank(self.url_base + 'images/1')
     generated_url = view._get_alternate_link(request, 1)
     actual_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(generated_url, actual_url)
Example #42
0
    def setUp(self):
        """Run before each test."""
        super(ImagesControllerTest, self).setUp()
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fakes.stub_out_compute_api_backup(self.stubs)
        fakes.stub_out_glance(self.stubs)

        self.controller = images.Controller()
        self.uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
        self.url = '/v2/fake/images/detail?server=' + self.uuid
        self.server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        self.server_href = ("http://localhost/v2/fake/servers/" +
                            self.server_uuid)
        self.server_bookmark = ("http://localhost/fake/servers/" +
                                self.server_uuid)
        self.alternate = "%s/fake/images/%s"
        self.fake_req = fakes.HTTPRequest.blank('/v2/fake/images/123')
        self.actual_image = self.controller.show(self.fake_req, '124')

        self.expected_image_123 = {
            "image": {
                'id':
                '123',
                'name':
                'public image',
                'metadata': {
                    'key1': 'value1'
                },
                'updated':
                NOW_API_FORMAT,
                'created':
                NOW_API_FORMAT,
                'status':
                'ACTIVE',
                'minDisk':
                10,
                'progress':
                100,
                'minRam':
                128,
                "links": [{
                    "rel": "self",
                    "href": "http://localhost/v2/fake/images/123",
                }, {
                    "rel": "bookmark",
                    "href": "http://localhost/fake/images/123",
                }, {
                    "rel":
                    "alternate",
                    "type":
                    "application/vnd.openstack.image",
                    "href":
                    self.alternate % (glance.generate_glance_url(), 123),
                }],
            },
        }

        self.expected_image_124 = {
            "image": {
                'id':
                '124',
                'name':
                'queued snapshot',
                'metadata': {
                    u'instance_uuid': self.server_uuid,
                    u'user_id': u'fake',
                },
                'updated':
                NOW_API_FORMAT,
                'created':
                NOW_API_FORMAT,
                'status':
                'SAVING',
                'progress':
                25,
                'minDisk':
                0,
                'minRam':
                0,
                'server': {
                    'id':
                    self.server_uuid,
                    "links": [{
                        "rel": "self",
                        "href": self.server_href,
                    }, {
                        "rel": "bookmark",
                        "href": self.server_bookmark,
                    }],
                },
                "links": [{
                    "rel": "self",
                    "href": "http://localhost/v2/fake/images/124",
                }, {
                    "rel": "bookmark",
                    "href": "http://localhost/fake/images/124",
                }, {
                    "rel":
                    "alternate",
                    "type":
                    "application/vnd.openstack.image",
                    "href":
                    self.alternate % (glance.generate_glance_url(), 124),
                }],
            },
        }

        self.image_service = self.mox.CreateMockAnything()
Example #43
0
    def test_get_image(self):
        fake_req = fakes.HTTPRequestV3.blank('/os-images/123')
        actual_image = self.controller.show(fake_req, '124')

        href = "http://localhost/v3/images/124"
        bookmark = "http://localhost/images/124"
        alternate = "%s/images/124" % glance.generate_glance_url()
        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v3/servers/" + server_uuid
        server_bookmark = "http://localhost/servers/" + server_uuid

        expected_image = {
            "image": {
                "id":
                "124",
                "name":
                "queued snapshot",
                "updated":
                NOW_API_FORMAT,
                "created":
                NOW_API_FORMAT,
                "status":
                "SAVING",
                "progress":
                25,
                "size":
                25165824,
                "minDisk":
                0,
                "minRam":
                0,
                'server': {
                    'id':
                    server_uuid,
                    "links": [{
                        "rel": "self",
                        "href": server_href,
                    }, {
                        "rel": "bookmark",
                        "href": server_bookmark,
                    }],
                },
                "metadata": {
                    "instance_uuid": server_uuid,
                    "user_id": "fake",
                },
                "links": [{
                    "rel": "self",
                    "href": href,
                }, {
                    "rel": "bookmark",
                    "href": bookmark,
                }, {
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image",
                    "href": alternate
                }],
            },
        }

        self.assertThat(actual_image, matchers.DictMatches(expected_image))
Example #44
0
    def test_get_image_details(self):
        request = fakes.HTTPRequest.blank('/v2/fake/images/detail')
        response = self.controller.detail(request)
        response_list = response["images"]

        server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
        server_href = "http://localhost/v2/fake/servers/" + server_uuid
        server_bookmark = "http://localhost/fake/servers/" + server_uuid
        alternate = "%s/fake/images/%s"

        expected = [{
            'id': '123',
            'name': 'public image',
            'metadata': {'key1': 'value1'},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 10,
            'minRam': 128,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/123",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/123",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 123),
            }],
        },
        {
            'id': '124',
            'name': 'queued snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'progress': 25,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/124",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/124",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": alternate % (glance.generate_glance_url(), 124),
            }],
        },
        {
            'id': '125',
            'name': 'saving snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'SAVING',
            'progress': 50,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/125",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/125",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/125" % glance.generate_glance_url()
            }],
        },
        {
            'id': '126',
            'name': 'active snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/126",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/126",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/126" % glance.generate_glance_url()
            }],
        },
        {
            'id': '127',
            'name': 'killed snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ERROR',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/127",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/127",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/127" % glance.generate_glance_url()
            }],
        },
        {
            'id': '128',
            'name': 'deleted snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'DELETED',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/128",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/128",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/128" % glance.generate_glance_url()
            }],
        },
        {
            'id': '129',
            'name': 'pending_delete snapshot',
            'metadata': {
                u'instance_uuid': server_uuid,
                u'user_id': u'fake',
            },
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'DELETED',
            'progress': 0,
            'minDisk': 0,
            'minRam': 0,
            'server': {
                'id': server_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_href,
                },
                {
                    "rel": "bookmark",
                    "href": server_bookmark,
                }],
            },
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/129",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/129",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/129" % glance.generate_glance_url()
            }],
        },
        {
            'id': '130',
            'name': None,
            'metadata': {},
            'updated': NOW_API_FORMAT,
            'created': NOW_API_FORMAT,
            'status': 'ACTIVE',
            'progress': 100,
            'minDisk': 0,
            'minRam': 0,
            "links": [{
                "rel": "self",
                "href": "http://localhost/v2/fake/images/130",
            },
            {
                "rel": "bookmark",
                "href": "http://localhost/fake/images/130",
            },
            {
                "rel": "alternate",
                "type": "application/vnd.openstack.image",
                "href": "%s/fake/images/130" % glance.generate_glance_url()
            }],
        },
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))