From 6df0925b25dc0e4c9dfdcc4cbd1b2f6e1099f85c Mon Sep 17 00:00:00 2001
From: "Ritchie, Frank (fr801x)" <fr801x@att.com>
Date: Wed, 30 Aug 2023 16:10:44 -0400
Subject: [PATCH] Make selenium v4 syntax optional

Make selenium v4 syntax optional using the same pattern as

https://review.opendev.org/c/openstack/openstack-helm-infra/+/892708

See:

https: //review.opendev.org/c/openstack/openstack-helm-infra/+/883894/5/grafana/templates/bin/_selenium-tests.py.tpl
Change-Id: I744b721750c474db9fecbd46280d30cfb8347a6f
---
 grafana/Chart.yaml                           |  2 +-
 grafana/templates/bin/_selenium-tests.py.tpl | 12 ++++++++++++
 grafana/values.yaml                          |  3 +++
 releasenotes/notes/grafana.yaml              |  1 +
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/grafana/Chart.yaml b/grafana/Chart.yaml
index 02e1a36b5..469bc9f4c 100644
--- a/grafana/Chart.yaml
+++ b/grafana/Chart.yaml
@@ -15,7 +15,7 @@ apiVersion: v1
 appVersion: v9.2.10
 description: OpenStack-Helm Grafana
 name: grafana
-version: 0.1.21
+version: 0.1.22
 home: https://grafana.com/
 sources:
   - https://github.com/grafana/grafana
diff --git a/grafana/templates/bin/_selenium-tests.py.tpl b/grafana/templates/bin/_selenium-tests.py.tpl
index f1c3d8c72..079a8d060 100644
--- a/grafana/templates/bin/_selenium-tests.py.tpl
+++ b/grafana/templates/bin/_selenium-tests.py.tpl
@@ -22,7 +22,9 @@ 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
+{{- if .Values.selenium_v4 }}
 from selenium.webdriver.chrome.service import Service
+{{- end }}
 from selenium.common.exceptions import TimeoutException
 from selenium.common.exceptions import NoSuchElementException
 
@@ -57,8 +59,12 @@ options.add_argument('--headless')
 options.add_argument('--no-sandbox')
 options.add_argument('--window-size=1920x1080')
 
+{{- if .Values.selenium_v4 }}
 service = Service(executable_path=chrome_driver)
 browser = webdriver.Chrome(service=service, options=options)
+{{- else }}
+browser = webdriver.Chrome(chrome_driver, chrome_options=options)
+{{- end }}
 
 logger.info("Attempting to open Grafana dashboard")
 try:
@@ -74,9 +80,15 @@ except TimeoutException:
 
 logger.info("Attempting to log into Grafana dashboard")
 try:
+{{- if .Values.selenium_v4 }}
     browser.find_element(By.NAME, 'user').send_keys(username)
     browser.find_element(By.NAME, 'password').send_keys(password)
     browser.find_element(By.CSS_SELECTOR, '[aria-label="Login button"]').click()
+{{- else }}
+    browser.find_element_by_name('user').send_keys(username)
+    browser.find_element_by_name('password').send_keys(password)
+    browser.find_element_by_css_selector('[aria-label="Login button"]').click()
+{{- end }}
     logger.info("Successfully logged in to Grafana")
 except NoSuchElementException:
     logger.error("Failed to log in to Grafana")
diff --git a/grafana/values.yaml b/grafana/values.yaml
index a62b97ca6..64a4276c1 100644
--- a/grafana/values.yaml
+++ b/grafana/values.yaml
@@ -31,6 +31,9 @@ images:
       - dep_check
       - image_repo_sync
 
+# Use selenium v4 syntax
+selenium_v4: true
+
 labels:
   grafana:
     node_selector_key: openstack-control-plane
diff --git a/releasenotes/notes/grafana.yaml b/releasenotes/notes/grafana.yaml
index 1fc6c0406..deae4f874 100644
--- a/releasenotes/notes/grafana.yaml
+++ b/releasenotes/notes/grafana.yaml
@@ -22,4 +22,5 @@ grafana:
   - 0.1.19 Update grafana to 9.2.10
   - 0.1.20 Upgrade osh-selenium image to latest-ubuntu_focal
   - 0.1.21 Fix run migrator job deployment condition
+  - 0.1.22 Make selenium v4 syntax optional
 ...