]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
In Arista ML2 delete tenant without any resources
authorSukhdev <sukhdev@aristanetworks.com>
Mon, 9 Mar 2015 21:45:21 +0000 (14:45 -0700)
committerSukhdev Kapur <sukhdev@aristanetworks.com>
Mon, 9 Mar 2015 21:56:10 +0000 (21:56 +0000)
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

neutron/plugins/ml2/drivers/arista/mechanism_arista.py
neutron/tests/unit/ml2/drivers/arista/test_arista_mechanism_driver.py

index 446c174fd4d906a8edb9efcebc8f6a26df5f942e..d99cdf4ce747475b5053d947b00ce5acf884037e 100644 (file)
@@ -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']
index 7fcee453cd56532747cd9eee4d1168cefbe3a84d..6c6ecd64028df4fa5a3fcdec39738f6742162243 100644 (file)
@@ -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)