From c9a2af5ee330d4b3571b139abfdfaf1fcfe705de Mon Sep 17 00:00:00 2001 From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk> Date: Thu, 31 Jan 2019 11:11:45 +0000 Subject: [PATCH] Moves SDN controller and SFEMC port numbers out of implementation - passed to CLMC as environment variables, default 8080 port used if not passed --- src/service/clmcservice/__init__.py | 2 ++ src/service/clmcservice/alertsapi/tests.py | 4 ++-- src/service/clmcservice/alertsapi/views.py | 3 ++- src/service/clmcservice/graphapi/views.py | 13 +++++++------ src/test/clmctest/alerts/resources_test_config.yaml | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/service/clmcservice/__init__.py b/src/service/clmcservice/__init__.py index 07f8d88..b2248c3 100644 --- a/src/service/clmcservice/__init__.py +++ b/src/service/clmcservice/__init__.py @@ -48,7 +48,9 @@ def main(global_config, **settings): Base.metadata.bind = engine # bind the engine to the Base class metadata settings['sfemc_fqdn'] = os.environ['SFEMC_FQDN'] # read the SFEMC FQDN from the OS environment + settings['sfemc_port'] = os.environ.get('SFEMC_PORT', 8080) # read the SFEMC port number from the OS environment, if not set use 8080 as default settings['sdn_controller_ip'] = os.environ['SDN_CONTROLLER_IP'] # read the SDN controller IP address from the OS environment + settings['sdn_controller_port'] = os.environ.get('SDN_CONTROLLER_PORT', 8080) # read the SDN controller port number from the OS environment, if not set use 8080 as default settings['influx_port'] = int(settings['influx_port']) # the influx port setting must be converted to integer instead of a string settings['kapacitor_port'] = int(settings['kapacitor_port']) # the kapacitor port setting must be converted to integer instead of a string diff --git a/src/service/clmcservice/alertsapi/tests.py b/src/service/clmcservice/alertsapi/tests.py index 5c5b4fa..8fd2ac0 100644 --- a/src/service/clmcservice/alertsapi/tests.py +++ b/src/service/clmcservice/alertsapi/tests.py @@ -62,7 +62,7 @@ class TestAlertsConfigurationAPI(object): """ self.registry = testing.setUp() - self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092, "sfemc_fqdn": "sfemc.localhost"}) + self.registry.add_settings({"kapacitor_host": "localhost", "kapacitor_port": 9092, "sfemc_fqdn": "sfemc.localhost", "sfemc_port": 8081}) yield @@ -301,7 +301,7 @@ def extract_alert_spec_data(alert_spec): for handler_url in trigger.trigger_tpl["action"]["implementation"]: if handler_url == "flame_sfemc": - handler_url = "http://sfemc.localhost:8080/sfemc/event/{0}/{1}/{2}".format(sfc, policy_id, "trigger_id_{0}".format(version)) + handler_url = "http://sfemc.localhost:8081/sfemc/event/{0}/{1}/{2}".format(sfc, policy_id, "trigger_id_{0}".format(version)) handler_id = "{0}\n{1}\n{2}\n{3}\n{4}".format(sfc, sfc_instance, policy_id, trigger_id, handler_url) handler_id = AlertsConfigurationAPI.get_hash(handler_id) diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 20892c3..d794e65 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -326,7 +326,8 @@ class AlertsConfigurationAPI(object): # check for flame_sfemc entry, if found replace with sfemc FQDN if http_handler_url == SFEMC: sfemc_fqdn = self.request.registry.settings['sfemc_fqdn'] - http_handler_url = "http://{0}:8080/sfemc/event/{1}/{2}/{3}".format(sfemc_fqdn, sfc, policy_id, trigger_id) + sfemc_port = self.request.registry.settings['sfemc_port'] + http_handler_url = "http://{0}:{1}/sfemc/event/{2}/{3}/{4}".format(sfemc_fqdn, sfemc_port, sfc, policy_id, trigger_id) handler_id = "{0}\n{1}\n{2}\n{3}\n{4}".format(sfc, sfc_i, policy_id, event_id, http_handler_url) handler_id = self.get_hash(handler_id) diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py index afa9a5c..15cf070 100644 --- a/src/service/clmcservice/graphapi/views.py +++ b/src/service/clmcservice/graphapi/views.py @@ -221,13 +221,14 @@ class GraphAPI(object): graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db sdn_controller_ip = self.request.registry.settings['sdn_controller_ip'] + sdn_controller_port = self.request.registry.settings['sdn_controller_port'] # retrieve all switches - if SDN controller is unavailable on the given IP address return 503 Service Unavailable try: - url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/core/controller/switches/json") + url = "http://{0}:{1}{2}".format(sdn_controller_ip, sdn_controller_port, "/wm/core/controller/switches/json") response = get(url) except exceptions.ConnectionError: - msg = "The SDN controller is not available on IP {0} and port 8080.".format(sdn_controller_ip) + msg = "The SDN controller is not available on IP {0} and port {1}.".format(sdn_controller_ip, sdn_controller_port) log.error("Unexpected error: {0}".format(msg)) raise HTTPServiceUnavailable("The SDN controller couldn't be reached when trying to build the network topology.") @@ -252,10 +253,10 @@ class GraphAPI(object): # retrieve all external links (gathered through BDDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable try: - url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/external-links/json") + url = "http://{0}:{1}{2}".format(sdn_controller_ip, sdn_controller_port, "/wm/topology/external-links/json") response = get(url) except exceptions.ConnectionError: - msg = "The SDN controller is not available on IP {0} and port 8080.".format(sdn_controller_ip) + msg = "The SDN controller is not available on IP {0} and port {1}.".format(sdn_controller_ip, sdn_controller_port) log.error("Unexpected error: {0}".format(msg)) raise HTTPServiceUnavailable("The SDN controller couldn't be reached when trying to build the network topology.") @@ -274,10 +275,10 @@ class GraphAPI(object): # retrieve all local links (gathered through LLDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable try: - url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/links/json") + url = "http://{0}:{1}{2}".format(sdn_controller_ip, sdn_controller_port, "/wm/topology/links/json") response = get(url) except exceptions.ConnectionError: - msg = "The SDN controller is not available on IP {0} and port 8080.".format(sdn_controller_ip) + msg = "The SDN controller is not available on IP {0} and port {1}.".format(sdn_controller_ip, sdn_controller_port) log.error("Unexpected error: {0}".format(msg)) raise HTTPServiceUnavailable("The SDN controller couldn't be reached when trying to build the network topology.") diff --git a/src/test/clmctest/alerts/resources_test_config.yaml b/src/test/clmctest/alerts/resources_test_config.yaml index 9bd17df..6f83faa 100644 --- a/src/test/clmctest/alerts/resources_test_config.yaml +++ b/src/test/clmctest/alerts/resources_test_config.yaml @@ -3,7 +3,7 @@ tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 metadata: template_name: Flame CLMC Alerts Integration Test servicefunctionchain: MS_Template_1 - sfci: MS_I1 +# sfci: MS_I1 # Import own definitions of nodes, capabilities and policy syntax. -- GitLab