Beispiel #1
0
    def _format_image(self, image):
        image_view = dict()
        try:
            image_view = dict(image.extra_properties)
            attributes = ['name', 'disk_format', 'container_format',
                          'visibility', 'size', 'status', 'checksum',
                          'protected', 'min_ram', 'min_disk']
            for key in attributes:
                image_view[key] = getattr(image, key)
            image_view['id'] = image.image_id
            image_view['created_at'] = timeutils.isotime(image.created_at)
            image_view['updated_at'] = timeutils.isotime(image.updated_at)

            if CONF.show_multiple_locations:
                if image.locations:
                    image_view['locations'] = list(image.locations)
                else:
                    # NOTE (flwang): We will still show "locations": [] if
                    # image.locations is None to indicate it's allowed to show
                    # locations but it's just non-existent.
                    image_view['locations'] = []

            if CONF.show_image_direct_url and image.locations:
                image_view['direct_url'] = image.locations[0]['url']

            image_view['tags'] = list(image.tags)
            image_view['self'] = self._get_image_href(image)
            image_view['file'] = self._get_image_href(image, 'file')
            image_view['schema'] = '/v2/schemas/image'
            image_view = self.schema.filter(image_view)  # domain
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(unicode(e))
        return image_view
Beispiel #2
0
    def _format_image(self, image):
        image_view = dict()
        try:
            image_view = dict(image.extra_properties)
            attributes = [
                'name', 'disk_format', 'container_format', 'visibility',
                'size', 'status', 'checksum', 'protected', 'min_ram',
                'min_disk'
            ]
            for key in attributes:
                image_view[key] = getattr(image, key)
            image_view['id'] = image.image_id
            image_view['created_at'] = timeutils.isotime(image.created_at)
            image_view['updated_at'] = timeutils.isotime(image.updated_at)

            if CONF.show_multiple_locations:
                if image.locations:
                    image_view['locations'] = list(image.locations)
                else:
                    # NOTE (flwang): We will still show "locations": [] if
                    # image.locations is None to indicate it's allowed to show
                    # locations but it's just non-existent.
                    image_view['locations'] = []

            if CONF.show_image_direct_url and image.locations:
                image_view['direct_url'] = image.locations[0]['url']

            image_view['tags'] = list(image.tags)
            image_view['self'] = self._get_image_href(image)
            image_view['file'] = self._get_image_href(image, 'file')
            image_view['schema'] = '/v2/schemas/image'
            image_view = self.schema.filter(image_view)  # domain
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(unicode(e))
        return image_view
Beispiel #3
0
def format_image_notification(image):
    """
    Given a glance.domain.Image object, return a dictionary of relevant
    notification information. We purposely do not include 'location'
    as it may contain credentials.
    """
    return {
        "id": image.image_id,
        "name": image.name,
        "status": image.status,
        "created_at": timeutils.isotime(image.created_at),
        "updated_at": timeutils.isotime(image.updated_at),
        "min_disk": image.min_disk,
        "min_ram": image.min_ram,
        "protected": image.protected,
        "checksum": image.checksum,
        "owner": image.owner,
        "disk_format": image.disk_format,
        "container_format": image.container_format,
        "size": image.size,
        "is_public": image.visibility == "public",
        "properties": dict(image.extra_properties),
        "tags": list(image.tags),
        "deleted": False,
        "deleted_at": None,
    }
Beispiel #4
0
 def _format_image(self, image):
     image_view = dict(image.extra_properties)
     attributes = [
         "name",
         "disk_format",
         "container_format",
         "visibility",
         "size",
         "status",
         "checksum",
         "protected",
         "min_ram",
         "min_disk",
     ]
     for key in attributes:
         image_view[key] = getattr(image, key)
     image_view["id"] = image.image_id
     image_view["created_at"] = timeutils.isotime(image.created_at)
     image_view["updated_at"] = timeutils.isotime(image.updated_at)
     if image.locations:
         if CONF.show_multiple_locations:
             image_view["locations"] = list(image.locations)
         if CONF.show_image_direct_url:
             image_view["direct_url"] = image.locations[0]["url"]
     image_view["tags"] = list(image.tags)
     image_view["self"] = self._get_image_href(image)
     image_view["file"] = self._get_image_href(image, "file")
     image_view["schema"] = "/v2/schemas/image"
     image_view = self.schema.filter(image_view)  # domain
     return image_view
Beispiel #5
0
def format_image_notification(image):
    """
    Given a glance.domain.Image object, return a dictionary of relevant
    notification information. We purposely do not include 'location'
    as it may contain credentials.
    """
    return {
        'id': image.image_id,
        'name': image.name,
        'status': image.status,
        'created_at': timeutils.isotime(image.created_at),
        'updated_at': timeutils.isotime(image.updated_at),
        'min_disk': image.min_disk,
        'min_ram': image.min_ram,
        'protected': image.protected,
        'checksum': image.checksum,
        'owner': image.owner,
        'disk_format': image.disk_format,
        'container_format': image.container_format,
        'size': image.size,
        'is_public': image.visibility == 'public',
        'properties': dict(image.extra_properties),
        'tags': list(image.tags),
        'deleted': False,
        'deleted_at': None,
    }
