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
diff --git a/xos/synchronizer/helpers.py b/xos/synchronizer/helpers.py
index a300892..efdce1a 100644
--- a/xos/synchronizer/helpers.py
+++ b/xos/synchronizer/helpers.py
@@ -40,7 +40,8 @@
 
         whitelisted = matching_entries[0]
         try:
-            pon_port = model_accessor.ONUDevice.objects.get(serial_number=tt_si.serial_number).pon_port
+            onu = model_accessor.ONUDevice.objects.get(serial_number=tt_si.serial_number)
+            pon_port = onu.pon_port
         except IndexError:
             raise DeferredException("ONU device %s is not know to XOS yet" % tt_si.serial_number)
 
diff --git a/xos/synchronizer/migrations/0003_auto_20190510_2043.py b/xos/synchronizer/migrations/0003_auto_20190510_2043.py
new file mode 100644
index 0000000..7e7b8ac
--- /dev/null
+++ b/xos/synchronizer/migrations/0003_auto_20190510_2043.py
@@ -0,0 +1,39 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-05-11 00:43
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('tt-workflow-driver', '0002_auto_20190410_1350'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='ttworkflowdriverserviceinstance',
+            old_name='onu_state',
+            new_name='admin_onu_state',
+        ),
+        migrations.AddField(
+            model_name='ttworkflowdriverserviceinstance',
+            name='oper_onu_status',
+            field=models.CharField(choices=[(b'AWAITING', b'Awaiting'), (b'ENABLED', b'Enabled'), (b'DISABLED', b'Disabled')], default=b'AWAITING', help_text=b'ONU operational state', max_length=256),
+        ),
+    ]
diff --git a/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_serviceinstance.py
index 95081c8..f9628e3 100644
--- a/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_serviceinstance.py
+++ b/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_serviceinstance.py
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 
-
+from helpers import TtHelpers
 from xossynchronizer.model_policies.policy import Policy
 
 import os
@@ -23,7 +23,6 @@
 sync_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
 sys.path.append(sync_path)
 
-from helpers import TtHelpers
 
 class DeferredException(Exception):
     pass
@@ -36,7 +35,7 @@
         self.handle_update(si)
 
     def handle_update(self, si):
-        self.logger.debug("MODEL_POLICY: handle_update for TtWorkflowDriverServiceInstance %s " % (si.id), onu_state=si.onu_state)
+        self.logger.debug("MODEL_POLICY: handle_update for TtWorkflowDriverServiceInstance %s " % (si.id), onu_state=si.admin_onu_state)
 
         self.process_onu_state(si)
         self.process_dhcp_state(si)
@@ -51,28 +50,22 @@
 
         si.save_changed_fields()
 
+    # Check the whitelist to see if the ONU is valid.  If it is, make sure that it's enabled.
     def process_onu_state(self, si):
         [valid, message] = TtHelpers.validate_onu(self.model_accessor, self.logger, si)
-        if si.onu_state == "AWAITING" or si.onu_state == "ENABLED":
-            si.status_message = message
-            if valid:
-                si.onu_state = "ENABLED"
-                self.update_onu(si.serial_number, "ENABLED")
-            else:
-                si.onu_state = "DISABLED"
-                self.update_onu(si.serial_number, "DISABLED")
-        else: # DISABLED
-            if not valid:
-                si.status_message = message
-            else:
-                si.status_message = "ONU has been disabled"
+        si.status_message = message
+        if valid:
+            si.admin_onu_state = "ENABLED"
+            self.update_onu(si.serial_number, "ENABLED")
+        else:
+            si.admin_onu_state = "DISABLED"
             self.update_onu(si.serial_number, "DISABLED")
 
 
     # The DhcpL2Relay ONOS app generates events that update the fields below.
     # It only sends events when it processes DHCP packets.  It keeps no internal state.
     def process_dhcp_state(self, si):
-        if si.onu_state in ["AWAITING", "DISABLED"]:
+        if si.admin_onu_state in ["AWAITING", "DISABLED"]:
             si.ip_address = ""
             si.mac_address = ""
             si.dhcp_state = "AWAITING"
@@ -87,17 +80,20 @@
     # ENABLED   | *
     # DISABLED  | AWAITING
     def validate_states(self, si):
-        if (si.onu_state == "AWAITING" or si.onu_state == "DISABLED") and si.dhcp_state == "AWAITING":
+        if (si.admin_onu_state == "AWAITING" or si.admin_onu_state == "DISABLED") and si.dhcp_state == "AWAITING":
             return
-        if si.onu_state == "ENABLED":
+        if si.admin_onu_state == "ENABLED":
             return
