Ian Wienand 59e8221e7c grafana : import and screenshot project-config graphs
This is a job that imports the graphs we have defined in
project-config/grafana to a testing grafana instance, then takes some
screenshots to validate the layout and aid review.

Operation is fairly straight-forward; a grafana container is setup
(see related work in Ibbc2b116d0c496655a7ce6bb6971e8270ac32647) and
grafyaml is used to import the dashboards from project-config.  We
query the grafana instance to find the dashboards, then use selenium
and a small helper to take screenshots of each.

It pulls graphyaml from the buildset registry as a soft dependency, so
we can also add it as an extra test to the grafyaml repo.

Change-Id: Ice0863d5a180738119d572df1871093a292126be
2022-06-24 13:56:09 +10:00

51 lines
1.4 KiB
Python

#! /usr/bin/env python3
#
# Copyright 2022 RedHat, 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.
#
# A selenium wrapper to take OpenDev grafana screenshots in CI
import sys
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
out = sys.argv[1]
height = sys.argv[2]
url = sys.argv[3]
print("Getting %s -> %s" % (url, out))
firefox_options = webdriver.FirefoxOptions()
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
options=firefox_options)
driver.set_window_size(1920, height)
driver.get(url)
WebDriverWait(driver, 30).until(
lambda driver: driver.execute_script(
'return document.readyState') == 'complete')
# NOTE(ianw) : Grafana is a magic react app and I haven't found
# anything to reliably activate on other than just waiting a bit.
time.sleep(5)
driver.get_screenshot_as_file(out)
driver.quit()