diff --git a/playbooks/test-grafana.yaml b/playbooks/test-grafana.yaml new file mode 100644 index 0000000000..c29aa0a27d --- /dev/null +++ b/playbooks/test-grafana.yaml @@ -0,0 +1,6 @@ +- hosts: "grafana" + tasks: + + - name: Run selenium container + include_role: + name: run-selenium diff --git a/testinfra/test_grafana.py b/testinfra/test_grafana.py index 526b082853..044c20f5a4 100644 --- a/testinfra/test_grafana.py +++ b/testinfra/test_grafana.py @@ -12,6 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from selenium import webdriver +from selenium.webdriver.support.ui import WebDriverWait +from selenium.common.exceptions import TimeoutException +import time + testinfra_hosts = ['grafana01.opendev.org'] @@ -34,3 +39,34 @@ def test_grafana_api_denial(host): '-d \'{"dashboard": {}}\' ' 'https://grafana.opendev.org/api/snapshots') assert '403 Forbidden' in cmd.stdout + +def test_grafana_screenshots(host): + driver = webdriver.Remote( + command_executor='http://%s:4444/wd/hub' % (host.backend.get_hostname()), + desired_capabilities=webdriver.DesiredCapabilities.FIREFOX) + + try: + driver.get("https://localhost") + WebDriverWait(driver, 30).until(lambda driver: driver.execute_script( + 'return document.readyState') == 'complete') + # NOTE(ianw): The page doesn't really seem to be complete at + # this point, not sure what to listen for... + time.sleep(5) + driver.save_screenshot("/var/log/screenshots/grafana-main-page.png") + + driver.get("https://localhost/dashboards") + original_size = driver.get_window_size() + required_width = driver.execute_script( + 'return document.body.parentNode.scrollWidth') + required_height = driver.execute_script( + 'return document.body.parentNode.scrollHeight') + 100 + driver.set_window_size(required_width, required_height) + driver.find_element_by_tag_name('body'). \ + screenshot("/var/log/screenshots/grafana-dashboards-page.png") + driver.set_window_size( + original_size['width'], original_size['height']) + + except TimeoutException as e: + raise e + finally: + driver.quit() diff --git a/zuul.d/system-config-run.yaml b/zuul.d/system-config-run.yaml index b27a85bec3..434d5c7cc9 100644 --- a/zuul.d/system-config-run.yaml +++ b/zuul.d/system-config-run.yaml @@ -623,6 +623,7 @@ run_playbooks: - playbooks/letsencrypt.yaml - playbooks/service-grafana.yaml + run_test_playbook: playbooks/test-grafana.yaml files: - playbooks/bridge.yaml - playbooks/letsencrypt.yaml