-        self.logger.warning("MODEL_POLICY (validate_states): invalid state combination", onu_state=si.onu_state, dhcp_state=si.dhcp_state)
+        self.logger.warning("MODEL_POLICY (validate_states): invalid state combination", onu_state=si.admin_onu_state, dhcp_state=si.dhcp_state)
 
 
     def update_onu(self, serial_number, admin_state):
-        onu = [onu for onu in self.model_accessor.ONUDevice.objects.all() if onu.serial_number.lower() == serial_number.lower()][0]
+        onu = [onu for onu in self.model_accessor.ONUDevice.objects.all() if onu.serial_number.lower()
+               == serial_number.lower()][0]
         if onu.admin_state == admin_state:
-            self.logger.debug("MODEL_POLICY: ONUDevice [%s] already has admin_state to %s" % (serial_number, admin_state))
+            self.logger.debug(
+                "MODEL_POLICY: ONUDevice [%s] already has admin_state to %s" %
+                (serial_number, admin_state))
         else:
             self.logger.debug("MODEL_POLICY: setting ONUDevice [%s] admin_state to %s" % (serial_number, admin_state))
             onu.admin_state = admin_state
@@ -105,10 +101,13 @@
 
     def get_subscriber(self, serial_number):
         try:
-            return [s for s in self.model_accessor.RCORDSubscriber.objects.all() if s.onu_device.lower() == serial_number.lower()][0]
+            return [s for s in self.model_accessor.RCORDSubscriber.objects.all() if s.onu_device.lower()
+                    == serial_number.lower()][0]
         except IndexError:
             # If the subscriber doesn't exist we don't do anything
-            self.logger.debug("MODEL_POLICY: subscriber does not exists for this SI, doing nothing", onu_device=serial_number)
+            self.logger.debug(
+                "MODEL_POLICY: subscriber does not exists for this SI, doing nothing",
+                onu_device=serial_number)
             return None
 
     def update_subscriber_ip(self, subscriber, ip):
@@ -119,10 +118,15 @@
                 subscriber_id=subscriber.id,
                 ip=ip
             )[0]
-            self.logger.debug("MODEL_POLICY: found existing RCORDIpAddress for subscriber", onu_device=subscriber.onu_device, subscriber_status=subscriber.status, ip=ip)
+            self.logger.debug("MODEL_POLICY: found existing RCORDIpAddress for subscriber",
+                              onu_device=subscriber.onu_device, subscriber_status=subscriber.status, ip=ip)
             ip.save_changed_fields()
         except IndexError:
-            self.logger.debug("MODEL_POLICY: Creating new RCORDIpAddress for subscriber", onu_device=subscriber.onu_device, subscriber_status=subscriber.status, ip=ip)
+            self.logger.debug(
+                "MODEL_POLICY: Creating new RCORDIpAddress for subscriber",
+                onu_device=subscriber.onu_device,
+                subscriber_status=subscriber.status,
+                ip=ip)
             ip = self.model_accessor.RCORDIpAddress(
                 subscriber_id=subscriber.id,
                 ip=ip,
@@ -136,25 +140,32 @@
                 subscriber_id=subscriber.id,
                 ip=ip
             )[0]
-            self.logger.debug("MODEL_POLICY: delete RCORDIpAddress for subscriber", onu_device=subscriber.onu_device, subscriber_status=subscriber.status, ip=ip)
+            self.logger.debug(
+                "MODEL_POLICY: delete RCORDIpAddress for subscriber",
+                onu_device=subscriber.onu_device,
+                subscriber_status=subscriber.status,
+                ip=ip)
             ip.delete()
-        except:
+        except BaseException:
             self.logger.warning("MODEL_POLICY: no RCORDIpAddress object found, cannot delete", ip=ip)
 
     def update_subscriber(self, subscriber, si):
         cur_status = subscriber.status
         # Don't change state if someone has disabled the subscriber
         if subscriber.status != "disabled":
-            if si.onu_state == "ENABLED":
+            if si.admin_onu_state == "ENABLED":
                 subscriber.status = "enabled"
-            elif si.onu_state == "DISABLED":
+            elif si.admin_onu_state == "DISABLED":
                 subscriber.status = "awaiting-auth"
 
         # NOTE we save the subscriber only if:
         # - the status has changed
         # - we get a DHCPACK event
         if cur_status != subscriber.status or si.dhcp_state == "DHCPACK":