Beispiel #6
0
def format_image_notification(image):
    """
    Given a glance.domain.Image object, return a dictionary of relevant
    notification information. We purposely do not include 'location'
    as it may contain credentials.
    """
    return {
        'id': image.image_id,
        'name': image.name,
        'status': image.status,
        'created_at': timeutils.isotime(image.created_at),
        'updated_at': timeutils.isotime(image.updated_at),
        'min_disk': image.min_disk,
        'min_ram': image.min_ram,
        'protected': image.protected,
        'checksum': image.checksum,
        'owner': image.owner,
        'disk_format': image.disk_format,
        'container_format': image.container_format,
        'size': image.size,
        'is_public': image.visibility == 'public',
        'properties': dict(image.extra_properties),
        'tags': list(image.tags),
        'deleted': False,
        'deleted_at': None,
    }
Beispiel #7
0
 def _format_image_member(self, member):
     member_view = {}
     attributes = ['member_id', 'image_id', 'status']
     for key in attributes:
         member_view[key] = getattr(member, key)
     member_view['created_at'] = timeutils.isotime(member.created_at)
     member_view['updated_at'] = timeutils.isotime(member.updated_at)
     return member_view
Beispiel #8
0
 def _format_image_member(self, member):
     member_view = {}
     attributes = ["member_id", "image_id"]
     for key in attributes:
         member_view[key] = getattr(member, key)
     member_view["created_at"] = timeutils.isotime(member.created_at)
     member_view["updated_at"] = timeutils.isotime(member.updated_at)
     return member_view
Beispiel #9
0
 def _format_image_member(self, member):
     member_view = {}
     attributes = ['member_id', 'image_id', 'status']
     for key in attributes:
         member_view[key] = getattr(member, key)
     member_view['created_at'] = timeutils.isotime(member.created_at)
     member_view['updated_at'] = timeutils.isotime(member.updated_at)
     member_view['schema'] = '/v2/schemas/member'
     member_view = self.schema.filter(member_view)
     return member_view
Beispiel #10
0
 def test_task_create_notification(self):
     self.task_repo_proxy.add(self.task_proxy)
     output_logs = self.notifier.get_logs()
     self.assertEqual(len(output_logs), 1)
     output_log = output_logs[0]
     self.assertEqual(output_log["notification_type"], "INFO")
     self.assertEqual(output_log["event_type"], "task.create")
     self.assertEqual(output_log["payload"]["id"], self.task.task_id)
     self.assertEqual(output_log["payload"]["updated_at"], timeutils.isotime(self.task.updated_at))
     self.assertEqual(output_log["payload"]["created_at"], timeutils.isotime(self.task.created_at))
     if "location" in output_log["payload"]:
         self.fail("Notification contained location field.")
Beispiel #11
0
 def _format_task(self, task, schema):
     task_view = {}
     attributes = ['type', 'status', 'input', 'result', 'owner', 'message']
     for key in attributes:
         task_view[key] = getattr(task, key)
     task_view['id'] = task.task_id
     task_view['expires_at'] = timeutils.isotime(task.expires_at)
     task_view['created_at'] = timeutils.isotime(task.created_at)
     task_view['updated_at'] = timeutils.isotime(task.updated_at)
     task_view['self'] = '/v2/tasks/%s' % task.task_id
     task_view['schema'] = '/v2/schemas/task'
     task_view = schema.filter(task_view)  # domain
     return task_view
Beispiel #12
0
 def _format_task_stub(self, schema, task):
     task_view = {}
     task_view['id'] = task.task_id
     task_view['type'] = task.type
     task_view['status'] = task.status
     task_view['owner'] = task.owner
     if task.expires_at:
         task_view['expires_at'] = timeutils.isotime(task.expires_at)
     task_view['created_at'] = timeutils.isotime(task.created_at)
     task_view['updated_at'] = timeutils.isotime(task.updated_at)
     task_view['self'] = self._get_task_location(task)
     task_view['schema'] = '/v2/schemas/task'
     task_view = schema.filter(task_view)  # domain
     return task_view
Beispiel #13
0
 def _format_task_stub(self, schema, task):
     task_view = {}
     task_view['id'] = task.task_id
     task_view['type'] = task.type
     task_view['status'] = task.status
     task_view['owner'] = task.owner
     if task.expires_at:
         task_view['expires_at'] = timeutils.isotime(task.expires_at)
     task_view['created_at'] = timeutils.isotime(task.created_at)
     task_view['updated_at'] = timeutils.isotime(task.updated_at)
     task_view['self'] = self._get_task_location(task)
     task_view['schema'] = '/v2/schemas/task'
     task_view = schema.filter(task_view)  # domain
     return task_view
