[SEBA-239] Dirtying SI Attributes on K8s event
Change-Id: Ia1580b914fc148e044a263da28026bf1f97c2d08
diff --git a/xos/synchronizer/event_steps/kubernetes_event.py b/xos/synchronizer/event_steps/kubernetes_event.py
index 41acbe7..2f81c04 100644
--- a/xos/synchronizer/event_steps/kubernetes_event.py
+++ b/xos/synchronizer/event_steps/kubernetes_event.py
@@ -61,3 +61,9 @@
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)
diff --git a/xos/synchronizer/event_steps/test_kubernetes_event.py b/xos/synchronizer/event_steps/test_kubernetes_event.py
index 4fb4ffe..ac0d67e 100644
--- a/xos/synchronizer/event_steps/test_kubernetes_event.py
+++ b/xos/synchronizer/event_steps/test_kubernetes_event.py
@@ -82,15 +82,25 @@
backend_code=1,
backend_status="succeeded")
+ self.attr = ServiceInstanceAttribute(
+ name="foo",
+ value="bar"
+ )
+
+ self.mockAllAttr = Mock()
+ self.mockAllAttr.all.return_value = [self.attr]
+
self.app1 = ONOSApp(name="myapp1",
owner=self.onos,
backend_code=1,
- backend_status="succeeded")
+ backend_status="succeeded",
+ service_instance_attributes=self.mockAllAttr)
self.app2 = ONOSApp(name="myapp2",
owner=self.onos,
backend_code=1,
- backend_status="succeeded")
+ backend_status="succeeded",
+ service_instance_attributes=self.mockAllAttr)
self.onos.service_instances = MockObjectList([self.app1, self.app2])
@@ -103,7 +113,8 @@
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(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",
@@ -129,6 +140,10 @@
call(self.app2, update_fields=["updated", "backend_code", "backend_status"],
always_update_timestamp=True)])
+ self.assertEqual(self.attr.backend_code, 0)
+ self.assertEqual(self.attr.backend_status, "resynchronize due to kubernetes event")
+ self.assertEqual(attr_save.call_count, 2)
+
def test_process_event_unknownstatus(self):
with patch.object(ONOSService.objects, "get_items") as service_objects, \
patch.object(ONOSService, "save") as service_save, \