-            self.logger.debug("MODEL_POLICY: updating subscriber", onu_device=subscriber.onu_device, subscriber_status=subscriber.status)
+            self.logger.debug(
+                "MODEL_POLICY: updating subscriber",
+                onu_device=subscriber.onu_device,
+                subscriber_status=subscriber.status)
             if subscriber.status == "awaiting-auth":
                 self.delete_subscriber_ip(subscriber, si.ip_address)
                 subscriber.mac_address = ""
diff --git a/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_whitelistentry.py
index b16642a..3d5f34c 100644
--- a/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_whitelistentry.py
+++ b/xos/synchronizer/model_policies/model_policy_tt_workflow_driver_whitelistentry.py
@@ -34,12 +34,14 @@
     def validate_onu_state(self, si):
         [valid, message] = TtHelpers.validate_onu(self.model_accessor, self.logger, si)
         if valid:
-            si.onu_state = "ENABLED"
+            si.admin_onu_state = "ENABLED"
         else:
-            si.onu_state = "DISABLED"
+            si.admin_onu_state = "DISABLED"
 
         self.logger.debug(
-            "MODEL_POLICY: activating TtWorkflowDriverServiceInstance because of change in the whitelist", si=si, onu_state=si.onu_state)
+            "MODEL_POLICY: activating TtWorkflowDriverServiceInstance because of change in the whitelist",
+            si=si,
+            onu_state=si.admin_onu_state)
         si.save_changed_fields(always_update_timestamp=True)
 
     def handle_update(self, whitelist):
diff --git a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
index a067779..2496f9d 100644
--- a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
+++ b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
@@ -15,11 +15,12 @@
 
 
 import unittest
-from mock import patch, call, Mock, PropertyMock
+from mock import patch
 
-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 TestModelPolicyTtWorkflowDriverServiceInstance(unittest.TestCase):
@@ -46,14 +47,12 @@
         from model_policy_tt_workflow_driver_serviceinstance import TtWorkflowDriverServiceInstancePolicy, TtHelpers
         self.TtHelpers = TtHelpers
 
-        from mock_modelaccessor import MockObjectList
-
         # import all class names to globals
         for (k, v) in model_accessor.all_model_classes.items():
             globals()[k] = v
 
-        # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of
-        # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
+        # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to
+        # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
         model_accessor.reset_all_object_stores()
 
 
@@ -72,7 +71,7 @@
             admin_state="ENABLED"
         )
         with patch.object(ONUDevice.objects, "get_items") as get_onu, \
-            patch.object(onu, "save") as onu_save:
+                patch.object(onu, "save") as onu_save:
             get_onu.return_value = [onu]
 
             self.policy.update_onu("brcm1234", "ENABLED")
@@ -80,13 +79,13 @@
 
             self.policy.update_onu("brcm1234", "DISABLED")
             self.assertEqual(onu.admin_state, "DISABLED")
-            onu_save.assert_called_with(always_update_timestamp=True, update_fields=['admin_state', 'serial_number', 'updated'])
-
+            onu_save.assert_called_with(
+                always_update_timestamp=True, update_fields=[
+                    'admin_state', 'serial_number', 'updated'])
 
     def test_enable_onu(self):
         with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
-            patch.object(self.policy, "update_onu") as update_onu, \
-            patch.object(self.si, "save") as save_si:
+                patch.object(self.policy, "update_onu") as update_onu:
             validate_onu.return_value = [True, "valid onu"]
 
             self.policy.process_onu_state(self.si)
@@ -98,8 +97,7 @@
 
     def test_disable_onu(self):
         with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
-                patch.object(self.policy, "update_onu") as update_onu, \
-                patch.object(self.si, "save") as save_si:
+                patch.object(self.policy, "update_onu") as update_onu:
             validate_onu.return_value = [False, "invalid onu"]
 
             self.policy.process_onu_state(self.si)
