From 1bac5769e98d55f1b6afbc701e71d61aad29eccf Mon Sep 17 00:00:00 2001 From: Swann Croiset Date: Tue, 5 Jul 2016 16:16:19 +0200 Subject: [PATCH] Use standard HTTP ports for UI All StackLight plugins will switch to use standard HTTP ports for their UI (Kibana, Grafana and Nagios UI). This change checks whether Grafana and Nagios use the old (non-standard) ports, if not the tests will use the standard port numbers. This avoids breaking the CI after the patches have landed in the respective plugin repositories. Co-Authored-By: Simon Pasquier Change-Id: Id94cae82b2bea92e049975ccc9e91e4383f52931 --- stacklight_tests/helpers/checkers.py | 15 +++++++++++++ stacklight_tests/influxdb_grafana/api.py | 18 +++++++++++++--- .../lma_infrastructure_alerting/api.py | 21 +++++++++++++++---- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/stacklight_tests/helpers/checkers.py b/stacklight_tests/helpers/checkers.py index 5f8d284..71adc57 100644 --- a/stacklight_tests/helpers/checkers.py +++ b/stacklight_tests/helpers/checkers.py @@ -12,6 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from contextlib import closing +import socket + from proboscis import asserts import requests @@ -56,3 +59,15 @@ def check_process_count(remote, process, count): len(pids), count, msg.format(process=process, count=count, got=len(pids))) return pids + + +def check_port(address, port): + """Check whether or not a TCP port is open. + + :param address: server address + :type address: str + :param port: server port + :type port: str + """ + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: + return sock.connect_ex((address, port)) == 0 diff --git a/stacklight_tests/influxdb_grafana/api.py b/stacklight_tests/influxdb_grafana/api.py index 3bb2ee1..e320042 100644 --- a/stacklight_tests/influxdb_grafana/api.py +++ b/stacklight_tests/influxdb_grafana/api.py @@ -23,6 +23,18 @@ from stacklight_tests.influxdb_grafana import plugin_settings class InfluxdbPluginApi(base_test.PluginApi): + def __init__(self): + super(InfluxdbPluginApi, self).__init__() + self._grafana_port = None + + @property + def grafana_port(self): + if self._grafana_port is None: + self._grafana_port = 80 + if self.checkers.check_port(self.get_plugin_vip(), 8000): + self._grafana_port = 8000 + return self._grafana_port + def get_plugin_settings(self): return plugin_settings @@ -39,7 +51,8 @@ class InfluxdbPluginApi(base_test.PluginApi): return self.helpers.get_plugin_vip(self.settings.vip_name) def get_grafana_url(self, path=''): - return "http://{0}:8000/{1}".format(self.get_plugin_vip(), path) + return "http://{0}:{1}/{2}".format(self.get_plugin_vip(), + self.grafana_port, path) def get_influxdb_url(self, path=''): return "http://{0}:8086/{1}".format(self.get_plugin_vip(), path) @@ -118,8 +131,7 @@ class InfluxdbPluginApi(base_test.PluginApi): self.settings.name, self.settings.version) def check_grafana_dashboards(self): - grafana_url = self.get_grafana_url() - ui_api.check_grafana_dashboards(grafana_url) + ui_api.check_grafana_dashboards(self.get_grafana_url()) def get_nova_instance_creation_time_metrics(self, time_point=None): """Gets instance creation metrics for provided interval diff --git a/stacklight_tests/lma_infrastructure_alerting/api.py b/stacklight_tests/lma_infrastructure_alerting/api.py index e6ec427..45f735b 100644 --- a/stacklight_tests/lma_infrastructure_alerting/api.py +++ b/stacklight_tests/lma_infrastructure_alerting/api.py @@ -25,6 +25,18 @@ from stacklight_tests.lma_infrastructure_alerting import( class InfraAlertingPluginApi(base_test.PluginApi): + def __init__(self): + super(InfraAlertingPluginApi, self).__init__() + self._nagios_port = None + + @property + def nagios_port(self): + if self._nagios_port is None: + self._nagios_port = 80 + if self.checkers.check_port(self.get_plugin_vip(), 8001): + self._nagios_port = 8001 + return self._nagios_port + def get_plugin_settings(self): return infra_alerting_plugin_settings @@ -60,12 +72,13 @@ class InfraAlertingPluginApi(base_test.PluginApi): ) def get_authenticated_nagios_url(self): - return "http://{0}:{1}@{2}:8001".format(self.settings.nagios_user, - self.settings.nagios_password, - self.get_plugin_vip()) + return "http://{0}:{1}@{2}:{3}".format(self.settings.nagios_user, + self.settings.nagios_password, + self.get_plugin_vip(), + self.nagios_port) def get_nagios_url(self): - return "http://{}:8001/".format(self.get_plugin_vip()) + return "http://{0}:{1}".format(self.get_plugin_vip(), self.nagios_port) def open_nagios_page(self, link_text, anchor): driver = self.ui_tester.get_driver(self.get_authenticated_nagios_url(),