コード例 #1
0
ファイル: test_utils.py プロジェクト: young8/openstack-bill
    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])
コード例 #2
0
ファイル: test_utils.py プロジェクト: young8/openstack-bill
    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/glance-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])
コード例 #3
0
 def prefetch_cache_image(self, image_id):
     """
     Pre-fetch a specified image from the cache
     """
     res = self.do_request("HEAD", "/images/%s" % image_id)
     image = utils.get_image_meta_from_headers(res)
     self.do_request("PUT", "/cached_images/%s" % image_id)
     return True
コード例 #4
0
ファイル: client.py プロジェクト: Cerberus98/glance
 def prefetch_cache_image(self, image_id):
     """
     Pre-fetch a specified image from the cache
     """
     res = self.do_request("HEAD", "/images/%s" % image_id)
     image = utils.get_image_meta_from_headers(res)
     self.do_request("PUT", "/cached_images/%s" % image_id)
     return True
コード例 #5
0
ファイル: client.py プロジェクト: Cerberus98/glance
    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
コード例 #6
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
コード例 #7
0
ファイル: test_utils.py プロジェクト: Cerberus98/glance
    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])
コード例 #8
0
ファイル: client.py プロジェクト: Cerberus98/glance
    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)
コード例 #9
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)
コード例 #10
0
ファイル: test_utils.py プロジェクト: Cerberus98/glance
    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/glance-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])
コード例 #11
0
ファイル: images.py プロジェクト: emonty/glance
 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
コード例 #12
0
ファイル: images.py プロジェクト: young8/openstack-bill
 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