Merge "Add library support for v2 image update"
This commit is contained in:
@@ -75,3 +75,25 @@ class Controller(object):
|
|||||||
def delete(self, image_id):
|
def delete(self, image_id):
|
||||||
"""Delete an image."""
|
"""Delete an image."""
|
||||||
self.http_client.json_request('DELETE', 'v2/images/%s' % image_id)
|
self.http_client.json_request('DELETE', 'v2/images/%s' % image_id)
|
||||||
|
|
||||||
|
def update(self, image_id, **kwargs):
|
||||||
|
"""
|
||||||
|
Update attributes of an image.
|
||||||
|
|
||||||
|
:param image_id: ID of the image to modify.
|
||||||
|
:param **kwargs: Image attribute names and their new values.
|
||||||
|
"""
|
||||||
|
image = self.get(image_id)
|
||||||
|
for (key, value) in kwargs.items():
|
||||||
|
setattr(image, key, value)
|
||||||
|
|
||||||
|
url = '/v2/images/%s' % image_id
|
||||||
|
hdrs = {'Content-Type': 'application/openstack-images-v2.0-json-patch'}
|
||||||
|
self.http_client.raw_request('PATCH', url,
|
||||||
|
headers=hdrs,
|
||||||
|
body=image.patch)
|
||||||
|
|
||||||
|
#NOTE(bcwaldon): calling image.patch doesn't clear the changes, so
|
||||||
|
# we need to fetch the image again to get a clean history. This is
|
||||||
|
# an obvious optimization for warlock
|
||||||
|
return self.get(image_id)
|
||||||
|
@@ -72,6 +72,10 @@ fixtures = {
|
|||||||
'name': 'image-1',
|
'name': 'image-1',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
'PATCH': (
|
||||||
|
{},
|
||||||
|
'',
|
||||||
|
),
|
||||||
},
|
},
|
||||||
'v2/images/87b634c1-f893-33c9-28a9-e5673c99239a': {
|
'v2/images/87b634c1-f893-33c9-28a9-e5673c99239a': {
|
||||||
'DELETE': (
|
'DELETE': (
|
||||||
@@ -102,7 +106,7 @@ fixtures = {
|
|||||||
},
|
},
|
||||||
'CCC',
|
'CCC',
|
||||||
),
|
),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -180,3 +184,22 @@ class TestController(testtools.TestCase):
|
|||||||
body = self.controller.data('1b1c6366-dd57-11e1-af0f-02163e68b1d8')
|
body = self.controller.data('1b1c6366-dd57-11e1-af0f-02163e68b1d8')
|
||||||
body = ''.join([b for b in body])
|
body = ''.join([b for b in body])
|
||||||
self.assertEqual(body, 'CCC')
|
self.assertEqual(body, 'CCC')
|
||||||
|
|
||||||
|
def test_update_without_data(self):
|
||||||
|
image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
|
||||||
|
params = {'name': 'pong'}
|
||||||
|
image = self.controller.update(image_id, **params)
|
||||||
|
expect_hdrs = {
|
||||||
|
'Content-Type': 'application/openstack-images-v2.0-json-patch',
|
||||||
|
}
|
||||||
|
expect_body = '[{"path": "/name", "value": "pong", "op": "replace"}]'
|
||||||
|
expect = [
|
||||||
|
('GET', '/v2/images/%s' % image_id, {}, None),
|
||||||
|
('PATCH', '/v2/images/%s' % image_id, expect_hdrs, expect_body),
|
||||||
|
('GET', '/v2/images/%s' % image_id, {}, None),
|
||||||
|
]
|
||||||
|
self.assertEqual(self.api.calls, expect)
|
||||||
|
self.assertEqual(image.id, image_id)
|
||||||
|
#NOTE(bcwaldon): due to limitations of our fake api framework, the name
|
||||||
|
# will not actually change - yet in real life it will...
|
||||||
|
self.assertEqual(image.name, 'image-1')
|
||||||
|
Reference in New Issue
Block a user