Update Nagios Helm test to use python3
This change updates the selenium_tests container image to one which installs python3. The selenium-test.py template file has been refactored to match the structure of the selenium tests in /tools/gate/selenium Depends On: https://review.opendev.org/688436 Change-Id: I49e0cfd05f27f868864a98e8e68ffe79e28c0f03
This commit is contained in:
parent
b661ce95df
commit
b3d2a178ad
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
Copyright 2019 The Openstack-Helm Authors.
|
Copyright 2019 The Openstack-Helm Authors.
|
||||||
@ -24,118 +24,114 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
|
from selenium.common.exceptions import TimeoutException
|
||||||
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
|
from selenium.common.exceptions import ScreenshotException
|
||||||
|
|
||||||
# Create logger, console handler and formatter
|
# Create logger, console handler and formatter
|
||||||
logger = logging.getLogger('Nagios Selenium Tests')
|
logger = logging.getLogger('Nagios Selenium Tests')
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
ch = logging.StreamHandler()
|
ch = logging.StreamHandler()
|
||||||
ch.setLevel(logging.DEBUG)
|
ch.setLevel(logging.DEBUG)
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
|
)
|
||||||
|
|
||||||
# Set the formatter and add the handler
|
# Set the formatter and add the handler
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
|
|
||||||
if "NAGIOS_USER" in os.environ:
|
def get_variable(env_var):
|
||||||
nagios_user = os.environ['NAGIOS_USER']
|
if env_var in os.environ:
|
||||||
logger.info('Found Nagios username')
|
logger.info('Found "{}"'.format(env_var))
|
||||||
else:
|
return os.environ[env_var]
|
||||||
logger.critical('Nagios username environment variable not set')
|
else:
|
||||||
|
logger.critical('Variable "{}" is not defined!'.format(env_var))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if "NAGIOS_PASSWORD" in os.environ:
|
def click_link_by_name(link_name):
|
||||||
nagios_password = os.environ['NAGIOS_PASSWORD']
|
try:
|
||||||
logger.info('Found Nagios password')
|
logger.info("Clicking '{}' link".format(link_name))
|
||||||
else:
|
link = browser.find_element_by_link_text(link_name)
|
||||||
logger.critical('Nagios password environment variable not set')
|
link.click()
|
||||||
|
except NoSuchElementException:
|
||||||
|
logger.error("Failed clicking '{}' link".format(link_name))
|
||||||
|
browser.quit()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if "NAGIOS_URI" in os.environ:
|
def take_screenshot(page_name, artifacts_dir='/tmp/artifacts/'):
|
||||||
nagios_uri = os.environ['NAGIOS_URI']
|
file_name = page_name.replace(' ', '_')
|
||||||
logger.info('Found Nagios URI')
|
try:
|
||||||
else:
|
el = WebDriverWait(browser, 15)
|
||||||
logger.critical('Nagios URI environment variable not set')
|
browser.save_screenshot('{}{}.png'.format(artifacts_dir, file_name))
|
||||||
|
logger.info("Successfully captured {} screenshot".format(page_name))
|
||||||
|
except ScreenshotException:
|
||||||
|
logger.error("Failed to capture {} screenshot".format(page_name))
|
||||||
|
browser.quit()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
username = get_variable('NAGIOS_USER')
|
||||||
|
password = get_variable('NAGIOS_PASSWORD')
|
||||||
|
nagios_uri = get_variable('NAGIOS_URI')
|
||||||
|
nagios_url = 'http://{0}:{1}@{2}'.format(username, password, nagios_uri)
|
||||||
|
|
||||||
|
chrome_driver = '/etc/selenium/chromedriver'
|
||||||
options = Options()
|
options = Options()
|
||||||
options.add_argument('--headless')
|
options.add_argument('--headless')
|
||||||
options.add_argument('--no-sandbox')
|
options.add_argument('--no-sandbox')
|
||||||
options.add_argument('--window-size=1920x1080')
|
options.add_argument('--window-size=1920x1080')
|
||||||
|
browser = webdriver.Chrome(chrome_driver, chrome_options=options)
|
||||||
|
|
||||||
logger.info("Attempting to open Chrome webdriver")
|
|
||||||
try:
|
try:
|
||||||
browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options)
|
logger.info('Attempting to connect to Nagios')
|
||||||
logger.info("Successfully opened Chrome webdriver")
|
browser.get(nagios_url)
|
||||||
except:
|
el = WebDriverWait(browser, 15).until(
|
||||||
logger.error("Unable to open Chrome webdriver")
|
EC.title_contains('Nagios')
|
||||||
browser.close()
|
)
|
||||||
|
logger.info('Connected to Nagios')
|
||||||
|
except TimeoutException:
|
||||||
|
logger.critical('Timed out waiting for Nagios')
|
||||||
|
browser.quit()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logger.info("Attempting to login to Nagios dashboard")
|
|
||||||
try:
|
try:
|
||||||
browser.get('http://'+nagios_user+':'+nagios_password+'@'+nagios_uri)
|
logger.info('Switching Focus to Navigation side frame')
|
||||||
logger.info("Successfully logged in to Nagios dashboard")
|
|
||||||
sideFrame = browser.switch_to.frame('side')
|
sideFrame = browser.switch_to.frame('side')
|
||||||
try:
|
except NoSuchElementException:
|
||||||
logger.info("Attempting to access Nagios services link")
|
logger.error('Failed selecting side frame')
|
||||||
services = browser.find_element_by_link_text('Services')
|
browser.quit()
|
||||||
services.click()
|
|
||||||
logger.info("Successfully accessed Nagios services link")
|
|
||||||
try:
|
|
||||||
logger.info("Attempting to capture Nagios services screen")
|
|
||||||
el = WebDriverWait(browser, 15)
|
|
||||||
browser.save_screenshot('/tmp/artifacts/Nagios_Services.png')
|
|
||||||
logger.info("Successfully captured Nagios services screen")
|
|
||||||
except:
|
|
||||||
logger.error("Unable to capture Nagios services screen")
|
|
||||||
browser.close()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except:
|
|
||||||
logger.error("Unable to access Nagios services link")
|
try:
|
||||||
browser.close()
|
logger.info('Attempting to visit Services page')
|
||||||
|
click_link_by_name('Services')
|
||||||
|
take_screenshot('Nagios Services')
|
||||||
|
except TimeoutException:
|
||||||
|
logger.error('Failed to load Services page')
|
||||||
|
browser.quit()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
|
||||||
logger.info("Attempting to access Nagios host groups link")
|
try:
|
||||||
host_groups = browser.find_element_by_link_text('Host Groups')
|
logger.info('Attempting to visit Host Groups page')
|
||||||
host_groups.click()
|
click_link_by_name('Host Groups')
|
||||||
logger.info("Successfully accessed Nagios host groups link")
|
take_screenshot('Nagios Host Groups')
|
||||||
try:
|
except TimeoutException:
|
||||||
logger.info("Attempting to capture Nagios host groups screen")
|
logger.error('Failed to load Host Groups page')
|
||||||
el = WebDriverWait(browser, 15)
|
browser.quit()
|
||||||
browser.save_screenshot('/tmp/artifacts/Nagios_Host_Groups.png')
|
|
||||||
logger.info("Successfully captured Nagios host groups screen")
|
|
||||||
except:
|
|
||||||
logger.error("Unable to capture Nagios host groups screen")
|
|
||||||
browser.close()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except:
|
|
||||||
logger.error("Unable to access Nagios host groups link")
|
try:
|
||||||
browser.close()
|
logger.info('Attempting to visit Hosts page')
|
||||||
|
click_link_by_name('Hosts')
|
||||||
|
take_screenshot('Nagios Hosts')
|
||||||
|
except TimeoutException:
|
||||||
|
logger.error('Failed to load Hosts page')
|
||||||
|
browser.quit()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
|
||||||
logger.info("Attempting to access Nagios hosts link")
|
logger.info("The following screenshots were captured:")
|
||||||
hosts = browser.find_element_by_link_text('Hosts')
|
for root, dirs, files in os.walk("/tmp/artifacts/"):
|
||||||
hosts.click()
|
|
||||||
logger.info("Successfully accessed Nagios hosts link")
|
|
||||||
try:
|
|
||||||
logger.info("Attempting to capture Nagios hosts screen")
|
|
||||||
el = WebDriverWait(browser, 15)
|
|
||||||
browser.save_screenshot('/tmp/artifacts/Nagios_Hosts.png')
|
|
||||||
logger.info("Successfully captured Nagios hosts screen")
|
|
||||||
except:
|
|
||||||
logger.error("Unable to capture Nagios hosts screen")
|
|
||||||
browser.close()
|
|
||||||
sys.exit(1)
|
|
||||||
except:
|
|
||||||
logger.error("Unable to access Nagios hosts link")
|
|
||||||
browser.close()
|
|
||||||
sys.exit(1)
|
|
||||||
browser.close()
|
|
||||||
logger.info("The following screenshots were captured:")
|
|
||||||
for root, dirs, files in os.walk("/tmp/artifacts/"):
|
|
||||||
for name in files:
|
for name in files:
|
||||||
logger.info(os.path.join(root, name))
|
logger.info(os.path.join(root, name))
|
||||||
except:
|
|
||||||
logger.error("Unable to log in to Nagios dashbaord")
|
browser.quit()
|
||||||
browser.close()
|
|
||||||
sys.exit(1)
|
|
||||||
|
@ -21,7 +21,7 @@ images:
|
|||||||
apache_proxy: docker.io/httpd:2.4
|
apache_proxy: docker.io/httpd:2.4
|
||||||
nagios: docker.io/openstackhelm/nagios:latest-ubuntu_xenial
|
nagios: docker.io/openstackhelm/nagios:latest-ubuntu_xenial
|
||||||
dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.2.1
|
dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.2.1
|
||||||
selenium_tests: docker.io/openstackhelm/osh-selenium:latest-ubuntu_xenial
|
selenium_tests: docker.io/openstackhelm/osh-selenium:latest-ubuntu_bionic
|
||||||
image_repo_sync: docker.io/docker:17.07.0
|
image_repo_sync: docker.io/docker:17.07.0
|
||||||
pull_policy: IfNotPresent
|
pull_policy: IfNotPresent
|
||||||
local_registry:
|
local_registry:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user