From 54634e6c12b80111e20a10c4f258dd0bfd4a944b Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Tue, 17 Apr 2018 11:21:51 -0300 Subject: [PATCH] Adds yaml support in policy module Adds timeout for creation of alarm in mon client in policy module Signed-off-by: Benjamin Diaz --- policy_module/osm_policy_agent.cfg | 3 --- policy_module/osm_policy_module/common/mon_client.py | 3 ++- policy_module/osm_policy_module/core/agent.py | 6 +++++- .../{test_policy_config_agent.py => test_policy_agent.py} | 0 policy_module/requirements.txt | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) delete mode 100644 policy_module/osm_policy_agent.cfg rename policy_module/osm_policy_module/tests/unit/{test_policy_config_agent.py => test_policy_agent.py} (100%) diff --git a/policy_module/osm_policy_agent.cfg b/policy_module/osm_policy_agent.cfg deleted file mode 100644 index 54ca70a..0000000 --- a/policy_module/osm_policy_agent.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[osm] -kafka_server_host=server -kafka_server_port=port diff --git a/policy_module/osm_policy_module/common/mon_client.py b/policy_module/osm_policy_module/common/mon_client.py index 0d86046..3e81757 100644 --- a/policy_module/osm_policy_module/common/mon_client.py +++ b/policy_module/osm_policy_module/common/mon_client.py @@ -50,7 +50,8 @@ class MonClient: future.get(timeout=60) consumer = KafkaConsumer(bootstrap_servers=self.kafka_server, key_deserializer=bytes.decode, - value_deserializer=bytes.decode) + value_deserializer=bytes.decode, + consumer_timeout_ms=10000) consumer.subscribe(['alarm_response']) for message in consumer: if message.key == 'create_alarm_response': diff --git a/policy_module/osm_policy_module/core/agent.py b/policy_module/osm_policy_module/core/agent.py index b4ae260..f8f82b5 100644 --- a/policy_module/osm_policy_module/core/agent.py +++ b/policy_module/osm_policy_module/core/agent.py @@ -23,6 +23,7 @@ ## import json import logging +import yaml from kafka import KafkaConsumer from osm_policy_module.core.config import Config @@ -55,7 +56,10 @@ class PolicyModuleAgent: log.info("Message arrived: %s", message) try: if message.key == 'configure_scaling': - content = json.loads(message.value) + try: + content = json.loads(message.value) + except: + content = yaml.safe_load(message.value) log.info("Creating scaling record in DB") # TODO: Use transactions: http://docs.peewee-orm.com/en/latest/peewee/transactions.html scaling_record = ScalingRecord.create( diff --git a/policy_module/osm_policy_module/tests/unit/test_policy_config_agent.py b/policy_module/osm_policy_module/tests/unit/test_policy_agent.py similarity index 100% rename from policy_module/osm_policy_module/tests/unit/test_policy_config_agent.py rename to policy_module/osm_policy_module/tests/unit/test_policy_agent.py diff --git a/policy_module/requirements.txt b/policy_module/requirements.txt index fbdc2a8..f92cee9 100644 --- a/policy_module/requirements.txt +++ b/policy_module/requirements.txt @@ -1,4 +1,5 @@ kafka==1.3.* peewee==3.1.* jsonschema==2.6.* -six \ No newline at end of file +six +pyyaml \ No newline at end of file -- 2.25.1