From cb240b1308768a51572864ee675c26cb87fbfe7a Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Mon, 16 Sep 2019 20:37:48 +0200 Subject: [PATCH] Fix image create with tags When passing tags to image create _make_v2_image_params will cast tags to string, while those should remain list. This is required to complete switch in OSC from glanceclient to SDK. Since we use TagMixin remove tags property from resource (it's anyway there). Change-Id: I4f068dfafe4bc85ddda6dbc716dffa0c316500f6 --- openstack/image/v2/_proxy.py | 3 ++- openstack/image/v2/image.py | 2 -- openstack/tests/unit/cloud/test_image.py | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openstack/image/v2/_proxy.py b/openstack/image/v2/_proxy.py index b539b6699..9f9d56226 100644 --- a/openstack/image/v2/_proxy.py +++ b/openstack/image/v2/_proxy.py @@ -26,6 +26,7 @@ from openstack import utils # Rackspace returns this for intermittent import errors _IMAGE_ERROR_396 = "Image cannot be imported. Error code: '396'" _INT_PROPERTIES = ('min_disk', 'min_ram', 'size', 'virtual_size') +_RAW_PROPERTIES = ('protected', 'tags') class Proxy(_base_proxy.BaseImageProxy): @@ -184,7 +185,7 @@ class Proxy(_base_proxy.BaseImageProxy): for k, v in iter(properties.items()): if k in _INT_PROPERTIES: ret[k] = int(v) - elif k == 'protected': + elif k in _RAW_PROPERTIES: ret[k] = v else: if v is None: diff --git a/openstack/image/v2/image.py b/openstack/image/v2/image.py index 13e9ff33c..dd789d5ba 100644 --- a/openstack/image/v2/image.py +++ b/openstack/image/v2/image.py @@ -104,8 +104,6 @@ class Image(resource.Resource, resource.TagMixin, _download.DownloadMixin): store = resource.Body('store') #: The image status. status = resource.Body('status') - #: Tags, if any, that are associated with the image. - tags = resource.Body('tags') #: The date and time when the image was updated. updated_at = resource.Body('updated_at') #: The virtual size of the image. diff --git a/openstack/tests/unit/cloud/test_image.py b/openstack/tests/unit/cloud/test_image.py index 78c56c4b4..12aec72fd 100644 --- a/openstack/tests/unit/cloud/test_image.py +++ b/openstack/tests/unit/cloud/test_image.py @@ -339,7 +339,8 @@ class TestImage(BaseTestImage): u'owner_specified.openstack.sha256': self.fake_image_dict[ 'owner_specified.openstack.sha256'], - u'visibility': u'private'}) + u'visibility': u'private', + u'tags': [u'tag1', u'tag2']}) ), dict(method='PUT', uri=self.get_mock_url( @@ -360,6 +361,7 @@ class TestImage(BaseTestImage): self.cloud.create_image( self.image_name, self.imagefile.name, wait=True, timeout=1, + tags=['tag1', 'tag2'], is_public=False) self.assert_calls()