diff --git a/blazar/plugins/oshosts/host_plugin.py b/blazar/plugins/oshosts/host_plugin.py index fa5d1294..ae4f4fd4 100644 --- a/blazar/plugins/oshosts/host_plugin.py +++ b/blazar/plugins/oshosts/host_plugin.py @@ -355,30 +355,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( diff --git a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py index 10b30ce5..b94622c9 100644 --- a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py +++ b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py @@ -253,8 +253,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):