From: Sukhdev Date: Mon, 9 Mar 2015 21:45:21 +0000 (-0700) Subject: In Arista ML2 delete tenant without any resources X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1ec7c542116f4980ee6680adf261d9a29c5a1d61;p=openstack-build%2Fneutron-build.git In Arista ML2 delete tenant without any resources If there are no resources associated with a tenant, it was deleted from Arista DB in delete_xxx_precommit() methods. The sync mechanism used to make sure that back-end is in sync with DB. Lately, the sync mechanism has been enhanced to support scaled deployment. Therefore, the delete_tenat() call now needs to be invoked from delete_xxx_postcommit() methods instead of delete_xxx_precommit() methods. Additionally, when the tenant is removed from the DB, it is removed from the back-end as well. This removes the dependancy on the sync mechanism to take care of this. [Note: Sync will still do it, but, this way it gets done right away] Closes-bug: 1429968 Change-Id: I2f6ddb01079fe4e2648685ca97d0be06db2d1a55 --- diff --git a/neutron/plugins/ml2/drivers/arista/mechanism_arista.py b/neutron/plugins/ml2/drivers/arista/mechanism_arista.py index 446c174fd..d99cdf4ce 100644 --- a/neutron/plugins/ml2/drivers/arista/mechanism_arista.py +++ b/neutron/plugins/ml2/drivers/arista/mechanism_arista.py @@ -155,8 +155,6 @@ class AristaDriver(driver_api.MechanismDriver): with self.eos_sync_lock: if db_lib.is_network_provisioned(tenant_id, network_id): db_lib.forget_network(tenant_id, network_id) - # if necessary, delete tenant as well. - self.delete_tenant(tenant_id) def delete_network_postcommit(self, context): """Send network delete request to Arista HW.""" @@ -170,6 +168,8 @@ class AristaDriver(driver_api.MechanismDriver): # alive. try: self.rpc.delete_network(tenant_id, network_id) + # if necessary, delete tenant as well. + self.delete_tenant(tenant_id) except arista_exc.AristaRpcError: LOG.info(EOS_UNREACHABLE_MSG) raise ml2_exc.MechanismDriverError() @@ -324,8 +324,6 @@ class AristaDriver(driver_api.MechanismDriver): network_id, tenant_id): db_lib.forget_vm(device_id, host_id, port_id, network_id, tenant_id) - # if necessary, delete tenant as well. - self.delete_tenant(tenant_id) def delete_port_postcommit(self, context): """unPlug a physical host from a network. @@ -356,6 +354,8 @@ class AristaDriver(driver_api.MechanismDriver): port_id, network_id, tenant_id) + # if necessary, delete tenant as well. + self.delete_tenant(tenant_id) except arista_exc.AristaRpcError: LOG.info(EOS_UNREACHABLE_MSG) raise ml2_exc.MechanismDriverError() @@ -370,6 +370,11 @@ class AristaDriver(driver_api.MechanismDriver): db_lib.num_vms_provisioned(tenant_id)) if not objects_for_tenant: db_lib.forget_tenant(tenant_id) + try: + self.rpc.delete_tenant(tenant_id) + except arista_exc.AristaRpcError: + LOG.info(EOS_UNREACHABLE_MSG) + raise ml2_exc.MechanismDriverError() def _host_name(self, hostname): fqdns_used = cfg.CONF.ml2_arista['use_fqdn'] diff --git a/neutron/tests/unit/ml2/drivers/arista/test_arista_mechanism_driver.py b/neutron/tests/unit/ml2/drivers/arista/test_arista_mechanism_driver.py index 7fcee453c..6c6ecd640 100644 --- a/neutron/tests/unit/ml2/drivers/arista/test_arista_mechanism_driver.py +++ b/neutron/tests/unit/ml2/drivers/arista/test_arista_mechanism_driver.py @@ -107,9 +107,6 @@ class AristaDriverTestCase(testlib_api.SqlTestCase): expected_calls = [ mock.call.is_network_provisioned(tenant_id, network_id), mock.call.forget_network(tenant_id, network_id), - mock.call.num_nets_provisioned(tenant_id), - mock.call.num_vms_provisioned(tenant_id), - mock.call.forget_tenant(tenant_id), ] mechanism_arista.db_lib.assert_has_calls(expected_calls) @@ -224,9 +221,6 @@ class AristaDriverTestCase(testlib_api.SqlTestCase): network_id, tenant_id), mock.call.forget_vm(vm_id, host_id, port_id, network_id, tenant_id), - mock.call.num_nets_provisioned(tenant_id), - mock.call.num_vms_provisioned(tenant_id), - mock.call.forget_tenant(tenant_id), ] mechanism_arista.db_lib.assert_has_calls(expected_calls)