From b78285761db0c6cd730117d2c90bc9de2114bf4d Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Fri, 19 Aug 2016 06:10:14 +0000 Subject: Revert "Don't update tags every time" This reverts commit e77322c17931810f4029ef339a791f702f2f4580. Change-Id: Ida826a2aa888beeb76dbe657b2ccd6cb088157ed --- glanceclient/tests/unit/v2/test_images.py | 31 ------------------------------- glanceclient/v2/schemas.py | 9 ++++++--- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/glanceclient/tests/unit/v2/test_images.py b/glanceclient/tests/unit/v2/test_images.py index c7baf94..73bb074 100644 --- a/glanceclient/tests/unit/v2/test_images.py +++ b/glanceclient/tests/unit/v2/test_images.py @@ -381,20 +381,6 @@ data_fixtures = { '', ) }, - '/v2/images/a2b83adc-888e-11e3-8872-78acc0b951d9': { - 'GET': ( - {}, - { - 'id': 'a2b83adc-888e-11e3-8872-78acc0b951d9', - 'name': 'image-1', - 'tags': ['tag1', 'tag2'], - }, - ), - 'PATCH': ( - {}, - '', - ) - }, '/v2/images?limit=%d&os_distro=NixOS' % images.DEFAULT_PAGE_SIZE: { 'GET': ( {}, @@ -996,23 +982,6 @@ class TestController(testtools.TestCase): # will not actually change - yet in real life it will... self.assertEqual('image-3', image.name) - def test_update_add_prop_with_tags(self): - image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d9' - params = {'finn': 'human'} - image = self.controller.update(image_id, **params) - expect_hdrs = { - 'Content-Type': 'application/openstack-images-v2.1-json-patch', - } - expect_body = [[('op', 'add'), ('path', '/finn'), ('value', 'human')]] - 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(expect, self.api.calls) - self.assertEqual(image_id, image.id) - self.assertEqual('image-1', image.name) - def test_update_bad_additionalProperty_type(self): image_id = 'e7e59ff6-fa2e-4075-87d3-1a1398a07dc3' params = {'name': 'pong', 'bad_prop': False} diff --git a/glanceclient/v2/schemas.py b/glanceclient/v2/schemas.py index 8c838f8..8247d31 100644 --- a/glanceclient/v2/schemas.py +++ b/glanceclient/v2/schemas.py @@ -31,12 +31,12 @@ class SchemaBasedModel(warlock.Model): """ def _make_custom_patch(self, new, original): - if 'tags' in new and 'tags' not in original: + if not self.get('tags'): + tags_patch = [] + else: tags_patch = [{"path": "/tags", "value": self.get('tags'), "op": "replace"}] - else: - tags_patch = [] patch_string = jsonpatch.make_patch(original, new).to_string() patch = json.loads(patch_string) @@ -55,6 +55,9 @@ class SchemaBasedModel(warlock.Model): if (name not in original and name in new and prop.get('is_base', True)): original[name] = None + + original['tags'] = None + new['tags'] = None return self._make_custom_patch(new, original) -- cgit v1.2.1