SEBA-612 Port SEBA-571 changes to tt-workflow-driver
Change-Id: I8d6933805fa0106979e9f2e4bd6ac68be0f51e6c
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