Merge "Raise database exception instead of returning None"

This commit is contained in:
Zuul 2018-09-26 14:03:49 +00:00 committed by Gerrit Code Review
commit cd5b0fdfa5
2 changed files with 15 additions and 17 deletions

View File

@ -362,30 +362,27 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
if trust_id:
host_details.update({'trust_id': trust_id})
host = db_api.host_create(host_details)
except db_ex.BlazarDBException:
except db_ex.BlazarDBException as e:
# We need to rollback
# TODO(sbauza): Investigate use of Taskflow for atomic
# transactions
pool.remove_computehost(self.freepool_name,
host_details['service_name'])
if host:
for key in extra_capabilities:
values = {'computehost_id': host['id'],
'capability_name': key,
'capability_value': extra_capabilities[key],
}
try:
db_api.host_extra_capability_create(values)
except db_ex.BlazarDBException:
cantaddextracapability.append(key)
raise e
for key in extra_capabilities:
values = {'computehost_id': host['id'],
'capability_name': key,
'capability_value': extra_capabilities[key],
}
try:
db_api.host_extra_capability_create(values)
except db_ex.BlazarDBException:
cantaddextracapability.append(key)
if cantaddextracapability:
raise manager_ex.CantAddExtraCapability(
keys=cantaddextracapability,
host=host['id'])
if host:
return self.get_computehost(host['id'])
else:
return None
return self.get_computehost(host['id'])
def is_updatable_extra_capability(self, capability):
reservations = db_utils.get_reservations_by_host_id(

View File

@ -254,8 +254,9 @@ class PhysicalHostPluginTestCase(tests.TestCase):
def fake_db_host_create(*args, **kwargs):
raise db_exceptions.BlazarDBException
self.db_host_create.side_effect = fake_db_host_create
host = self.fake_phys_plugin.create_computehost(self.fake_host)
self.assertIsNone(host)
self.assertRaises(db_exceptions.BlazarDBException,
self.fake_phys_plugin.create_computehost,
self.fake_host)
def test_create_host_having_issue_when_storing_extra_capability(self):
def fake_db_host_extra_capability_create(*args, **kwargs):