stacklight-integration-tests/stacklight_tests/influxdb_grafana/grafana_ui/api.py
Igor Degtiarov 98bedc5de3 Add LDAP test for authentication only
Change-Id: I395bfc2e390fb735f7d4dc1838eaad5a48aa7d0c
2016-08-16 17:32:16 +03:00

77 lines
3.2 KiB
Python

# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from fuelweb_test import logger
from proboscis import asserts
from stacklight_tests.helpers.ui_tester import ui_driver
from stacklight_tests.influxdb_grafana.grafana_ui import pages
def check_grafana_dashboards(grafana_url):
login_key_xpath = '/html/body/div/div[2]/div/div/div[2]/form/div[2]/button'
with ui_driver(grafana_url, "Grafana", login_key_xpath) as driver:
login_page = pages.LoginPage(driver)
login_page.is_login_page()
home_page = login_page.login("grafana", "grafanapass")
home_page.is_main_page()
dashboard_names = {
"Apache", "Cinder", "Elasticsearch", "Glance", "HAProxy", "Heat",
"Hypervisor", "InfluxDB", "Keystone", "LMA self-monitoring",
"Memcached", "MySQL", "Neutron", "Nova", "RabbitMQ", "System"
}
dashboard_names = {
panel_name.lower() for panel_name in dashboard_names}
available_dashboards_names = {
dashboard.text.lower() for dashboard in home_page.dashboards}
msg = ("There is not enough panels in available panels, "
"panels that are not presented: {}")
# NOTE(rpromyshlennikov): should there be 'elasticsearch'
# and 'influxdb' dashboards?
asserts.assert_true(
dashboard_names.issubset(available_dashboards_names),
msg.format(dashboard_names - available_dashboards_names))
for name in available_dashboards_names:
dashboard_page = home_page.open_dashboard(name)
dashboard_page.get_back_to_home()
def check_grafana_ldap(grafana_url, authz=False, uadmin=("uadmin", "uadmin"),
uviewer=("uviewer", "uviewer")):
_check_available_menu_items_for_user(uadmin, grafana_url, authz)
_check_available_menu_items_for_user(uviewer, grafana_url, authz)
def _check_available_menu_items_for_user(user, url, authz):
logger.info("Checking Grafana service at {} with LDAP authorization "
"for {} user".format(url, user[0]))
login_key_xpath = '//form[1]//button[1]'
admin_panels = ["Dashboards", "Data Sources", "Plugins"]
viewer_panel = list(admin_panels[1]) if authz else admin_panels
with ui_driver(url, "Grafana", login_key_xpath) as driver:
login_page = pages.LoginPage(driver)
login_page.is_login_page()
home_page = login_page.login(*user)
home_page.is_main_page()
menu_items = [name.text for name in home_page.main_menu_items]
msg = "Not all required panels are available in main menu."
asserts.assert_true(
(admin_panels if ("uadmin" in user)
else viewer_panel) == menu_items,
msg
)