From 589bdb9551259741c6e8972c32eff4fcbaabd741 Mon Sep 17 00:00:00 2001 From: Kaiyan Sheng Date: Tue, 9 Feb 2016 16:21:17 -0700 Subject: [PATCH] Detect Endpoint Changes in Http Check In monasca agent, detect protocol changes on urls in http check. If the protocal changed, remove the old instance in http_check.yaml and merge in the new one. Change-Id: I16a1ee10cfad0bcdd624328cf4a54a34a8038f36 --- monasca_setup/agent_config.py | 15 ++++++++++++++- monasca_setup/main.py | 12 ++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/monasca_setup/agent_config.py b/monasca_setup/agent_config.py index f5ecc6f0..3cc6d79e 100644 --- a/monasca_setup/agent_config.py +++ b/monasca_setup/agent_config.py @@ -1,4 +1,4 @@ -# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP +# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP """Classes to aid in configuration of the agent.""" @@ -92,3 +92,16 @@ def save_plugin_config(config_dir, plugin_name, user, conf): gid = pwd.getpwnam(user).pw_gid os.chmod(config_path, 0o640) os.chown(config_path, 0, gid) + + +def check_endpoint_changes(value, config): + new_url = value['instances'][0]['url'] + old_urls = [i['url'] for i in config['instances'] if 'url' in i] + new_path = new_url.split("://")[1] + old_paths = [url.split("://")[1] for url in old_urls] + for i, old_path in enumerate(old_paths): + if old_path == new_path: + if config['instances'][i]['url'] == config['instances'][i]['name']: + config['instances'][i]['name'] = new_url + config['instances'][i]['url'] = new_url + return value, config diff --git a/monasca_setup/main.py b/monasca_setup/main.py index e80d6628..907124c4 100644 --- a/monasca_setup/main.py +++ b/monasca_setup/main.py @@ -139,6 +139,9 @@ def modify_config(args, detected_config): old_config = agent_config.read_plugin_config_from_disk(args.config_dir, key) # merge old and new config, new has precedence if old_config is not None: + if key is "http_check": + old_config_urls = [i['url'] for i in old_config['instances'] if 'url' in i] + value, old_config = agent_config.check_endpoint_changes(value, old_config) agent_config.merge_by_name(value['instances'], old_config['instances']) # Sort before compare, if instances have no name the sort will fail making order changes significant try: @@ -146,8 +149,13 @@ def modify_config(args, detected_config): old_config['instances'].sort(key=lambda k: k['name']) except Exception: pass - if value == old_config: # Don't write config if no change - continue + value_urls = [i['url'] for i in value['instances'] if 'url' in i] + if key is "http_check": + if value_urls is old_config_urls: # Don't write config if no change + continue + else: + if value is old_config: + continue changes = True if args.dry_run: log.info("Changes would be made to the config file for the {0} check plugin".format(key))