Check that Nagios requires authentication

This change also improves the log messages by displaying the URLs of the
tested services.

Change-Id: Ib19e59046b060f0a406b62e95db7b6696e0e69e3
This commit is contained in:
Simon Pasquier
2016-06-24 10:30:47 +02:00
parent 5517dcbada
commit 689cb9adba
3 changed files with 37 additions and 17 deletions

View File

@@ -47,29 +47,31 @@ class ElasticsearchPluginApi(base_test.PluginApi):
def get_plugin_vip(self): def get_plugin_vip(self):
return self.helpers.get_plugin_vip(self.settings.vip_name) return self.helpers.get_plugin_vip(self.settings.vip_name)
def get_elasticsearch_url(self, query=''): def get_elasticsearch_url(self, path=''):
return "http://{}:9200/{}".format(self.get_plugin_vip(), query) return "http://{}:9200/{}".format(self.get_plugin_vip(), path)
def get_kibana_url(self): def get_kibana_url(self):
return "http://{}:80/".format(self.get_plugin_vip()) return "http://{}:80/".format(self.get_plugin_vip())
def check_plugin_online(self): def check_plugin_online(self):
logger.info("Check that Elasticsearch is ready") elasticsearch_url = self.get_elasticsearch_url()
logger.info("Checking Elasticsearch service at {}".format(
elasticsearch_url))
msg = "Elasticsearch responded with {0}, expected {1}" msg = "Elasticsearch responded with {0}, expected {1}"
self.checkers.check_http_get_response( self.checkers.check_http_get_response(elasticsearch_url, msg=msg)
self.get_elasticsearch_url(), msg=msg)
logger.info("Check that Kibana is running") kibana_url = self.get_kibana_url()
logger.info("Checking Kibana service at {}".format(kibana_url))
msg = "Kibana responded with {0}, expected {1}" msg = "Kibana responded with {0}, expected {1}"
self.checkers.check_http_get_response( self.checkers.check_http_get_response(
self.get_kibana_url(), msg=msg, kibana_url, msg=msg,
auth=(self.settings.kibana_username, auth=(self.settings.kibana_username,
self.settings.kibana_password) self.settings.kibana_password)
) )
def check_elasticsearch_nodes_count(self, expected_count): def check_elasticsearch_nodes_count(self, expected_count):
logger.debug("Get information about Elasticsearch nodes") logger.debug("Get information about Elasticsearch nodes")
url = self.get_elasticsearch_url(query='_nodes') url = self.get_elasticsearch_url(path='_nodes')
response = self.checkers.check_http_get_response(url) response = self.checkers.check_http_get_response(url)
nodes_count = len(response.json()['nodes']) nodes_count = len(response.json()['nodes'])

View File

@@ -38,11 +38,11 @@ class InfluxdbPluginApi(base_test.PluginApi):
def get_plugin_vip(self): def get_plugin_vip(self):
return self.helpers.get_plugin_vip(self.settings.vip_name) return self.helpers.get_plugin_vip(self.settings.vip_name)
def get_grafana_url(self, resource=''): def get_grafana_url(self, path=''):
return "http://{0}:8000/{1}".format(self.get_plugin_vip(), resource) return "http://{0}:8000/{1}".format(self.get_plugin_vip(), path)
def get_influxdb_url(self, resource=''): def get_influxdb_url(self, path=''):
return "http://{0}:8086/{1}".format(self.get_plugin_vip(), resource) return "http://{0}:8086/{1}".format(self.get_plugin_vip(), path)
def do_influxdb_query(self, def do_influxdb_query(self,
query, query,
@@ -56,6 +56,8 @@ class InfluxdbPluginApi(base_test.PluginApi):
params={"db": db, "u": user, "p": password, "q": query}) params={"db": db, "u": user, "p": password, "q": query})
def check_plugin_online(self): def check_plugin_online(self):
logger.info("InfluxDB service is at {}".format(
self.get_influxdb_url()))
logger.info("Check that the InfluxDB server replies to ping requests") logger.info("Check that the InfluxDB server replies to ping requests")
self.checkers.check_http_get_response( self.checkers.check_http_get_response(
url=self.get_influxdb_url('ping'), url=self.get_influxdb_url('ping'),
@@ -77,11 +79,13 @@ class InfluxdbPluginApi(base_test.PluginApi):
user=plugin_settings.influxdb_rootuser, user=plugin_settings.influxdb_rootuser,
password=plugin_settings.influxdb_rootpass) password=plugin_settings.influxdb_rootpass)
logger.info("Grafana service is at {}".format(
self.get_grafana_url()))
logger.info("Check that the Grafana UI server is running") logger.info("Check that the Grafana UI server is running")
self.checkers.check_http_get_response( self.checkers.check_http_get_response(
self.get_grafana_url('login')) self.get_grafana_url('login'))
logger.info("Check that the Grafana user is authorized") logger.info("Check that the Grafana admin user is authorized")
self.checkers.check_http_get_response( self.checkers.check_http_get_response(
self.get_grafana_url('api/org'), self.get_grafana_url('api/org'),
auth=(plugin_settings.grafana_user, plugin_settings.grafana_pass)) auth=(plugin_settings.grafana_user, plugin_settings.grafana_pass))

View File

@@ -45,16 +45,30 @@ class InfraAlertingPluginApi(base_test.PluginApi):
return self.helpers.get_plugin_vip(self.settings.vip_name) return self.helpers.get_plugin_vip(self.settings.vip_name)
def check_plugin_online(self): def check_plugin_online(self):
logger.info("Check that the Nagios server is running") nagios_url = self.get_nagios_url()
self.checkers.check_http_get_response(self.get_nagios_url()) logger.info("Nagios UI is at {}".format(nagios_url))
logger.info("Check that the '{}' user is authorized".format(
self.settings.nagios_user))
self.checkers.check_http_get_response(
nagios_url,
auth=(self.settings.nagios_user, self.settings.nagios_password)
)
logger.info("Check that the Nagios UI requires authentication")
self.checkers.check_http_get_response(
nagios_url, expected_code=401,
auth=(self.settings.nagios_user, 'rogue')
)
def get_nagios_url(self): def get_authenticated_nagios_url(self):
return "http://{0}:{1}@{2}:8001".format(self.settings.nagios_user, return "http://{0}:{1}@{2}:8001".format(self.settings.nagios_user,
self.settings.nagios_password, self.settings.nagios_password,
self.get_plugin_vip()) self.get_plugin_vip())
def get_nagios_url(self):
return "http://{}:8001/".format(self.get_plugin_vip())
def open_nagios_page(self, link_text, anchor): def open_nagios_page(self, link_text, anchor):
driver = self.ui_tester.get_driver(self.get_nagios_url(), driver = self.ui_tester.get_driver(self.get_authenticated_nagios_url(),
"//frame[2]", "Nagios Core") "//frame[2]", "Nagios Core")
driver.switch_to.default_content() driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_name("side")) driver.switch_to.frame(driver.find_element_by_name("side"))