SEBA-612 Port SEBA-571 changes to tt-workflow-driver
Change-Id: I8d6933805fa0106979e9f2e4bd6ac68be0f51e6c
diff --git a/xos/synchronizer/event_steps/onu_event.py b/xos/synchronizer/event_steps/onu_event.py
index 8d64254..f7f795f 100644
--- a/xos/synchronizer/event_steps/onu_event.py
+++ b/xos/synchronizer/event_steps/onu_event.py
@@ -32,16 +32,19 @@
value = json.loads(event.value)
self.log.info("onu.events: received event", value=value)
+ tt_si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
if value["status"] == "activated":
self.log.info("onu.events: activated onu", value=value)
tt_si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
tt_si.no_sync = False
tt_si.uni_port_id = long(value["portNumber"])
tt_si.of_dpid = value["deviceId"]
- tt_si.onu_state = "ENABLED"
+ tt_si.oper_onu_status = "ENABLED"
tt_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)
+ tt_si.oper_onu_status = "DISABLED"
+ tt_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_onu_events.py b/xos/synchronizer/event_steps/test_onu_events.py
index c11812f..cb2312a 100644
--- a/xos/synchronizer/event_steps/test_onu_events.py
+++ b/xos/synchronizer/event_steps/test_onu_events.py
@@ -13,12 +13,14 @@
# limitations under the License.
import unittest
-from mock import patch, call, Mock, PropertyMock
+from mock import patch, Mock
import json
-import os, sys
+import os
+import sys
-test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+
class TestSyncOLTDevice(unittest.TestCase):
@@ -69,7 +71,6 @@
def tearDown(self):
sys.path = self.sys_path_save
-
def test_create_instance(self):
with patch.object(TtWorkflowDriverServiceInstance.objects, "get_items") as tt_si_mock , \
@@ -88,7 +89,9 @@
self.assertEqual(tt_si.serial_number, self.event_dict['serialNumber'])
self.assertEqual(tt_si.of_dpid, self.event_dict['deviceId'])
self.assertEqual(tt_si.uni_port_id, long(self.event_dict['portNumber']))
- self.assertEqual(tt_si.onu_state, "ENABLED")
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(tt_si.admin_onu_state, "AWAITING")
+ self.assertEqual(tt_si.oper_onu_status, "ENABLED")
def test_reuse_instance(self):
@@ -112,23 +115,75 @@
self.assertEqual(tt_si.serial_number, self.event_dict['serialNumber'])
self.assertEqual(tt_si.of_dpid, self.event_dict['deviceId'])
self.assertEqual(tt_si.uni_port_id, long(self.event_dict['portNumber']))
- self.assertEqual(tt_si.onu_state, "ENABLED")
+ # Receiving an ONU event doesn't change the admin_onu_state until the model policy runs
+ self.assertEqual(tt_si.admin_onu_state, "AWAITING")
+ self.assertEqual(tt_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 = TtWorkflowDriverServiceInstance(
+ 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(TtWorkflowDriverServiceInstance, "save", autospec=True) as mock_save:
+ with patch.object(TtWorkflowDriverServiceInstance.objects, "get_items") as tt_si_mock, \
+ patch.object(TtWorkflowDriverServiceInstance, "save_changed_fields", autospec=True) as mock_save:
+ tt_si_mock.return_value = [si]
self.event_step.process_event(self.event)
- self.assertEqual(mock_save.call_count, 0)
-
+ tt_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(tt_si.admin_onu_state, 'ENABLED')
+ self.assertEqual(tt_si.oper_onu_status, 'DISABLED')
+
+ def test_enable_onu(self):
+ self.event_dict = {
+ 'status': 'activated',
+ 'serialNumber': 'BRCM1234',
+ 'deviceId': 'of:109299321',
+ 'portNumber': '16',
+ }
+
+ si = TtWorkflowDriverServiceInstance(
+ 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(TtWorkflowDriverServiceInstance.objects, "get_items") as tt_si_mock, \
+ patch.object(TtWorkflowDriverServiceInstance, "save_changed_fields", autospec=True) as mock_save:
+ tt_si_mock.return_value = [si]
+
+ self.event_step.process_event(self.event)
+
+ tt_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(tt_si.admin_onu_state, 'DISABLED')
+ self.assertEqual(tt_si.oper_onu_status, 'ENABLED')
+
+
if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) # for import of helpers.py