Fix destroy DBReferenceError in driver_device.py

The error info as follows:

Cannot delete or update a parent row: a foreign key constraint fails
(`cyborg`.`attach_handles`, CONSTRAINT `attach_handles_ibfk_2` FOREIGN
KEY (`cpid_id`) REFERENCES `controlpath_ids` (`id`)

Change-Id: I1fcfb367dba520be98e792559a463b7f9804198d
This commit is contained in:
chenchunxiu
2019-03-29 03:08:07 +00:00
parent 0160a6b3bb
commit 470b2320aa
@@ -79,14 +79,14 @@ class DriverDevice(base.DriverObjectBase,
delete the internal layer objects."""
# get dev_obj_list from hostname
device_obj = self.get_device_obj(context, host)
# delete deployable_list first.
for driver_deployable in self.deployable_list:
driver_deployable.destroy(context, device_obj.id)
if hasattr(self.controlpath_id, 'cpid_info'):
cpid_obj = ControlpathID.get_by_device_id_cpidinfo(
context, device_obj.id, self.controlpath_id.cpid_info)
# delete controlpath_id
cpid_obj.destroy(context)
# delete deployable_list first.
for driver_deployable in self.deployable_list:
driver_deployable.destroy(context, device_obj.id)
# delete the device
device_obj.destroy(context)