[SEBA-571] Reset subscriber status when ONU is disabled
Change-Id: Ic05484e0bbf52ab82ee712b895638cbe4e4bacf9
diff --git a/xos/synchronizer/event_steps/onu_event.py b/xos/synchronizer/event_steps/onu_event.py
index 9a6c6f8..0d51255 100644
--- a/xos/synchronizer/event_steps/onu_event.py
+++ b/xos/synchronizer/event_steps/onu_event.py
@@ -32,16 +32,18 @@
value = json.loads(event.value)
self.log.info("onu.events: received event", value=value)
+ att_si = AttHelpers.find_or_create_att_si(self.model_accessor, self.log, value)
if value["status"] == "activated":
self.log.info("onu.events: activated onu", value=value)
- att_si = AttHelpers.find_or_create_att_si(self.model_accessor, self.log, value)
att_si.no_sync = False
att_si.uni_port_id = long(value["portNumber"])
att_si.of_dpid = value["deviceId"]
- att_si.onu_state = "ENABLED"
+ att_si.oper_onu_status = "ENABLED"
att_si.save_changed_fields(always_update_timestamp=True)
elif value["status"] == "disabled":
- self.log.info("onu.events: disabled onu, not taking any action", value=value)
+ self.log.info("onu.events: disabled onu, resetting the subscriber", value=value)
+ att_si.oper_onu_status = "DISABLED"
+ att_si.save_changed_fields(always_update_timestamp=True)
return
else:
self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
diff --git a/xos/synchronizer/event_steps/test_dhcp_event.py b/xos/synchronizer/event_steps/test_dhcp_event.py
index 275c1ef..2b9b963 100644
--- a/xos/synchronizer/event_steps/test_dhcp_event.py
+++ b/xos/synchronizer/event_steps/test_dhcp_event.py
@@ -103,5 +103,5 @@
if __name__ == '__main__':
- sys.path.append("..") # for import of helpers.py
+ sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) # for import of helpers.py
unittest.main()
diff --git a/xos/synchronizer/event_steps/test_onu_events.py b/xos/synchronizer/event_steps/test_onu_events.py
index fe8f87e..a425908 100644
--- a/xos/synchronizer/event_steps/test_onu_events.py
+++ b/xos/synchronizer/event_steps/test_onu_events.py
@@ -89,7 +89,9 @@
self.assertEqual(att_si.serial_number, self.event_dict['serialNumber'])
self.assertEqual(att_si.of_dpid, self.event_dict['deviceId'])
self.assertEqual(att_si.uni_port_id, long(self.event_dict['portNumber']))
- self.assertEqual(att_si.onu_state, "ENABLED")
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(att_si.admin_onu_state, "AWAITING")
+ self.assertEqual(att_si.oper_onu_status, "ENABLED")
def test_reuse_instance(self):
@@ -113,24 +115,76 @@
self.assertEqual(att_si.serial_number, self.event_dict['serialNumber'])
self.assertEqual(att_si.of_dpid, self.event_dict['deviceId'])
self.assertEqual(att_si.uni_port_id, long(self.event_dict['portNumber']))
- self.assertEqual(att_si.onu_state, "ENABLED")
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(att_si.admin_onu_state, "AWAITING")
+ self.assertEqual(att_si.oper_onu_status, "ENABLED")
def test_disable_onu(self):
self.event_dict = {
'status': 'disabled',
'serialNumber': 'BRCM1234',
'deviceId': 'of:109299321',
- 'portNumber': '16'
+ 'portNumber': '16',
}
+
+ si = AttWorkflowDriverServiceInstance(
+ serial_number=self.event_dict["serialNumber"],
+ of_dpid="foo",
+ uni_port_id="foo",
+ admin_onu_state="ENABLED",
+ oper_onu_status="ENABLED",
+ )
+
self.event.value = json.dumps(self.event_dict)
- with patch.object(AttWorkflowDriverServiceInstance, "save", autospec=True) as mock_save:
+ with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as att_si_mock, \
+ patch.object(AttWorkflowDriverServiceInstance, "save_changed_fields", autospec=True) as mock_save:
+ att_si_mock.return_value = [si]
self.event_step.process_event(self.event)
- self.assertEqual(mock_save.call_count, 0)
+ att_si = mock_save.call_args[0][0]
+
+ self.assertEqual(mock_save.call_count, 1)
+
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(att_si.admin_onu_state, 'ENABLED')
+ self.assertEqual(att_si.oper_onu_status, 'DISABLED')
+
+ def test_enable_onu(self):
+ self.event_dict = {
+ 'status': 'activated',
+ 'serialNumber': 'BRCM1234',
+ 'deviceId': 'of:109299321',
+ 'portNumber': '16',
+ }
+
+ si = AttWorkflowDriverServiceInstance(
+ serial_number=self.event_dict["serialNumber"],
+ of_dpid="foo",
+ uni_port_id="foo",
+ admin_onu_state="DISABLED",
+ oper_onu_status="DISABLED",
+ )
+
+ self.event.value = json.dumps(self.event_dict)
+
+ with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as att_si_mock, \
+ patch.object(AttWorkflowDriverServiceInstance, "save_changed_fields", autospec=True) as mock_save:
+ att_si_mock.return_value = [si]
+
+ self.event_step.process_event(self.event)
+
+ att_si = mock_save.call_args[0][0]
+
+ self.assertEqual(mock_save.call_count, 1)
+
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(att_si.admin_onu_state, 'DISABLED')
+ self.assertEqual(att_si.oper_onu_status, 'ENABLED')
+
if __name__ == '__main__':
- sys.path.append("..") # for import of helpers.py
+ sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) # for import of helpers.py
unittest.main()