def test_image_create_v2_additional_props(self):
        request = self.mock_rest_request(body='''{"name": "Test",
            "disk_format": "raw", "import_data": true,
            "container_format": "docker",
            "visibility": "public", "protected": false,
            "arbitrary": "property", "another": "prop",
            "source_type": "url", "image_url": "test.com" }''')
        self.mock_VERSIONS.active = 2
        new = self.mock_image_create.return_value
        new.to_dict.return_value = {'name': 'testimage'}
        new.name = 'testimage'

        metadata = {
            'name': 'Test',
            'disk_format': 'raw',
            'container_format': 'docker',
            'copy_from': 'test.com',
            'visibility': 'public',
            'protected': False,
            'min_disk': 0,
            'min_ram': 0,
            'arbitrary': 'property',
            'another': 'prop'
        }
        response = glance.Images().put(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'], '/api/glance/images/testimage')
        self.mock_image_create.assert_called_once_with(request, **metadata)
    def test_image_create_v2_private(self):
        request = self.mock_rest_request(body='''{"name": "Test",
            "disk_format": "aki", "import_data": false,
            "visibility": "private", "container_format": "aki",
            "protected": false, "image_url": "test.com",
            "source_type": "url", "architecture": "testArch",
            "description": "description", "kernel": "kernel",
            "min_disk": 10, "min_ram": 5, "ramdisk": 10 }
        ''')
        self.mock_VERSIONS.active = 2
        new = self.mock_image_create.return_value
        new.to_dict.return_value = {'name': 'testimage'}
        new.name = 'testimage'

        metadata = {
            'name': 'Test',
            'disk_format': 'aki',
            'container_format': 'aki',
            'visibility': 'private',
            'protected': False,
            'min_disk': 10,
            'min_ram': 5,
            'location': 'test.com',
            'description': 'description',
            'architecture': 'testArch',
            'ramdisk_id': 10,
            'kernel_id': 'kernel',
        }

        response = glance.Images().put(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response.content.decode('utf-8'),
                         '{"name": "testimage"}')
        self.assertEqual(response['location'], '/api/glance/images/testimage')
        self.mock_image_create.assert_called_once_with(request, **metadata)
Exemple #3
0
    def test_image_create_v1_required(self, gc):
        request = self.mock_rest_request(body='''{"name": "Test",
            "disk_format": "raw", "import_data": true,
            "container_format": "docker",
            "visibility": "public", "protected": false,
            "source_type": "url", "image_url": "test.com" }''')
        gc.VERSIONS.active = 1
        new = gc.image_create.return_value
        new.to_dict.return_value = {'name': 'testimage'}
        new.name = 'testimage'

        metadata = {
            'name': 'Test',
            'disk_format': 'raw',
            'container_format': 'docker',
            'copy_from': 'test.com',
            'is_public': True,
            'protected': False,
            'min_disk': 0,
            'min_ram': 0,
            'properties': {}
        }
        response = glance.Images().put(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'], '/api/glance/images/testimage')
        gc.image_create.assert_called_once_with(request, **metadata)
    def test_image_get_list_detailed(self):
        kwargs = {
            'sort_dir': 'desc',
            'sort_key': 'namespace',
            'marker': 1,
            'paginate': False,
        }
        filters = {'name': 'fedora'}
        request = self.mock_rest_request(**{'GET': dict(kwargs, **filters)})
        self.mock_image_list_detailed.return_value = ([
            mock.Mock(**{'to_dict.return_value': {
                'name': 'fedora'
            }}),
            mock.Mock(**{'to_dict.return_value': {
                'name': 'cirros'
            }})
        ], False, False)

        response = glance.Images().get(request)
        self.assertStatusCode(response, 200)
        self.assertEqual(
            response.json, {
                "items": [{
                    "name": "fedora"
                }, {
                    "name": "cirros"
                }],
                "has_more_data": False,
                "has_prev_data": False
            })
        self.mock_image_list_detailed.assert_called_once_with(request,
                                                              filters=filters,
                                                              **kwargs)
    def test_image_create_bad_visibility(self, gc):
        request = self.mock_rest_request(body='''{"name": "Test",
            "disk_format": "aki", "import_data": false,
            "visibility": "verybad", "container_format": "aki",
            "protected": false, "image_url": "test.com",
            "source_type": "url", "architecture": "testArch",
            "description": "description", "kernel": "kernel",
            "min_disk": 10, "min_ram": 5, "ramdisk": 10 }
        ''')

        response = glance.Images().post(request)
        self.assertStatusCode(response, 400)
        self.assertEqual(response.content.decode('utf-8'),
                         '"invalid visibility option: verybad"')