Beispiel #14
0
 def test_task_create_notification(self):
     self.task_repo_proxy.add(self.task_proxy)
     output_logs = self.notifier.get_logs()
     self.assertEqual(len(output_logs), 1)
     output_log = output_logs[0]
     self.assertEqual(output_log['notification_type'], 'INFO')
     self.assertEqual(output_log['event_type'], 'task.create')
     self.assertEqual(output_log['payload']['id'], self.task.task_id)
     self.assertEqual(output_log['payload']['updated_at'],
                      timeutils.isotime(self.task.updated_at))
     self.assertEqual(output_log['payload']['created_at'],
                      timeutils.isotime(self.task.created_at))
     if 'location' in output_log['payload']:
         self.fail('Notification contained location field.')
Beispiel #15
0
    def _format_image(self, image):
        image_view = dict()
        try:
            image_view = dict(image.extra_properties)
            attributes = [
                'name', 'disk_format', 'container_format', 'visibility',
                'size', 'virtual_size', 'status', 'checksum', 'protected',
                'min_ram', 'min_disk', 'owner'
            ]
            for key in attributes:
                image_view[key] = getattr(image, key)
            image_view['id'] = image.image_id
            image_view['created_at'] = timeutils.isotime(image.created_at)
            image_view['updated_at'] = timeutils.isotime(image.updated_at)

            if CONF.show_multiple_locations:
                locations = list(image.locations)
                if locations:
                    image_view['locations'] = []
                    for loc in locations:
                        tmp = dict(loc)
                        tmp.pop('id', None)
                        tmp.pop('status', None)
                        image_view['locations'].append(tmp)
                else:
                    # NOTE (flwang): We will still show "locations": [] if
                    # image.locations is None to indicate it's allowed to show
                    # locations but it's just non-existent.
                    image_view['locations'] = []
                    LOG.debug("There is not available location "
                              "for image %s" % image.image_id)

            if CONF.show_image_direct_url:
                if image.locations:
                    # Choose best location configured strategy
                    l = location_strategy.choose_best_location(image.locations)
                    image_view['direct_url'] = l['url']
                else:
                    LOG.debug("There is not available location "
                              "for image %s" % image.image_id)

            image_view['tags'] = list(image.tags)
            image_view['self'] = self._get_image_href(image)
            image_view['file'] = self._get_image_href(image, 'file')
            image_view['schema'] = '/v2/schemas/image'
            image_view = self.schema.filter(image_view)  # domain
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        return image_view
Beispiel #16
0
def format_task_notification(task):
    # NOTE(nikhil): input is not passed to the notifier payload as it may
    # contain sensitive info.
    return {'id': task.task_id,
            'type': task.type,
            'status': task.status,
            'result': None,
            'owner': task.owner,
            'message': None,
            'expires_at': timeutils.isotime(task.expires_at),
            'created_at': timeutils.isotime(task.created_at),
            'updated_at': timeutils.isotime(task.updated_at),
            'deleted': False,
            'deleted_at': None,
            }
Beispiel #17
0
def format_task_notification(task):
    # NOTE(nikhil): input is not passed to the notifier payload as it may
    # contain sensitive info.
    return {'id': task.task_id,
            'type': task.type,
            'status': task.status,
            'result': None,
            'owner': task.owner,
            'message': None,
            'expires_at': timeutils.isotime(task.expires_at),
            'created_at': timeutils.isotime(task.created_at),
            'updated_at': timeutils.isotime(task.updated_at),
            'deleted': False,
            'deleted_at': None,
            }
Beispiel #18
0
    def _format_image(self, image):
        image_view = dict()
        try:
            image_view = dict(image.extra_properties)
            attributes = ['name', 'disk_format', 'container_format',
                          'visibility', 'size', 'virtual_size', 'status',
                          'checksum', 'protected', 'min_ram', 'min_disk',
                          'owner']
            for key in attributes:
                image_view[key] = getattr(image, key)
            image_view['id'] = image.image_id
            image_view['created_at'] = timeutils.isotime(image.created_at)
            image_view['updated_at'] = timeutils.isotime(image.updated_at)

            if CONF.show_multiple_locations:
                locations = list(image.locations)
                if locations:
                    image_view['locations'] = []
                    for loc in locations:
                        tmp = dict(loc)
                        tmp.pop('id', None)
                        tmp.pop('status', None)
                        image_view['locations'].append(tmp)
                else:
                    # NOTE (flwang): We will still show "locations": [] if
                    # image.locations is None to indicate it's allowed to show
                    # locations but it's just non-existent.
                    image_view['locations'] = []
                    LOG.debug("There is not available location "
                              "for image %s" % image.image_id)

            if CONF.show_image_direct_url:
                if image.locations:
                    # Choose best location configured strategy
                    l = location_strategy.choose_best_location(image.locations)
                    image_view['direct_url'] = l['url']
                else:
                    LOG.debug("There is not available location "
                              "for image %s" % image.image_id)

            image_view['tags'] = list(image.tags)
            image_view['self'] = self._get_image_href(image)
            image_view['file'] = self._get_image_href(image, 'file')
            image_view['schema'] = '/v2/schemas/image'
            image_view = self.schema.filter(image_view)  # domain
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        return image_view
Beispiel #19
0
    def to_wsme_model(model, db_entity, self_link=None, schema=None):
        # Return the wsme_attributes names:values as a dict
        names = []
        for attribute in model._wsme_attributes:
            names.append(attribute.name)

        values = {}
        for name in names:
            value = getattr(db_entity, name, None)
            if value is not None:
                if type(value) == datetime:
                    iso_datetime_value = timeutils.isotime(value)
                    values.update({name: iso_datetime_value})
                else:
                    values.update({name: value})

        if schema:
            values['schema'] = schema

        model_object = model(**values)

        # 'self' kwarg is used in wsme.types.Base.__init__(self, ..) and
        # conflicts during initialization. self_link is a proxy field to self.
        if self_link:
            model_object.self = self_link

        return model_object
