SEBA-497 delayering, Makefile, and tox for onos-synchronizer
Change-Id: I849b307330a6fd5a5de5489d8f2db804a02acead
diff --git a/xos/synchronizer/event_steps/__init__.py b/xos/synchronizer/event_steps/__init__.py
new file mode 100644
index 0000000..19d1424
--- /dev/null
+++ b/xos/synchronizer/event_steps/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2019-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.
diff --git a/xos/synchronizer/event_steps/kubernetes_event.py b/xos/synchronizer/event_steps/kubernetes_event.py
index 67c2569..d319eb0 100644
--- a/xos/synchronizer/event_steps/kubernetes_event.py
+++ b/xos/synchronizer/event_steps/kubernetes_event.py
@@ -15,8 +15,6 @@
import json
-import os
-import sys
from xossynchronizer.event_steps.eventstep import EventStep
from xossynchronizer.modelaccessor import ONOSApp, ONOSService
from xosconfig import Config
@@ -24,6 +22,7 @@
log = create_logger(Config().get('logging'))
+
class KubernetesPodDetailsEventStep(EventStep):
topics = ["xos.kubernetes.pod-details"]
technology = "kafka"
@@ -52,18 +51,23 @@
continue
log.info("Dirtying ONOS Service", service=service)
- service.backend_code=0
- service.backend_status="resynchronize due to kubernetes event"
+ service.backend_code = 0
+ service.backend_status = "resynchronize due to kubernetes event"
service.save(update_fields=["updated", "backend_code", "backend_status"], always_update_timestamp=True)
for app in service.service_instances.all():
log.info("Dirtying ONOS App", app=app)
- app.backend_code=0
- app.backend_status="resynchronize due to kubernetes event"
+ app.backend_code = 0
+ app.backend_status = "resynchronize due to kubernetes event"
app.save(update_fields=["updated", "backend_code", "backend_status"], always_update_timestamp=True)
for attr in app.service_instance_attributes.all():
log.info("Dirtying ServiceInstanceAttributes for App", app=app, attr=attr)
attr.backend_code = 0
attr.backend_status = "resynchronize due to kubernetes event"
- attr.save(update_fields=["updated", "backend_code", "backend_status"], always_update_timestamp=True)
+ attr.save(
+ update_fields=[
+ "updated",
+ "backend_code",
+ "backend_status"],
+ always_update_timestamp=True)
diff --git a/xos/synchronizer/event_steps/test_kubernetes_event.py b/xos/synchronizer/event_steps/test_kubernetes_event.py
index 3d81f78..70d20df 100644
--- a/xos/synchronizer/event_steps/test_kubernetes_event.py
+++ b/xos/synchronizer/event_steps/test_kubernetes_event.py
@@ -14,13 +14,12 @@
import unittest
import json
-import functools
-from mock import patch, call, Mock, PropertyMock
-import requests_mock
+from mock import patch, call, Mock
-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 TestKubernetesEvent(unittest.TestCase):
@@ -38,15 +37,13 @@
# END Setting up the config module
from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
- mock_modelaccessor_config(test_path, [("onos-service", "onos.xproto"),])
+ mock_modelaccessor_config(test_path, [("onos-service", "onos.xproto"), ])
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 kubernetes_event import KubernetesPodDetailsEventStep
-
from xossynchronizer.modelaccessor import model_accessor
self.model_accessor = model_accessor
@@ -62,10 +59,10 @@
self.event_step = KubernetesPodDetailsEventStep
self.onos = ONOSService(name="myonos",
- rest_hostname = "onos-url",
- rest_port = "8181",
- rest_username = "karaf",
- rest_password = "karaf",
+ rest_hostname="onos-url",
+ rest_port="8181",
+ rest_username="karaf",
+ rest_password="karaf",
backend_code=1,
backend_status="succeeded")
@@ -78,16 +75,16 @@
self.mockAllAttr.all.return_value = [self.attr]
self.app1 = ONOSApp(name="myapp1",
- owner=self.onos,
- backend_code=1,
- backend_status="succeeded",
- service_instance_attributes=self.mockAllAttr)
+ owner=self.onos,
+ backend_code=1,
+ backend_status="succeeded",
+ service_instance_attributes=self.mockAllAttr)
self.app2 = ONOSApp(name="myapp2",
- owner=self.onos,
- backend_code=1,
- backend_status="succeeded",
- service_instance_attributes=self.mockAllAttr)
+ owner=self.onos,
+ backend_code=1,
+ backend_status="succeeded",
+ service_instance_attributes=self.mockAllAttr)
self.onos.service_instances = MockObjectList([self.app1, self.app2])
@@ -99,9 +96,9 @@
def test_process_event(self):
with patch.object(ONOSService.objects, "get_items") as service_objects, \
- patch.object(ONOSService, "save", autospec=True) as service_save, \
- patch.object(ONOSApp, "save", autospec=True) as app_save, \
- patch.object(ServiceInstanceAttribute, "save", autospec=True) as attr_save:
+ patch.object(ONOSService, "save", autospec=True) as service_save, \
+ patch.object(ONOSApp, "save", autospec=True) as app_save, \
+ patch.object(ServiceInstanceAttribute, "save", autospec=True) as attr_save:
service_objects.return_value = [self.onos]
event_dict = {"status": "created",
@@ -114,8 +111,13 @@
self.assertEqual(self.onos.backend_code, 0)
self.assertEqual(self.onos.backend_status, "resynchronize due to kubernetes event")
- service_save.assert_called_with(self=self.onos, update_fields=["updated", "backend_code", "backend_status"],
- always_update_timestamp=True)
+ service_save.assert_called_with(
+ self=self.onos,
+ update_fields=[
+ "updated",
+ "backend_code",
+ "backend_status"],
+ always_update_timestamp=True)
self.assertEqual(self.app1.backend_code, 0)
self.assertEqual(self.app1.backend_status, "resynchronize due to kubernetes event")
@@ -206,9 +208,5 @@
self.assertEqual(self.app2.backend_status, "succeeded")
-
if __name__ == '__main__':
unittest.main()
-
-
-