Merge "Fix update_image unsupported media type"
This commit is contained in:
commit
c8f5194fdc
@ -158,7 +158,8 @@ class Proxy(proxy2.BaseProxy):
|
|||||||
:returns: The updated image
|
:returns: The updated image
|
||||||
:rtype: :class:`~openstack.image.v2.image.Image`
|
:rtype: :class:`~openstack.image.v2.image.Image`
|
||||||
"""
|
"""
|
||||||
return self._update(_image.Image, image, **attrs)
|
img = self._get_resource(_image.Image, image)
|
||||||
|
return img.update(self._session, **attrs)
|
||||||
|
|
||||||
def deactivate_image(self, image):
|
def deactivate_image(self, image):
|
||||||
"""Deactivate an image
|
"""Deactivate an image
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import jsonpatch
|
||||||
|
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from openstack.image import image_service
|
from openstack.image import image_service
|
||||||
from openstack import resource2
|
from openstack import resource2
|
||||||
@ -283,3 +285,17 @@ class Image(resource2.Resource):
|
|||||||
"Unable to verify the integrity of image %s" % (self.id))
|
"Unable to verify the integrity of image %s" % (self.id))
|
||||||
|
|
||||||
return resp.content
|
return resp.content
|
||||||
|
|
||||||
|
def update(self, session, **attrs):
|
||||||
|
url = utils.urljoin(self.base_path, self.id)
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/openstack-images-v2.1-json-patch',
|
||||||
|
'Accept': ''
|
||||||
|
}
|
||||||
|
original = self.to_dict()
|
||||||
|
patch_string = jsonpatch.make_patch(original, attrs).to_string()
|
||||||
|
resp = session.patch(url, endpoint_filter=self.service,
|
||||||
|
data=patch_string,
|
||||||
|
headers=headers)
|
||||||
|
self._translate_response(resp, has_body=True)
|
||||||
|
return self
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -292,3 +294,33 @@ class TestImage(testtools.TestCase):
|
|||||||
stream=True)
|
stream=True)
|
||||||
|
|
||||||
self.assertEqual(rv, resp)
|
self.assertEqual(rv, resp)
|
||||||
|
|
||||||
|
def test_image_update(self):
|
||||||
|
sot = image.Image(**EXAMPLE)
|
||||||
|
# Let the translate pass through, that portion is tested elsewhere
|
||||||
|
sot._translate_response = mock.Mock()
|
||||||
|
|
||||||
|
resp = mock.Mock()
|
||||||
|
resp.content = b"abc"
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/openstack-images-v2.1-json-patch',
|
||||||
|
'Accept': '',
|
||||||
|
}
|
||||||
|
resp.headers = headers
|
||||||
|
resp.status_code = 200
|
||||||
|
self.sess.patch.return_value = resp
|
||||||
|
|
||||||
|
value = ('[{"value": "fake_name", "op": "replace", "path": "/name"}, '
|
||||||
|
'{"value": "fake_value", "op": "add", '
|
||||||
|
'"path": "/new_property"}]')
|
||||||
|
fake_img = sot.to_dict()
|
||||||
|
fake_img['name'] = 'fake_name'
|
||||||
|
fake_img['new_property'] = 'fake_value'
|
||||||
|
|
||||||
|
sot.update(self.sess, **fake_img)
|
||||||
|
url = 'images/' + IDENTIFIER
|
||||||
|
self.sess.patch.assert_called_once()
|
||||||
|
call = self.sess.patch.call_args
|
||||||
|
call_args, call_kwargs = call
|
||||||
|
self.assertEqual(url, call_args[0])
|
||||||
|
self.assertEqual(json.loads(value), json.loads(call_kwargs['data']))
|
||||||
|
@ -16,8 +16,11 @@ from openstack import exceptions
|
|||||||
from openstack.image.v2 import _proxy
|
from openstack.image.v2 import _proxy
|
||||||
from openstack.image.v2 import image
|
from openstack.image.v2 import image
|
||||||
from openstack.image.v2 import member
|
from openstack.image.v2 import member
|
||||||
|
from openstack.tests.unit.image.v2 import test_image as fake_image
|
||||||
from openstack.tests.unit import test_proxy_base2
|
from openstack.tests.unit import test_proxy_base2
|
||||||
|
|
||||||
|
EXAMPLE = fake_image.EXAMPLE
|
||||||
|
|
||||||
|
|
||||||
class TestImageProxy(test_proxy_base2.TestProxyBase):
|
class TestImageProxy(test_proxy_base2.TestProxyBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -53,8 +56,19 @@ class TestImageProxy(test_proxy_base2.TestProxyBase):
|
|||||||
def test_image_delete_ignore(self):
|
def test_image_delete_ignore(self):
|
||||||
self.verify_delete(self.proxy.delete_image, image.Image, True)
|
self.verify_delete(self.proxy.delete_image, image.Image, True)
|
||||||
|
|
||||||
def test_image_update(self):
|
@mock.patch("openstack.resource2.Resource._translate_response")
|
||||||
self.verify_update(self.proxy.update_image, image.Image)
|
@mock.patch("openstack.proxy2.BaseProxy._get")
|
||||||
|
@mock.patch("openstack.image.v2.image.Image.update")
|
||||||
|
def test_image_update(self, mock_update_image, mock_get_image,
|
||||||
|
mock_transpose):
|
||||||
|
original_image = image.Image(**EXAMPLE)
|
||||||
|
mock_get_image.return_value = original_image
|
||||||
|
EXAMPLE['name'] = 'fake_name'
|
||||||
|
updated_image = image.Image(**EXAMPLE)
|
||||||
|
mock_update_image.return_value = updated_image.to_dict()
|
||||||
|
result = self.proxy.update_image(original_image,
|
||||||
|
**updated_image.to_dict())
|
||||||
|
self.assertEqual('fake_name', result.get('name'))
|
||||||
|
|
||||||
def test_image_get(self):
|
def test_image_get(self):
|
||||||
self.verify_get(self.proxy.get_image, image.Image)
|
self.verify_get(self.proxy.get_image, image.Image)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# of appearance. Changing the order has an impact on the overall integration
|
# of appearance. Changing the order has an impact on the overall integration
|
||||||
# process, which may cause wedges in the gate later.
|
# process, which may cause wedges in the gate later.
|
||||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||||
|
jsonpatch>=1.1 # BSD
|
||||||
six>=1.9.0 # MIT
|
six>=1.9.0 # MIT
|
||||||
stevedore>=1.20.0 # Apache-2.0
|
stevedore>=1.20.0 # Apache-2.0
|
||||||
os-client-config>=1.27.0 # Apache-2.0
|
os-client-config>=1.27.0 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user