def test_update_purge_props(self, ver, show, translate_from_glance):
        self.flags(glance_api_version=ver)

        image_id = mock.sentinel.image_id
        client = mock.Mock(call=mock.Mock())
        service = glance.GlanceImageService(client=client)

        image_meta = {'properties': {'k1': 'v1'}}
        client.call.return_value = {'k1': 'v1'}
        if ver == 2:
            show.return_value = {'properties': {'k2': 'v2'}}
        translate_from_glance.return_value = image_meta.copy()

        ret = service.update(self.context, image_id, image_meta)
        self.assertDictEqual(image_meta, ret)
        if ver == 2:
            client.call.assert_called_once_with(self.context,
                                                'update',
                                                image_id,
                                                k1='v1',
                                                remove_props=['k2'])
        else:
            client.call.assert_called_once_with(self.context,
                                                'update',
                                                image_id,
                                                properties={'k1': 'v1'},
                                                purge_props=True)
        translate_from_glance.assert_called_once_with(self.context,
                                                      {'k1': 'v1'})
Exemple #2
0
    def _create_image_service(self, client):
        def _fake_create_glance_client(context, netloc, use_ssl):
            return client

        self.mock_object(glance, '_create_glance_client',
                         _fake_create_glance_client)

        client_wrapper = glance.GlanceClientWrapper('fake', 'fake_host', 9292)
        return glance.GlanceImageService(client=client_wrapper)
    def _create_image_service(self, client):
        def _fake_create_glance_client(context, host, port, use_ssl, version):
            return client

        self.stubs.Set(glance, '_create_glance_client',
                       _fake_create_glance_client)

        client_wrapper = glance.GlanceClientWrapper('fake', 'fake_host', 9292)
        return glance.GlanceImageService(client=client_wrapper)
Exemple #4
0
    def test_update_purge_props(self, show, translate_from_glance):
        image_id = mock.sentinel.image_id
        client = mock.Mock(call=mock.Mock())
        service = glance.GlanceImageService(client=client)

        image_meta = {'properties': {'k1': 'v1'}}
        show.return_value = {'properties': {'k2': 'v2'}}
        translate_from_glance.return_value = image_meta.copy()

        ret = service.update(self.context, image_id, image_meta)
        self.assertDictEqual(image_meta, ret)
        client.call.assert_called_once_with(
            self.context, 'update', image_id, k1='v1', remove_props=['k2'])
Exemple #5
0
    def test_update_base_image_ref(self, show, translate_from_glance):
        image_id = mock.sentinel.image_id
        client = mock.Mock(call=mock.Mock())
        service = glance.GlanceImageService(client=client)
        data = '*' * 256
        show.return_value = {}
        translate_from_glance.return_value = {}

        service.update(self.context, image_id, {}, data, base_image_ref=123)
        calls = [
            mock.call.call(self.context,
                           'upload',
                           image_id,
                           data,
                           base_image_ref=123),
            mock.call.call(self.context, 'get', image_id)
        ]
        client.assert_has_calls(calls, any_order=True)