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
This commit is contained in:
Sukhdev 2015-03-09 14:45:21 -07:00 committed by Sukhdev Kapur
parent feb3273e68
commit 1ec7c54211
2 changed files with 9 additions and 10 deletions

View 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']

View 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)