From c8c689b293acb5943ffb1fe9a1488b89b693eaa7 Mon Sep 17 00:00:00 2001
From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk>
Date: Thu, 24 May 2018 11:21:20 +0100
Subject: [PATCH] Malformed flag is now also indicated in the response of an
 update of the configuration of the aggregator

---
 src/clmc-webservice/clmcservice/tests.py | 6 ++++--
 src/clmc-webservice/clmcservice/views.py | 6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/clmc-webservice/clmcservice/tests.py b/src/clmc-webservice/clmcservice/tests.py
index c106dfa..c6b95ed 100644
--- a/src/clmc-webservice/clmcservice/tests.py
+++ b/src/clmc-webservice/clmcservice/tests.py
@@ -308,7 +308,8 @@ class TestAggregatorAPI(object):
 
         # update the configuration of the aggregator while it is running
         config_body = '{"aggregator_report_period": 15, "aggregator_database_name": "E2EMetrics", "aggregator_database_url": "http://172.50.231.51:8086"}'
-        output_body = {'aggregator_report_period': 15, 'aggregator_database_name': "E2EMetrics", 'aggregator_database_url': "http://172.50.231.51:8086"}
+        output_body = {'aggregator_report_period': 15, 'aggregator_database_name': "E2EMetrics", 'aggregator_database_url': "http://172.50.231.51:8086", 'malformed': True,
+                       'comment': 'Aggregator is running in a malformed state - it uses an old version of the configuration. Please, restart it so that the updated configuration is used.'}
         request = testing.DummyRequest()
         request.body = config_body.encode(request.charset)
         response = AggregatorConfig(request).put()
@@ -338,7 +339,8 @@ class TestAggregatorAPI(object):
 
         # update the configuration again while the aggregator is running
         config_body = '{"aggregator_report_period": 30, "aggregator_database_name": "E2EMetrics", "aggregator_database_url": "http://172.50.231.51:8086"}'
-        output_body = {'aggregator_report_period': 30, 'aggregator_database_name': "E2EMetrics", 'aggregator_database_url': "http://172.50.231.51:8086"}
+        output_body = {'aggregator_report_period': 30, 'aggregator_database_name': "E2EMetrics", 'aggregator_database_url': "http://172.50.231.51:8086", 'malformed': True,
+                       'comment': 'Aggregator is running in a malformed state - it uses an old version of the configuration. Please, restart it so that the updated configuration is used.'}
         request = testing.DummyRequest()
         request.body = config_body.encode(request.charset)
         response = AggregatorConfig(request).put()
diff --git a/src/clmc-webservice/clmcservice/views.py b/src/clmc-webservice/clmcservice/views.py
index 969d174..14c7700 100644
--- a/src/clmc-webservice/clmcservice/views.py
+++ b/src/clmc-webservice/clmcservice/views.py
@@ -74,7 +74,11 @@ class AggregatorConfig(object):
 
             # if configuration is not already malformed, check whether the configuration is updated
             if not self.request.registry.settings[MALFORMED_FLAG]:
-                self.request.registry.settings[MALFORMED_FLAG] = old_config != new_config and self.request.registry.settings[RUNNING_FLAG]
+                malformed = old_config != new_config and self.request.registry.settings[RUNNING_FLAG]
+                self.request.registry.settings[MALFORMED_FLAG] = malformed
+                if malformed:
+                    new_config[MALFORMED_FLAG] = True
+                    new_config[COMMENT_ATTRIBUTE] = COMMENT_VALUE
 
             return new_config
 
-- 
GitLab