Beispiel #20
0
    def to_wsme_model(model, db_entity, self_link=None, schema=None):
        # Return the wsme_attributes names:values as a dict
        names = []
        for attribute in model._wsme_attributes:
            names.append(attribute.name)

        values = {}
        for name in names:
            value = getattr(db_entity, name, None)
            if value is not None:
                if type(value) == datetime:
                    iso_datetime_value = timeutils.isotime(value)
                    values.update({name: iso_datetime_value})
                else:
                    values.update({name: value})

        if schema:
            values['schema'] = schema

        model_object = model(**values)

        # 'self' kwarg is used in wsme.types.Base.__init__(self, ..) and
        # conflicts during initialization. self_link is a proxy field to self.
        if self_link:
            model_object.self = self_link

        return model_object
Beispiel #21
0
def format_task_notification(task):
    # NOTE(nikhil): input is not passed to the notifier payload as it may
    # contain sensitive info.
    return {
        "id": task.task_id,
        "type": task.type,
        "status": task.status,
        "result": None,
        "owner": task.owner,
        "message": None,
        "expires_at": timeutils.isotime(task.expires_at),
        "created_at": timeutils.isotime(task.created_at),
        "updated_at": timeutils.isotime(task.updated_at),
        "deleted": False,
        "deleted_at": None,
    }
    def test_get_image_details_with_changes_since(self):
        """Tests that a detailed call can be filtered by changes-since"""
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)

        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)

        dt3 = timeutils.utcnow() + datetime.timedelta(2)
        iso3 = timeutils.isotime(dt3)

        dt4 = timeutils.utcnow() + datetime.timedelta(3)
        iso4 = timeutils.isotime(dt4)

        UUID3 = _gen_uuid()
        extra_fixture = self.get_fixture(id=UUID3, name='fake image #3')

        db_api.image_create(self.context, extra_fixture)
        db_api.image_destroy(self.context, UUID3)

        UUID4 = _gen_uuid()
        extra_fixture = self.get_fixture(id=UUID4,
                                         name='fake image #4',
                                         created_at=dt3,
                                         updated_at=dt3)

        db_api.image_create(self.context, extra_fixture)

        # Check a standard list, 4 images in db (2 deleted)
        images = self.client.get_images_detailed(filters={})
        self.assertEqualImages(images, (UUID4, UUID2), unjsonify=False)

        # Expect 3 images (1 deleted)
        filters = {'changes-since': iso1}
        images = self.client.get_images(filters=filters)
        self.assertEqualImages(images, (UUID4, UUID3, UUID2), unjsonify=False)

        # Expect 1 images (0 deleted)
        filters = {'changes-since': iso2}
        images = self.client.get_images_detailed(filters=filters)
        self.assertEqualImages(images, (UUID4, ), unjsonify=False)

        # Expect 0 images (0 deleted)
        filters = {'changes-since': iso4}
        images = self.client.get_images(filters=filters)
        self.assertEqualImages(images, (), unjsonify=False)
Beispiel #23
0
    def _format_image(self, image):
        image_view = dict()
        try:
            image_view = dict(image.extra_properties)
            attributes = [
                "name",
                "disk_format",
                "container_format",
                "visibility",
                "size",
                "virtual_size",
                "status",
                "checksum",
                "protected",
                "min_ram",
                "min_disk",
                "owner",
            ]
            for key in attributes:
                image_view[key] = getattr(image, key)
            image_view["id"] = image.image_id
            image_view["created_at"] = timeutils.isotime(image.created_at)
            image_view["updated_at"] = timeutils.isotime(image.updated_at)

            if CONF.show_multiple_locations:
                if image.locations:
                    image_view["locations"] = list(image.locations)
                else:
                    # NOTE (flwang): We will still show "locations": [] if
                    # image.locations is None to indicate it's allowed to show
                    # locations but it's just non-existent.
                    image_view["locations"] = []

            if CONF.show_image_direct_url and image.locations:
                # Choose best location configured strategy
                best_location = location_strategy.choose_best_location(image.locations)
                image_view["direct_url"] = best_location["url"]

            image_view["tags"] = list(image.tags)
            image_view["self"] = self._get_image_href(image)
            image_view["file"] = self._get_image_href(image, "file")
            image_view["schema"] = "/v2/schemas/image"
            image_view = self.schema.filter(image_view)  # domain
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(unicode(e))
        return image_view
