From 99309f6690a92b160f120186515cf0fa90c04d70 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Tue, 27 Oct 2015 15:22:46 +0300 Subject: [PATCH] Adding ability to register image without description set_description method of SaharaImageManager was changed so that its description parameter became optional Change-Id: Ib357872e658b9c74f12cfedc1b505ce00e555d0f Closes-bug: #1510505 --- .../tests/unit/utils/openstack/test_images.py | 21 +++++++++++++++++-- sahara/utils/openstack/images.py | 8 +++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sahara/tests/unit/utils/openstack/test_images.py b/sahara/tests/unit/utils/openstack/test_images.py index 0fad0c8c..f0a2a8c3 100644 --- a/sahara/tests/unit/utils/openstack/test_images.py +++ b/sahara/tests/unit/utils/openstack/test_images.py @@ -27,10 +27,13 @@ class FakeImage(object): class TestImages(base.SaharaTestCase): - @mock.patch('sahara.utils.openstack.base.url_for', return_value='') - def test_list_registered_images(self, url_for_mock): + def setUp(self): + super(TestImages, self).setUp() self.override_config('auth_uri', 'https://127.0.0.1:8080/v3/', 'keystone_authtoken') + + @mock.patch('sahara.utils.openstack.base.url_for', return_value='') + def test_list_registered_images(self, url_for_mock): some_images = [ FakeImage('foo', ['bar', 'baz'], 'test'), FakeImage('baz', [], 'test'), @@ -57,3 +60,17 @@ class TestImages(base.SaharaTestCase): images = nova.images.list_registered(tags=['bar', 'eggs']) self.assertEqual(0, len(images)) + + @mock.patch('novaclient.v2.images.ImageManager.set_meta') + def test_set_description(self, set_meta): + with mock.patch('sahara.utils.openstack.base.url_for'): + nova = nova_client.client() + nova.images.set_description('id', 'ubuntu') + self.assertEqual( + ('id', {'_sahara_username': 'ubuntu'}), set_meta.call_args[0]) + + nova.images.set_description('id', 'ubuntu', 'descr') + self.assertEqual( + ('id', {'_sahara_description': 'descr', + '_sahara_username': 'ubuntu'}), + set_meta.call_args[0]) diff --git a/sahara/utils/openstack/images.py b/sahara/utils/openstack/images.py index ee4fdbb4..5867df15 100644 --- a/sahara/utils/openstack/images.py +++ b/sahara/utils/openstack/images.py @@ -85,10 +85,10 @@ class SaharaImageManager(images.ImageManager): Ubuntu 13.04 x64 with Java 1.7u21 and Apache Hadoop 1.1.1, ubuntu """ - self.set_meta(image, { - PROP_DESCR: description, - PROP_USERNAME: username, - }) + meta = {PROP_USERNAME: username} + if description: + meta[PROP_DESCR] = description + self.set_meta(image, meta) def unset_description(self, image): """Unsets all Sahara-related information.