New event handling imported from att-workflow-driver
Change-Id: I692e4eb7604a42d47416474fac1c45dbf0ccfbe1
diff --git a/xos/synchronizer/event_steps/dhcp_event.py b/xos/synchronizer/event_steps/dhcp_event.py
index 8b3ea8d..92828f6 100644
--- a/xos/synchronizer/event_steps/dhcp_event.py
+++ b/xos/synchronizer/event_steps/dhcp_event.py
@@ -14,12 +14,9 @@
# limitations under the License.
import json
-import time
-import os
-import sys
from xossynchronizer.event_steps.eventstep import EventStep
+from helpers import TtHelpers
-from ..helpers import TtHelpers
class SubscriberDhcpEventStep(EventStep):
topics = ["dhcp.events"]
@@ -30,18 +27,11 @@
def process_event(self, event):
value = json.loads(event.value)
+ self.log.info("dhcp.events: Got event for subscriber", event_value=value)
- onu_sn = TtHelpers.get_onu_sn(self.model_accessor, self.log, value)
- si = TtHelpers.get_si_by_sn(self.model_accessor, self.log, onu_sn)
-
- if not si:
- self.log.exception("dhcp.events: Cannot find tt-workflow-driver service instance for this event", kafka_event=value)
- raise Exception("dhcp.events: Cannot find tt-workflow-driver service instance for this event")
-
- self.log.info("dhcp.events: Got event for subscriber", event_value=value, onu_sn=onu_sn, si=si)
-
+ si = TtHelpers.find_or_create_tt_si(self.model_accessor, self.log, value)
+ self.log.debug("dhcp.events: Updating service instance", si=si)
si.dhcp_state = value["messageType"]
si.ip_address = value["ipAddress"]
si.mac_address = value["macAddress"]
-
si.save_changed_fields(always_update_timestamp=True)