[SEBA-200] Deleting an OLT that was never sync'ed
Change-Id: I6e319c3d4cc93b8718f98a0c2dc1cc7a36260b1e
diff --git a/xos/synchronizer/steps/sync_olt_device.py b/xos/synchronizer/steps/sync_olt_device.py
index b65dfef..81a9288 100644
--- a/xos/synchronizer/steps/sync_olt_device.py
+++ b/xos/synchronizer/steps/sync_olt_device.py
@@ -142,8 +142,10 @@
voltha = Helpers.get_voltha_info(model.volt_service)
- if not model.device_id:
- log.error("OLTDevice %s has no device_id" % model.name)
+ if not model.device_id or model.backend_code == 2:
+ # NOTE if the device was not synchronized, just remove it from the data model
+ log.warning("OLTDevice %s has no device_id, it was never saved in VOLTHA" % model.name)
+ return
else:
# Disable the OLT device
request = requests.post("%s:%d/api/v1/devices/%s/disable" % (voltha['url'], voltha['port'], model.device_id))
diff --git a/xos/synchronizer/steps/test_sync_olt_device.py b/xos/synchronizer/steps/test_sync_olt_device.py
index 670c49c..0df502f 100644
--- a/xos/synchronizer/steps/test_sync_olt_device.py
+++ b/xos/synchronizer/steps/test_sync_olt_device.py
@@ -292,7 +292,14 @@
self.sync_step().delete_record(self.o)
- # We don't need to assert here if there are no exceptions happening
+ self.assertEqual(m.call_count, 2)
+
+ @requests_mock.Mocker()
+ def test_delete_unsynced_record(self, m):
+
+ self.sync_step().delete_record(self.o)
+
+ self.assertEqual(m.call_count, 0)
if __name__ == "__main__":
unittest.main()