Beispiel #24
0
 def _format_task(self, schema, task, task_details=None):
     task_view = {}
     task_attributes = ['type', 'status', 'owner']
     task_details_attributes = ['input', 'result', 'message']
     for key in task_attributes:
         task_view[key] = getattr(task, key)
     if task_details:
         for key in task_details_attributes:
             task_view[key] = getattr(task_details, key)
     task_view['id'] = task.task_id
     if task.expires_at:
         task_view['expires_at'] = timeutils.isotime(task.expires_at)
     task_view['created_at'] = timeutils.isotime(task.created_at)
     task_view['updated_at'] = timeutils.isotime(task.updated_at)
     task_view['self'] = self._get_task_location(task)
     task_view['schema'] = '/v2/schemas/task'
     task_view = schema.filter(task_view)  # domain
     return task_view
Beispiel #25
0
 def _format_image(self, image):
     image_view = dict(image.extra_properties)
     attributes = ['name', 'disk_format', 'container_format', 'visibility',
                   'size', 'status', 'checksum', 'protected',
                   'min_ram', 'min_disk']
     for key in attributes:
         image_view[key] = getattr(image, key)
     image_view['id'] = image.image_id
     image_view['created_at'] = timeutils.isotime(image.created_at)
     image_view['updated_at'] = timeutils.isotime(image.updated_at)
     if CONF.show_image_direct_url and image.locations:  # domain
         image_view['direct_url'] = image.locations[0]
     image_view['tags'] = list(image.tags)
     image_view['self'] = self._get_image_href(image)
     image_view['file'] = self._get_image_href(image, 'file')
     image_view['schema'] = '/v2/schemas/image'
     image_view = self.schema.filter(image_view)  # domain
     return image_view
Beispiel #26
0
 def _format_task(self, schema, task, task_details=None):
     task_view = {}
     task_attributes = ['type', 'status', 'owner']
     task_details_attributes = ['input', 'result', 'message']
     for key in task_attributes:
         task_view[key] = getattr(task, key)
     if task_details:
         for key in task_details_attributes:
             task_view[key] = getattr(task_details, key)
     task_view['id'] = task.task_id
     if task.expires_at:
         task_view['expires_at'] = timeutils.isotime(task.expires_at)
     task_view['created_at'] = timeutils.isotime(task.created_at)
     task_view['updated_at'] = timeutils.isotime(task.updated_at)
     task_view['self'] = self._get_task_location(task)
     task_view['schema'] = '/v2/schemas/task'
     task_view = schema.filter(task_view)  # domain
     return task_view
Beispiel #27
0
 def test_task_create_notification(self):
     self.task_repo_proxy.add(self.task_proxy, self.task_details_proxy)
     output_logs = self.notifier.get_logs()
     self.assertEqual(len(output_logs), 1)
     output_log = output_logs[0]
     self.assertEqual(output_log['notification_type'], 'INFO')
     self.assertEqual(output_log['event_type'], 'task.create')
     self.assertEqual(output_log['payload']['id'], self.task.task_id)
     self.assertEqual(
         output_log['payload']['updated_at'],
         timeutils.isotime(self.task.updated_at)
     )
     self.assertEqual(
         output_log['payload']['created_at'],
         timeutils.isotime(self.task.created_at)
     )
     if 'location' in output_log['payload']:
         self.fail('Notification contained location field.')
Beispiel #28
0
 def _format_image(self, image):
     image_view = dict(image.extra_properties)
     attributes = ['name', 'disk_format', 'container_format', 'visibility',
                   'size', 'status', 'checksum', 'protected',
                   'min_ram', 'min_disk']
     for key in attributes:
         image_view[key] = getattr(image, key)
     image_view['id'] = image.image_id
     image_view['created_at'] = timeutils.isotime(image.created_at)
     image_view['updated_at'] = timeutils.isotime(image.updated_at)
     if CONF.show_image_direct_url and image.location is not None:  # domain
         image_view['direct_url'] = image.location
     image_view['tags'] = list(image.tags)
     image_view['self'] = self._get_image_href(image)
     image_view['file'] = self._get_image_href(image, 'file')
     image_view['schema'] = '/v2/schemas/image'
     image_view = self.schema.filter(image_view)  # domain
     return image_view
