Merge "Grafana: Add Selenium tests to helm test pod"
This commit is contained in:
commit
3ba03ed8ea
87
grafana/templates/bin/_selenium-tests.py.tpl
Normal file
87
grafana/templates/bin/_selenium-tests.py.tpl
Normal file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
{{/*
|
||||
Copyright 2019 The Openstack-Helm Authors.
|
||||
|
||||
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.
|
||||
*/}}
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
|
||||
# Create logger, console handler and formatter
|
||||
logger = logging.getLogger('Grafana Selenium Tests')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Set the formatter and add the handler
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
# Get Grafana admin user name
|
||||
if "GRAFANA_USER" in os.environ:
|
||||
grafana_user = os.environ['GRAFANA_USER']
|
||||
logger.info('Found Grafana username')
|
||||
else:
|
||||
logger.critical('Grafana username environment variable not set')
|
||||
sys.exit(1)
|
||||
|
||||
if "GRAFANA_PASSWORD" in os.environ:
|
||||
grafana_password = os.environ['GRAFANA_PASSWORD']
|
||||
logger.info('Found Grafana password')
|
||||
else:
|
||||
logger.critical('Grafana password environment variable not set')
|
||||
sys.exit(1)
|
||||
|
||||
if "GRAFANA_URI" in os.environ:
|
||||
grafana_uri = os.environ['GRAFANA_URI']
|
||||
logger.info('Found Grafana URI')
|
||||
else:
|
||||
logger.critical('Grafana URI environment variable not set')
|
||||
sys.exit(1)
|
||||
|
||||
options = Options()
|
||||
options.add_argument('--headless')
|
||||
options.add_argument('--no-sandbox')
|
||||
options.add_argument('--window-size=1920x1080')
|
||||
|
||||
logger.info("Attempting to open Grafana dashboard")
|
||||
try:
|
||||
browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options)
|
||||
logger.info("Successfully opened Grafana dashboard")
|
||||
except exception, e:
|
||||
logger.error("Unable to open Grafana")
|
||||
browser.close()
|
||||
sys.exit(1)
|
||||
|
||||
logger.info("Attempting to log into Grafana dashboard")
|
||||
try:
|
||||
browser.get(grafana_uri)
|
||||
browser.find_element_by_name('username').send_keys(grafana_user)
|
||||
browser.find_element_by_name('password').send_keys(grafana_password)
|
||||
browser.find_element_by_css_selector('body > grafana-app > div.main-view > div > div:nth-child(1) > div > div > div.login-inner-box > form > div.login-button-group > button').click()
|
||||
logger.info("Successfully logged in to Grafana")
|
||||
except exception, e:
|
||||
logger.error("Failed to log in to Grafana")
|
||||
browser.close()
|
||||
sys.exit(1)
|
||||
|
||||
browser.close()
|
@ -32,6 +32,8 @@ data:
|
||||
{{ tuple "bin/_helm-tests.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
grafana.sh: |
|
||||
{{ tuple "bin/_grafana.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
selenium-tests.py: |
|
||||
{{ tuple "bin/_selenium-tests.py.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
set-admin-password.sh: |
|
||||
{{ tuple "bin/_set-admin-password.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
{{- end }}
|
||||
|
@ -67,6 +67,32 @@ spec:
|
||||
mountPath: /tmp/helm-tests.sh
|
||||
subPath: helm-tests.sh
|
||||
readOnly: true
|
||||
- name: {{.Release.Name}}-selenium-tests
|
||||
{{ tuple $envAll "selenium_tests" | include "helm-toolkit.snippets.image" | indent 6 }}
|
||||
{{ tuple $envAll $envAll.Values.pod.resources.jobs.tests | include "helm-toolkit.snippets.kubernetes_resources" | indent 6 }}
|
||||
{{ dict "envAll" $envAll "application" "test" "container" "helm_tests" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 6 }}
|
||||
command:
|
||||
- /tmp/selenium-tests.py
|
||||
env:
|
||||
- name: GRAFANA_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: grafana-admin-creds
|
||||
key: GRAFANA_ADMIN_USERNAME
|
||||
- name: GRAFANA_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: grafana-admin-creds
|
||||
key: GRAFANA_ADMIN_PASSWORD
|
||||
- name: GRAFANA_URI
|
||||
value: {{ tuple "grafana" "public" "grafana" . | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup" }}
|
||||
volumeMounts:
|
||||
- name: pod-tmp
|
||||
mountPath: /tmp
|
||||
- name: grafana-bin
|
||||
mountPath: /tmp/selenium-tests.py
|
||||
subPath: selenium-tests.py
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: pod-tmp
|
||||
emptyDir: {}
|
||||
|
@ -23,6 +23,7 @@ images:
|
||||
db_init: docker.io/openstackhelm/heat:newton-ubuntu_xenial
|
||||
grafana_db_session_sync: docker.io/openstackhelm/heat:newton-ubuntu_xenial
|
||||
helm_tests: docker.io/openstackhelm/heat:newton-ubuntu_xenial
|
||||
selenium_tests: docker.io/openstackhelm/osh-selenium:latest-ubuntu_xenial
|
||||
image_repo_sync: docker.io/docker:17.07.0
|
||||
pull_policy: IfNotPresent
|
||||
local_registry:
|
||||
|
Loading…
x
Reference in New Issue
Block a user