@@ -115,24 +113,26 @@
         when necessary
         """
         with patch.object(self.policy, "process_onu_state") as process_onu_state, \
-            patch.object(self.policy, "update_onu") as update_onu, \
-            patch.object(self.policy, "get_subscriber") as get_subscriber:
+                patch.object(self.policy, "update_onu") as update_onu, \
+                patch.object(self.policy, "get_subscriber") as get_subscriber:
             update_onu.return_value = None
             get_subscriber.return_value = None
 
-            self.si.onu_state = "AWAITING"
+            self.si.admin_onu_state = "AWAITING"
+            self.si.oper_onu_status = "AWAITING"
             self.policy.handle_update(self.si)
             process_onu_state.assert_called_with(self.si)
 
-            self.si.onu_state = "ENABLED"
+            self.si.admin_onu_state = "ENABLED"
+            self.si.oper_onu_status = "ENABLED"
             self.policy.handle_update(self.si)
             process_onu_state.assert_called_with(self.si)
 
-            self.si.onu_state = "DISABLED"
+            self.si.admin_onu_state = "DISABLED"
+            self.si.oper_onu_status = "DISABLED"
             self.policy.handle_update(self.si)
             process_onu_state.assert_called_with(self.si)
 
-
     def test_get_subscriber(self):
 
         sub = RCORDSubscriber(
@@ -160,7 +160,7 @@
         self.si.status_message = "some content"
 
         with patch.object(sub, "save") as sub_save:
-            self.si.onu_state = "ENABLED"
+            self.si.admin_onu_state = "ENABLED"
             sub.status = "awaiting-auth"
             self.policy.update_subscriber(sub, self.si)
             self.assertEqual(sub.status, "enabled")
@@ -168,7 +168,7 @@
             sub_save.reset_mock()
             sub.status = None
 
-            self.si.onu_state = "DISABLED"
+            self.si.admin_onu_state = "DISABLED"
             sub.status = "enabled"
             self.policy.update_subscriber(sub, self.si)
             self.assertEqual(sub.status, "awaiting-auth")
@@ -183,12 +183,12 @@
 
         with patch.object(sub, "save") as sub_save:
             sub.status = "enabled"
-            self.si.onu_state = "ENABLED"
+            self.si.admin_onu_state = "ENABLED"
             self.policy.update_subscriber(sub, self.si)
             sub_save.assert_not_called()
 
             sub.status = "awaiting-auth"
-            self.si.onu_state = "DISABLED"
+            self.si.admin_onu_state = "DISABLED"
             self.policy.update_subscriber(sub, self.si)
             sub_save.assert_not_called()
 
@@ -208,8 +208,8 @@
         self.si.mac_address = "4321"
 
         with patch.object(sub, "save") as sub_save, \
-            patch.object(RCORDIpAddress.objects, "get_items") as get_ips, \
-            patch.object(ip, "save_changed_fields") as ip_mock:
+                patch.object(RCORDIpAddress.objects, "get_items") as get_ips, \
+                patch.object(ip, "save_changed_fields") as ip_mock:
 
             get_ips.return_value = [ip]
             ip_mock.return_value = []
@@ -231,7 +231,7 @@
         self.si.mac_address = "4321"
 
         with patch.object(sub, "save") as sub_save, \
-            patch.object(RCORDIpAddress, "save", autospec=True) as ip_mock:
+                patch.object(RCORDIpAddress, "save", autospec=True) as ip_mock:
 
             ip_mock.return_value = []
 
@@ -245,19 +245,19 @@
             self.assertEqual(saved_ip.description, "DHCP Assigned IP Address")
 
     def test_handle_update_subscriber(self):
-        self.si.onu_state = "DISABLED"
+        self.si.admin_onu_state = "DISABLED"
 
         sub = RCORDSubscriber(
             onu_device="BRCM1234"
         )
 
         with patch.object(self.policy, "get_subscriber") as get_subscriber, \
-            patch.object(self.policy, "update_onu") as update_onu, \
-            patch.object(self.policy, "update_subscriber") as update_subscriber:
+                patch.object(self.policy, "update_onu") as update_onu, \
+                patch.object(self.policy, "update_subscriber") as update_subscriber:
 
             get_subscriber.return_value = None
             self.policy.handle_update(self.si)
-            update_onu.assert_called_with(sub.onu_device, "DISABLED");
+            update_onu.assert_called_with(sub.onu_device, "DISABLED")
             self.assertEqual(update_subscriber.call_count, 0)
 
             get_subscriber.return_value = sub
@@ -266,5 +266,5 @@
 
 
 if __name__ == '__main__':
+    sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
     unittest.main()
-
diff --git a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_whitelistentry.py
index bee8971..a439cab 100644
--- a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_whitelistentry.py
+++ b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_whitelistentry.py
@@ -15,11 +15,12 @@
 
 
 import unittest
-from mock import patch, call, Mock, PropertyMock
+from mock import patch
 
-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 TestModelPolicyTtWorkflowDriverWhiteListEntry(unittest.TestCase):
     def setUp(self):
@@ -37,7 +38,7 @@
 
         import xossynchronizer.modelaccessor
         import mock_modelaccessor
-        reload(mock_modelaccessor) # in case nose2 loaded it in a previous test
+        reload(mock_modelaccessor)  # in case nose2 loaded it in a previous test
         reload(xossynchronizer.modelaccessor)      # in case nose2 loaded it in a previous test
 
         from xossynchronizer.modelaccessor import model_accessor
@@ -51,8 +52,8 @@
         for (k, v) in model_accessor.all_model_classes.items():
             globals()[k] = v
 
-        # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of
-        # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
+        # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to
+        # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
         model_accessor.reset_all_object_stores()
 
         self.policy = TtWorkflowDriverWhiteListEntryPolicy(model_accessor=model_accessor)
@@ -67,39 +68,44 @@
     def test_enable_onu(self):
         si = TtWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id, valid="invalid")
         with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
-            patch.object(si, "save") as save_si:
+                patch.object(si, "save") as save_si:
             validate_onu.return_value = [True, "valid onu"]
 
             self.policy.validate_onu_state(si)
 
             save_si.assert_called_once()
-            save_si.assert_called_with(always_update_timestamp=True, update_fields=['onu_state', 'serial_number', 'updated'])
+            save_si.assert_called_with(
+                always_update_timestamp=True, update_fields=[
+                    'admin_onu_state', 'serial_number', 'updated'])
 
     def test_disable_onu(self):
         si = TtWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id, valid="invalid")
         with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
-            patch.object(si, "save") as save_si:
+                patch.object(si, "save") as save_si:
             validate_onu.return_value = [False, "invalid onu"]
 
             self.policy.validate_onu_state(si)
 
             save_si.assert_called_once()
-            save_si.assert_called_with(always_update_timestamp=True, update_fields=['onu_state', 'serial_number', 'updated'])
+            save_si.assert_called_with(
+                always_update_timestamp=True, update_fields=[
+                    'admin_onu_state', 'serial_number', 'updated'])
 
     def test_whitelist_update(self):
         si = TtWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id)
         wle = TtWorkflowDriverWhiteListEntry(serial_number="brcm333", owner_id=self.service.id, owner=self.service)
         with patch.object(TtWorkflowDriverServiceInstance.objects, "get_items") as oss_si_items, \
-            patch.object(self.policy, "validate_onu_state") as validate_onu_state, \
-            patch.object(wle, "save") as wle_save:
+                patch.object(self.policy, "validate_onu_state") as validate_onu_state, \
+                patch.object(wle, "save") as wle_save:
             oss_si_items.return_value = [si]
 
-
             self.policy.handle_update(wle)
 
             validate_onu_state.assert_called_with(si)
             self.assertTrue(wle.backend_need_delete_policy)
-            wle_save.assert_called_with(always_update_timestamp=False, update_fields=['backend_need_delete_policy', 'owner', 'serial_number'])
+            wle_save.assert_called_with(
+                always_update_timestamp=False, update_fields=[
+                    'backend_need_delete_policy', 'owner', 'serial_number'])
 
     def test_whitelist_delete(self):
         si = TtWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id)
@@ -113,7 +119,11 @@
 
             validate_onu_state.assert_called_with(si)
             self.assertTrue(wle.backend_need_reap)
-            wle_save.assert_called_with(always_update_timestamp=False, update_fields=['backend_need_reap', 'owner', 'serial_number'])
-if __name__ == '__main__':
-    unittest.main()
+            wle_save.assert_called_with(
+                always_update_timestamp=False, update_fields=[
+                    'backend_need_reap', 'owner', 'serial_number'])
 
+
+if __name__ == '__main__':
+    sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
+    unittest.main()
diff --git a/xos/synchronizer/models/tt-workflow-driver.xproto b/xos/synchronizer/models/tt-workflow-driver.xproto
index 3aca987..2052588 100644
--- a/xos/synchronizer/models/tt-workflow-driver.xproto
+++ b/xos/synchronizer/models/tt-workflow-driver.xproto
@@ -22,7 +22,7 @@
         max_length = 256];
     required int32 uni_port_id = 5 [
         help_text = "ONU UNI port ID"];
-    required string onu_state = 6 [
+    required string admin_onu_state = 6 [
         help_text = "ONU administrative state",
         choices = "(('AWAITING', 'Awaiting'), ('ENABLED', 'Enabled'), ('DISABLED', 'Disabled'))",
         default = "AWAITING",
@@ -45,6 +45,12 @@
         help_text = "Management MAC address, leanred from DHCP",
         feedback_state = True,
         max_length = 20];
+    required string oper_onu_status = 11 [
+        help_text = "ONU operational state",
+        choices = "(('AWAITING', 'Awaiting'), ('ENABLED', 'Enabled'), ('DISABLED', 'Disabled'))",
+        default = "AWAITING",
+        feedback_state = True,
+        max_length = 256];
 }
 
 message TtWorkflowDriverWhiteListEntry (XOSBase) {