Beispiel #29
0
    def test_get_image_details_with_changes_since(self):
        """Tests that a detailed call can be filtered by changes-since"""
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)

        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)

        dt3 = timeutils.utcnow() + datetime.timedelta(2)
        iso3 = timeutils.isotime(dt3)

        dt4 = timeutils.utcnow() + datetime.timedelta(3)
        iso4 = timeutils.isotime(dt4)

        UUID3 = _gen_uuid()
        extra_fixture = self.get_fixture(id=UUID3, name='fake image #3')

        db_api.image_create(self.context, extra_fixture)
        db_api.image_destroy(self.context, UUID3)

        UUID4 = _gen_uuid()
        extra_fixture = self.get_fixture(id=UUID4, name='fake image #4',
                                         created_at=dt3, updated_at=dt3)

        db_api.image_create(self.context, extra_fixture)

        # Check a standard list, 4 images in db (2 deleted)
        images = self.client.get_images_detailed(filters={})
        self.assertEqualImages(images, (UUID4, UUID2), unjsonify=False)

        # Expect 3 images (1 deleted)
        filters = {'changes-since': iso1}
        images = self.client.get_images(filters=filters)
        self.assertEqualImages(images, (UUID4, UUID3, UUID2), unjsonify=False)

        # Expect 1 images (0 deleted)
        filters = {'changes-since': iso2}
        images = self.client.get_images_detailed(filters=filters)
        self.assertEqualImages(images, (UUID4,), unjsonify=False)

        # Expect 0 images (0 deleted)
        filters = {'changes-since': iso4}
        images = self.client.get_images(filters=filters)
        self.assertEqualImages(images, (), unjsonify=False)
    def test_get_image_details_with_changes_since(self):
        """Tests that a detailed call can be filtered by changes-since"""
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)

        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)

        dt3 = timeutils.utcnow() + datetime.timedelta(2)
        iso3 = timeutils.isotime(dt3)

        dt4 = timeutils.utcnow() + datetime.timedelta(3)
        iso4 = timeutils.isotime(dt4)

        UUID3 = _gen_uuid()
        extra_fixture = {
            "id": UUID3,
            "status": "active",
            "is_public": True,
            "disk_format": "vhd",
            "container_format": "ovf",
            "name": "fake image #3",
            "size": 18,
            "checksum": None,
        }

        db_api.image_create(self.context, extra_fixture)
        db_api.image_destroy(self.context, UUID3)

        UUID4 = _gen_uuid()
        extra_fixture = {
            "id": UUID4,
            "status": "active",
            "is_public": True,
            "disk_format": "ami",
            "container_format": "ami",
            "name": "fake image #4",
            "size": 20,
            "checksum": None,
            "created_at": dt3,
            "updated_at": dt3,
        }

        db_api.image_create(self.context, extra_fixture)

        # Check a standard list, 4 images in db (2 deleted)
        images = self.client.get_images_detailed(filters={})
        self.assertEqual(images[0]["id"], UUID4)
        self.assertEqual(images[1]["id"], UUID2)

        # Expect 3 images (1 deleted)
        filters = {"changes-since": iso1}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 3)
        self.assertEqual(images[0]["id"], UUID4)
        self.assertEqual(images[1]["id"], UUID3)  # deleted
        self.assertEqual(images[2]["id"], UUID2)

        # Expect 1 images (0 deleted)
        filters = {"changes-since": iso2}
        images = self.client.get_images_detailed(filters=filters)
        self.assertEquals(len(images), 1)
        self.assertEqual(images[0]["id"], UUID4)

        # Expect 0 images (0 deleted)
        filters = {"changes-since": iso4}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 0)
Beispiel #31
0
 def remove(self, task):
     payload = format_task_notification(task)
     payload['deleted'] = True
     payload['deleted_at'] = timeutils.isotime()
     self.notifier.info('task.delete', payload)
     return super(TaskRepoProxy, self).add(task)
Beispiel #32
0
 def remove(self, image):
     super(ImageRepoProxy, self).remove(image)
     payload = format_image_notification(image)
     payload['deleted'] = True
     payload['deleted_at'] = timeutils.isotime()
     self.notifier.info('image.delete', payload)
Beispiel #33
0
 def remove(self, task):
     payload = format_task_notification(task)
     payload["deleted"] = True
     payload["deleted_at"] = timeutils.isotime()
     self.notifier.info("task.delete", payload)
     super(TaskRepoProxy, self).remove(task)
