Exemplo n.º 1
0
    def get_image_meta(self, image_id):
        """
        Returns a mapping of image metadata from Registry

        :raises exception.NotFound if image is not in registry
        """
        res = self.do_request("HEAD", "/images/%s" % image_id)

        image = utils.get_image_meta_from_headers(res)
        return image
Exemplo n.º 2
0
    def test_boolean_header_values(self):
        """
        Tests that boolean headers like is_public can be set
        to True if any of ('True', 'On', 1) is provided, case-insensitive
        """
        fixtures = [{'is_public': True},
                    {'is_public': 'True'},
                    {'is_public': 'true'}]

        expected = {'is_public': True}

        class FakeResponse():
            pass

        for fixture in fixtures:
            headers = utils.image_meta_to_http_headers(fixture)

            response = FakeResponse()
            response.headers = headers
            result = utils.get_image_meta_from_headers(response)
            for k, v in expected.items():
                self.assertEqual(v, result[k])

        # Ensure False for other values...
        fixtures = [{'is_public': False},
                    {'is_public': 'Off'},
                    {'is_public': 'on'},
                    {'is_public': '1'},
                    {'is_public': 'False'}]

        expected = {'is_public': False}

        for fixture in fixtures:
            headers = utils.image_meta_to_http_headers(fixture)

            response = FakeResponse()
            response.headers = headers
            result = utils.get_image_meta_from_headers(response)
            for k, v in expected.items():
                self.assertEqual(v, result[k])
Exemplo n.º 3
0
    def get_image(self, image_id):
        """
        Returns a tuple with the image's metadata and the raw disk image as
        a mime-encoded blob stream for the supplied opaque image identifier.

        :param image_id: The opaque image identifier

        :retval Tuple containing (image_meta, image_blob)
        :raises exception.NotFound if image is not found
        """
        res = self.do_request("GET", "/images/%s" % image_id)

        image = utils.get_image_meta_from_headers(res)
        return image, base_client.ImageBodyIterator(res)
Exemplo n.º 4
0
    def test_data_passed_properly_through_headers(self):
        """
        Verifies that data is the same after being passed through headers
        """
        fixture = {'name': 'fake public image',
                   'is_public': True,
                   'deleted': False,
                   'type': 'kernel',
                   'name': None,
                   'size': 19,
                   'location': "file:///tmp/tank-tests/2",
                   'properties': {'distro': 'Ubuntu 10.04 LTS'}}
        headers = utils.image_meta_to_http_headers(fixture)

        class FakeResponse():
            pass

        response = FakeResponse()
        response.headers = headers
        result = utils.get_image_meta_from_headers(response)
        for k, v in fixture.iteritems():
            self.assertEqual(v, result[k])
Exemplo n.º 5
0
 def _deserialize(self, request):
     result = {}
     result['image_meta'] = utils.get_image_meta_from_headers(request)
     data = request.body_file if self.has_body(request) else None
     result['image_data'] = data
     return result