Fix wrong check when create image without data.

The default value of 'locations' is [].So there is a wrong check in
db/sqlalchemy/api.py.
When create an image without data, The function '_image_locations_set'
should not be executed.

Change-Id: Ie4cb29ab0d714d3ce67f717d5eaf641424efa5b7
Closes-bug:#1471080
This commit is contained in:
wangxiyuan 2015-07-03 11:45:57 +08:00
parent 3bef5bddcf
commit 356e66c239
2 changed files with 7 additions and 1 deletions

View File

@ -795,7 +795,7 @@ def _image_update(context, values, image_id, purge_props=False,
_set_properties_for_image(context, image_ref, properties, purge_props,
session)
if location_data is not None:
if location_data:
_image_locations_set(context, image_ref.id, location_data,
session=session)

View File

@ -191,6 +191,12 @@ class DriverTests(object):
for l in image['locations']]
self.assertEqual(locations, actual)
def test_image_create_without_locations(self):
locations = []
fixture = {'status': 'queued',
'locations': locations}
self.db_api.image_create(self.context, fixture)
def test_image_create_with_location_data(self):
location_data = [{'url': 'a', 'metadata': {'key': 'value'},
'status': 'active'},