Beispiel #34
0
 def _serialize_datetimes(image):
     for (key, value) in image.iteritems():
         if isinstance(value, datetime.datetime):
             image[key] = timeutils.isotime(value)
    def test_results_filtering(self):
        self.cleanup()
        self.start_servers(**self.__dict__.copy())

        api_port = self.api_port
        registry_port = self.registry_port

        # 1. Add some images
        _add_cmd = "bin/glance --port=%d add is_public=True" % api_port
        _add_args = [
            "name=Name1 disk_format=vhd container_format=ovf foo=bar",
            "name=Name2 disk_format=ami container_format=ami foo=bar",
            "name=Name3 disk_format=vhd container_format=ovf foo=baz "
            "min_disk=7 min_ram=256",
        ]

        image_ids = []
        for i, args in enumerate(_add_args):
            cmd = "%s %s" % (_add_cmd, args)
            exitcode, out, err = execute(cmd)
            self.assertEqual(0, exitcode)
            self.assertTrue(out.strip().find('Added new image with ID:') > -1)
            image_ids.append(out.strip().split(':')[1].strip())

        _base_cmd = "bin/glance --port=%d" % api_port
        _index_cmd = "%s index -f" % (_base_cmd, )

        # 2. Check name filter
        cmd = "name=Name2"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))
        image_lines = out.split("\n")[2:-1]

        self.assertEqual(0, exitcode)
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 3. Check disk_format filter
        cmd = "disk_format=vhd"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(2, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[2])
        self.assertEqual(image_lines[1].split()[0], image_ids[0])

        # 4. Check container_format filter
        cmd = "container_format=ami"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 5. Check container_format filter
        cmd = "container_format=ami"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 6. Check status filter
        cmd = "status=killed"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(0, len(image_lines))

        # 7. Check property filter
        cmd = "foo=bar"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(2, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])
        self.assertEqual(image_lines[1].split()[0], image_ids[0])

        # 8. Check multiple filters
        cmd = "name=Name2 foo=bar"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 9. Check past changes-since
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)
        cmd = "changes-since=%s" % iso1
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(3, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[2])
        self.assertEqual(image_lines[1].split()[0], image_ids[1])
        self.assertEqual(image_lines[2].split()[0], image_ids[0])

        # 10. Check future changes-since
        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)
        cmd = "changes-since=%s" % iso2
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(0, len(image_lines))

        # 11. Ensure details call also respects filters
        _details_cmd = "%s details" % (_base_cmd, )
        cmd = "foo=bar"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[1:-1]
        self.assertEqual(30, len(image_lines))
        self.assertEqual(image_lines[1].split()[1], image_ids[1])
        self.assertEqual(image_lines[16].split()[1], image_ids[0])

        # 12. Check min_ram filter
        cmd = "min_ram=256"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(14, len(image_lines))
        self.assertEqual(image_lines[0].split()[1], image_ids[2])

        # 13. Check min_disk filter
        cmd = "min_disk=7"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(14, len(image_lines))
        self.assertEqual(image_lines[0].split()[1], image_ids[2])

        self.stop_servers()
Beispiel #36
0
 def remove(self, task):
     payload = format_task_notification(task)
     payload['deleted'] = True
     payload['deleted_at'] = timeutils.isotime()
     self.notifier.info('task.delete', payload)
     super(TaskRepoProxy, self).remove(task)
Beispiel #37
0
 def remove(self, image):
     super(ImageRepoProxy, self).remove(image)
     payload = format_image_notification(image)
     payload['deleted'] = True
     payload['deleted_at'] = timeutils.isotime()
     self.notifier.info('image.delete', payload)
Beispiel #38
0
    def test_get_image_details_with_changes_since(self):
        """Tests that a detailed call can be filtered by changes-since"""
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)

        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)

        dt3 = timeutils.utcnow() + datetime.timedelta(2)
        iso3 = timeutils.isotime(dt3)

        dt4 = timeutils.utcnow() + datetime.timedelta(3)
        iso4 = timeutils.isotime(dt4)

        UUID3 = _gen_uuid()
        extra_fixture = {'id': UUID3,
                         'status': 'active',
                         'is_public': True,
                         'disk_format': 'vhd',
                         'container_format': 'ovf',
                         'name': 'fake image #3',
                         'size': 18,
                         'checksum': None}

        db_api.image_create(self.context, extra_fixture)
        db_api.image_destroy(self.context, UUID3)

        UUID4 = _gen_uuid()
        extra_fixture = {'id': UUID4,
                         'status': 'active',
                         'is_public': True,
                         'disk_format': 'ami',
                         'container_format': 'ami',
                         'name': 'fake image #4',
                         'size': 20,
                         'checksum': None,
                         'created_at': dt3,
                         'updated_at': dt3}

        db_api.image_create(self.context, extra_fixture)

        # Check a standard list, 4 images in db (2 deleted)
        images = self.client.get_images_detailed(filters={})
        self.assertEqual(images[0]['id'], UUID4)
        self.assertEqual(images[1]['id'], UUID2)

        # Expect 3 images (1 deleted)
        filters = {'changes-since': iso1}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 3)
        self.assertEqual(images[0]['id'], UUID4)
        self.assertEqual(images[1]['id'], UUID3)  # deleted
        self.assertEqual(images[2]['id'], UUID2)

        # Expect 1 images (0 deleted)
        filters = {'changes-since': iso2}
        images = self.client.get_images_detailed(filters=filters)
        self.assertEquals(len(images), 1)
        self.assertEqual(images[0]['id'], UUID4)

        # Expect 0 images (0 deleted)
        filters = {'changes-since': iso4}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 0)
Beispiel #39
0
 def _serialize_datetimes(image):
     for (key, value) in image.iteritems():
         if isinstance(value, datetime.datetime):
             image[key] = timeutils.isotime(value)
