CORD-1802 make sure to update ONOSApp when updating attributes
Change-Id: I49deea46b89e977652c2ee95e713d2c73823dfbb
(cherry picked from commit ff59a2abf95bf53e4a7d0ab8c53cb277d1260b88)
diff --git a/xos/synchronizer/steps/sync_onos_netcfg.py b/xos/synchronizer/steps/sync_onos_netcfg.py
index 67dc878..f9085ac 100644
--- a/xos/synchronizer/steps/sync_onos_netcfg.py
+++ b/xos/synchronizer/steps/sync_onos_netcfg.py
@@ -59,17 +59,22 @@
return service_instances
def save_service_instance_attribute(self, service_instance, name, value):
+ # returns True if something changed
+ something_changed=False
tas = ServiceInstanceAttribute.objects.filter(service_instance_id=service_instance.id, name=name)
if tas:
ta = tas[0]
if ta.value != value:
logger.info("updating %s with attribute" % name)
ta.value = value
- ta.save()
+ ta.save(update_fields=["value", "updated"], always_update_timestamp=True)
+ something_changed = True
else:
logger.info("saving autogenerated config %s" % name)
ta = model_accessor.create_obj(ServiceInstanceAttribute, service_instance=service_instance, name=name, value=value)
ta.save()
+ something_changed = True
+ return something_changed
# This function currently assumes a single Deployment and Site
def get_onos_netcfg(self, vtn):
@@ -199,4 +204,8 @@
service_instances = self.get_service_instances_who_want_config()
for service_instance in service_instances:
- self.save_service_instance_attribute(service_instance, "rest_onos/v1/network/configuration/", netcfg)
+ something_changed = self.save_service_instance_attribute(service_instance, "rest_onos/v1/network/configuration/", netcfg)
+ if (something_changed):
+ # make sure we cause the ServiceInstance to be updated as well as the attribute
+ # TODO: revisit this after synchronizer multi-object-watching is complete
+ service_instance.save(update_fields=["updated"], always_update_timestamp=True)