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
This commit is contained in:
Andrey Pavlov 2015-10-27 15:22:46 +03:00
parent 63c5a1d6d9
commit 99309f6690
2 changed files with 23 additions and 6 deletions

View File

@ -27,10 +27,13 @@ class FakeImage(object):
class TestImages(base.SaharaTestCase): class TestImages(base.SaharaTestCase):
@mock.patch('sahara.utils.openstack.base.url_for', return_value='') def setUp(self):
def test_list_registered_images(self, url_for_mock): super(TestImages, self).setUp()
self.override_config('auth_uri', 'https://127.0.0.1:8080/v3/', self.override_config('auth_uri', 'https://127.0.0.1:8080/v3/',
'keystone_authtoken') 'keystone_authtoken')
@mock.patch('sahara.utils.openstack.base.url_for', return_value='')
def test_list_registered_images(self, url_for_mock):
some_images = [ some_images = [
FakeImage('foo', ['bar', 'baz'], 'test'), FakeImage('foo', ['bar', 'baz'], 'test'),
FakeImage('baz', [], 'test'), FakeImage('baz', [], 'test'),
@ -57,3 +60,17 @@ class TestImages(base.SaharaTestCase):
images = nova.images.list_registered(tags=['bar', 'eggs']) images = nova.images.list_registered(tags=['bar', 'eggs'])
self.assertEqual(0, len(images)) 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])

View File

@ -85,10 +85,10 @@ class SaharaImageManager(images.ImageManager):
Ubuntu 13.04 x64 with Java 1.7u21 and Apache Hadoop 1.1.1, ubuntu Ubuntu 13.04 x64 with Java 1.7u21 and Apache Hadoop 1.1.1, ubuntu
""" """
self.set_meta(image, { meta = {PROP_USERNAME: username}
PROP_DESCR: description, if description:
PROP_USERNAME: username, meta[PROP_DESCR] = description
}) self.set_meta(image, meta)
def unset_description(self, image): def unset_description(self, image):
"""Unsets all Sahara-related information. """Unsets all Sahara-related information.