Beispiel #40
0
    def test_results_filtering(self):
        self.cleanup()
        self.start_servers(**self.__dict__.copy())

        api_port = self.api_port
        registry_port = self.registry_port

        # 1. Add some images
        _add_cmd = "bin/glance --port=%d add is_public=True" % api_port
        _add_args = [
            "name=Name1 disk_format=vhd container_format=ovf foo=bar",
            "name=Name2 disk_format=ami container_format=ami foo=bar",
            "name=Name3 disk_format=vhd container_format=ovf foo=baz " "min_disk=7 min_ram=256",
        ]

        image_ids = []
        for i, args in enumerate(_add_args):
            cmd = "%s %s" % (_add_cmd, args)
            exitcode, out, err = execute(cmd)
            self.assertEqual(0, exitcode)
            self.assertTrue(out.strip().find("Added new image with ID:") > -1)
            image_ids.append(out.strip().split(":")[1].strip())

        _base_cmd = "bin/glance --port=%d" % api_port
        _index_cmd = "%s index -f" % (_base_cmd,)

        # 2. Check name filter
        cmd = "name=Name2"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))
        image_lines = out.split("\n")[2:-1]

        self.assertEqual(0, exitcode)
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 3. Check disk_format filter
        cmd = "disk_format=vhd"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(2, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[2])
        self.assertEqual(image_lines[1].split()[0], image_ids[0])

        # 4. Check container_format filter
        cmd = "container_format=ami"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 5. Check container_format filter
        cmd = "container_format=ami"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 6. Check status filter
        cmd = "status=killed"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(0, len(image_lines))

        # 7. Check property filter
        cmd = "foo=bar"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(2, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])
        self.assertEqual(image_lines[1].split()[0], image_ids[0])

        # 8. Check multiple filters
        cmd = "name=Name2 foo=bar"
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(1, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[1])

        # 9. Check past changes-since
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)
        cmd = "changes-since=%s" % iso1
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(3, len(image_lines))
        self.assertEqual(image_lines[0].split()[0], image_ids[2])
        self.assertEqual(image_lines[1].split()[0], image_ids[1])
        self.assertEqual(image_lines[2].split()[0], image_ids[0])

        # 10. Check future changes-since
        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)
        cmd = "changes-since=%s" % iso2
        exitcode, out, err = execute("%s %s" % (_index_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(0, len(image_lines))

        # 11. Ensure details call also respects filters
        _details_cmd = "%s details" % (_base_cmd,)
        cmd = "foo=bar"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[1:-1]
        self.assertEqual(26, len(image_lines))
        self.assertEqual(image_lines[1].split()[1], image_ids[1])
        self.assertEqual(image_lines[14].split()[1], image_ids[0])

        # 12. Check min_ram filter
        cmd = "min_ram=256"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(12, len(image_lines))
        self.assertEqual(image_lines[0].split()[1], image_ids[2])

        # 13. Check min_disk filter
        cmd = "min_disk=7"
        exitcode, out, err = execute("%s %s" % (_details_cmd, cmd))

        self.assertEqual(0, exitcode)
        image_lines = out.split("\n")[2:-1]
        self.assertEqual(12, len(image_lines))
        self.assertEqual(image_lines[0].split()[1], image_ids[2])

        self.stop_servers()
Beispiel #41
0
    def test_get_image_details_with_changes_since(self):
        """Tests that a detailed call can be filtered by changes-since"""
        dt1 = timeutils.utcnow() - datetime.timedelta(1)
        iso1 = timeutils.isotime(dt1)

        dt2 = timeutils.utcnow() + datetime.timedelta(1)
        iso2 = timeutils.isotime(dt2)

        dt3 = timeutils.utcnow() + datetime.timedelta(2)
        iso3 = timeutils.isotime(dt3)

        dt4 = timeutils.utcnow() + datetime.timedelta(3)
        iso4 = timeutils.isotime(dt4)

        UUID3 = _gen_uuid()
        extra_fixture = {
            'id': UUID3,
            'status': 'active',
            'is_public': True,
            'disk_format': 'vhd',
            'container_format': 'ovf',
            'name': 'fake image #3',
            'size': 18,
            'checksum': None
        }

        db_api.image_create(self.context, extra_fixture)
        db_api.image_destroy(self.context, UUID3)

        UUID4 = _gen_uuid()
        extra_fixture = {
            'id': UUID4,
            'status': 'active',
            'is_public': True,
            'disk_format': 'ami',
            'container_format': 'ami',
            'name': 'fake image #4',
            'size': 20,
            'checksum': None,
            'created_at': dt3,
            'updated_at': dt3
        }

        db_api.image_create(self.context, extra_fixture)

        # Check a standard list, 4 images in db (2 deleted)
        images = self.client.get_images_detailed(filters={})
        self.assertEqual(images[0]['id'], UUID4)
        self.assertEqual(images[1]['id'], UUID2)

        # Expect 3 images (1 deleted)
        filters = {'changes-since': iso1}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 3)
        self.assertEqual(images[0]['id'], UUID4)
        self.assertEqual(images[1]['id'], UUID3)  # deleted
        self.assertEqual(images[2]['id'], UUID2)

        # Expect 1 images (0 deleted)
        filters = {'changes-since': iso2}
        images = self.client.get_images_detailed(filters=filters)
        self.assertEquals(len(images), 1)
        self.assertEqual(images[0]['id'], UUID4)

        # Expect 0 images (0 deleted)
        filters = {'changes-since': iso4}
        images = self.client.get_images(filters=filters)
        self.assertEquals(len(images), 0)