Esempio n. 1
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['uuid'])
     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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Esempio n. 2
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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance)
Esempio n. 3
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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Esempio n. 4
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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Esempio n. 5
0
def _usage_from_instance(context, instance_ref, network_info=None, **kw):
    def null_safe_str(s):
        return str(s) if s else ''

    image_ref_url = "%s/images/%s" % (utils.generate_glance_url(),
                                      instance_ref['image_ref'])

    usage_info = dict(
          tenant_id=instance_ref['project_id'],
          user_id=instance_ref['user_id'],
          instance_id=instance_ref['uuid'],
          instance_type=instance_ref['instance_type']['name'],
          instance_type_id=instance_ref['instance_type_id'],
          memory_mb=instance_ref['memory_mb'],
          disk_gb=instance_ref['root_gb'] + instance_ref['ephemeral_gb'],
          display_name=instance_ref['display_name'],
          created_at=str(instance_ref['created_at']),
          # Nova's deleted vs terminated instance terminology is confusing,
          # this should be when the instance was deleted (i.e. terminated_at),
          # not when the db record was deleted. (mdragon)
          deleted_at=null_safe_str(instance_ref['terminated_at']),
          launched_at=null_safe_str(instance_ref['launched_at']),
          image_ref_url=image_ref_url,
          state=instance_ref['vm_state'],
          state_description=null_safe_str(instance_ref['task_state']))

    if network_info is not None:
        usage_info['fixed_ips'] = network_info.fixed_ips()

    usage_info.update(kw)
    return usage_info
Esempio n. 6
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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance)
def _usage_from_instance(context, instance_ref, network_info=None, **kw):
    def null_safe_str(s):
        return str(s) if s else ''

    image_ref_url = "%s/images/%s" % (utils.generate_glance_url(),
                                      instance_ref['image_ref'])

    usage_info = dict(
          tenant_id=instance_ref['project_id'],
          user_id=instance_ref['user_id'],
          instance_id=instance_ref['uuid'],
          instance_type=instance_ref['instance_type']['name'],
          instance_type_id=instance_ref['instance_type_id'],
          memory_mb=instance_ref['memory_mb'],
          disk_gb=instance_ref['root_gb'] + instance_ref['ephemeral_gb'],
          display_name=instance_ref['display_name'],
          created_at=str(instance_ref['created_at']),
          deleted_at=null_safe_str(instance_ref['deleted_at']),
          launched_at=null_safe_str(instance_ref['launched_at']),
          image_ref_url=image_ref_url,
          state=instance_ref['vm_state'],
          state_description=null_safe_str(instance_ref['task_state']))

    if network_info is not None:
        usage_info['fixed_ips'] = network_info.fixed_ips()

    usage_info.update(kw)
    return usage_info
Esempio n. 8
0
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific flavor id."""
     glance_url = utils.generate_glance_url()
     return os.path.join(glance_url,
                         request.environ["nova.context"].project_id,
                         self._collection_name,
                         str(identifier))
Esempio n. 9
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)
     compute_utils.notify_usage_exists(self.context, instance)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
     msg = test_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 = 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" % utils.generate_glance_url()
     self.assertEquals(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, instance["uuid"])
Esempio n. 10
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" % utils.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
Esempio n. 11
0
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific image id."""
     glance_url = utils.generate_glance_url()
     glance_url = self._update_link_prefix(glance_url,
                                           FLAGS.osapi_glance_link_prefix)
     return os.path.join(glance_url,
                         request.environ["nova.context"].project_id,
                         self._collection_name, str(identifier))
Esempio n. 12
0
 def _get_alternate_link(self, request, identifier):
     """Create an alternate link for a specific image id."""
     glance_url = utils.generate_glance_url()
     glance_url = self._update_link_prefix(glance_url,
                                           CONF.osapi_glance_link_prefix)
     return os.path.join(glance_url,
                         request.environ["nova.context"].project_id,
                         self._collection_name,
                         str(identifier))
Esempio n. 13
0
    def test_get_image(self):
        fake_req = fakes.HTTPRequest.blank('/v2/fake/images/123')
        actual_image = self.controller.show(fake_req, '124')

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

        expected_image = {
            "image": {
                "id": "124",
                "name": "queued snapshot",
                "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,
                    }],
                },
                "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))
Esempio n. 14
0
    def test_get_image(self):
        fake_req = fakes.HTTPRequest.blank('/v2/fake/images/123')
        actual_image = self.controller.show(fake_req, '124')

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

        expected_image = {
            "image": {
                "id": "124",
                "name": "queued snapshot",
                "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,
                    }],
                },
                "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.assertDictMatch(expected_image, actual_image)
Esempio n. 15
0
 def test_generate_glance_url(self):
     generated_url = utils.generate_glance_url()
     actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
     self.assertEqual(generated_url, actual_url)
Esempio n. 16
0
 def test_generate_glance_http_url(self):
     generated_url = utils.generate_glance_url()
     http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
Esempio n. 17
0
 def test_generate_glance_url(self):
     generated_url = utils.generate_glance_url()
     actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
     self.assertEqual(generated_url, actual_url)
Esempio n. 18
0
    def generate_alternate(self, image_id):
        """Create an alternate link for a specific flavor id."""
        glance_url = utils.generate_glance_url()

        return "%s/%s/images/%s" % (glance_url, self.project_id,
                str(image_id))
Esempio n. 19
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 % (utils.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 % (utils.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))
Esempio n. 20
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 % (utils.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 % (utils.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" % utils.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" % utils.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" % utils.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" % utils.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" % utils.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" % utils.generate_glance_url()
            }],
        },
        ]

        self.assertThat(expected, matchers.DictListMatches(response_list))
Esempio n. 21
0
 def test_generate_glance_http_url(self):
     generated_url = utils.generate_glance_url()
     http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
Esempio n. 22
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" % utils.generate_glance_url()
     self.assertEqual(generated_url, actual_url)
Esempio n. 23
0
 def test_generate_glance_https_url(self):
     self.flags(glance_protocol="https")
     generated_url = utils.generate_glance_url()
     https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, https_url)
Esempio n. 24
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 % (utils.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 % (utils.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" % utils.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" % utils.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" % utils.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" % utils.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" % utils.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" % utils.generate_glance_url()
            }],
        },
        ]

        self.assertDictListMatch(expected, response_list)
Esempio n. 25
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 % (utils.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 % (utils.generate_glance_url(), 124),
            }],
        }]

        self.assertDictListMatch(expected, 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.assertDictMatch({'limit': ['2'], 'marker': ['124']}, params)
Esempio n. 26
0
 def test_generate_glance_https_url(self):
     self.flags(glance_protocol="https")
     generated_url = utils.generate_glance_url()
     https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
     self.assertEqual(generated_url, https_url)
Esempio n. 27
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" % utils.generate_glance_url()
     self.assertEqual(generated_url, actual_url)