From 1db1ddf0baf65bc5302ab5a09f748970de9ee425 Mon Sep 17 00:00:00 2001 From: "Kabanov, Dmitrii (dk370c)" Date: Tue, 25 Jun 2019 00:41:54 -0700 Subject: [PATCH] [Kibana] Add improvements to Selenium tests for Kibana This PS adds several fixes to Selenium tests (for Kibana) and adds role which allows to collect the results. Change-Id: If9fb5f50e395379fdd3ccc46e945a93606dcbabe --- playbooks/osh-infra-collect-logs.yaml | 4 +- roles/gather-selenium-data/tasks/main.yaml | 31 ++++++ tools/gate/selenium/kibanaSelenium.py | 118 ++++++++------------- 3 files changed, 78 insertions(+), 75 deletions(-) create mode 100644 roles/gather-selenium-data/tasks/main.yaml diff --git a/playbooks/osh-infra-collect-logs.yaml b/playbooks/osh-infra-collect-logs.yaml index 75412898e..337671e57 100644 --- a/playbooks/osh-infra-collect-logs.yaml +++ b/playbooks/osh-infra-collect-logs.yaml @@ -34,8 +34,10 @@ - describe-kubernetes-objects - gather-pod-logs - gather-prom-metrics + - gather-selenium-data tags: - helm-release-status - describe-kubernetes-objects - gather-pod-logs - - gather-prom-metrics \ No newline at end of file + - gather-prom-metrics + - gather-selenium-data diff --git a/roles/gather-selenium-data/tasks/main.yaml b/roles/gather-selenium-data/tasks/main.yaml new file mode 100644 index 000000000..3fcc9ca7d --- /dev/null +++ b/roles/gather-selenium-data/tasks/main.yaml @@ -0,0 +1,31 @@ +# 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. + +- name: "creating directory for helm release descriptions" + file: + path: "{{ logs_dir }}/selenium" + state: directory + +- name: "Get selenium data" + shell: |- + set -x + cp /tmp/artifacts/* {{ logs_dir }}/selenium/. + args: + executable: /bin/bash + ignore_errors: True + +- name: "Downloads logs to executor" + synchronize: + src: "{{ logs_dir }}/selenium" + dest: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}" + mode: pull + ignore_errors: True diff --git a/tools/gate/selenium/kibanaSelenium.py b/tools/gate/selenium/kibanaSelenium.py index 542be9be8..cca28ee95 100644 --- a/tools/gate/selenium/kibanaSelenium.py +++ b/tools/gate/selenium/kibanaSelenium.py @@ -7,98 +7,68 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException -from threading import Thread logger = logging.getLogger('Kibana Selenium Tests') logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() 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') ch.setFormatter(formatter) logger.addHandler(ch) -# Get Grafana admin user name -if "KIBANA_USER" in os.environ: - kibana_user = os.environ['KIBANA_USER'] - logger.info('Found Kibana username') -else: - logger.critical('Kibana username environment variable not set') - sys.exit(1) +artifacts = '/tmp/artifacts/' +if not os.path.exists(artifacts): + os.makedirs(artifacts) -if "KIBANA_PASSWORD" in os.environ: - kibana_password = os.environ['KIBANA_PASSWORD'] - logger.info('Found Kibana password') -else: - logger.critical('Kibana password environment variable not set') - sys.exit(1) -if "KIBANA_JOURNAL_URI" in os.environ: - kibana_journal_uri = os.environ['KIBANA_JOURNAL_URI'] - logger.info('Found Kibana Journal URI') -else: - logger.critical('Kibana Journal URI environment variable not set') - sys.exit(1) +def get_variable(env_var): + if env_var in os.environ: + logger.info('Found "{}"'.format(env_var)) + return os.environ[env_var] + else: + logger.critical('Variable "{}" is not defined!'.format(env_var)) + sys.exit(1) -if "KIBANA_KERNEL_URI" in os.environ: - kibana_kernel_uri = os.environ['KIBANA_KERNEL_URI'] - logger.info('Found Kibana Kernel URI') -else: - logger.critical('Kibana Kernel URI environment variable not set') - sys.exit(1) -if "KIBANA_LOGSTASH_URI" in os.environ: - kibana_logstash_uri = os.environ['KIBANA_LOGSTASH_URI'] - logger.info('Found Kibana Logstash URI') -else: - logger.critical('Kibana Logstash URI environment variable not set') - sys.exit(1) +kibana_user = get_variable('KIBANA_USER') +kibana_password = get_variable('KIBANA_PASSWORD') +kibana_journal_uri = get_variable('KIBANA_JOURNAL_URI') +kibana_kernel_uri = get_variable('KIBANA_KERNEL_URI') +kibana_logstash_uri = get_variable('KIBANA_LOGSTASH_URI') options = Options() options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--window-size=1920x1080') -errNO = 1 +targets = [(kibana_kernel_uri, 'Kernel'), + (kibana_journal_uri, 'Journal'), + (kibana_logstash_uri, 'Logstash')] -browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) -url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_journal_uri) -browser.get(url) +for target, name in targets: + retry = 3 + while retry > 0: + prefix = '' + browser = webdriver.Chrome( + '/etc/selenium/chromedriver', chrome_options=options) + url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, target) + browser.get(url) -try: - WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) - ) - browser.save_screenshot('/tmp/artifacts/Kibana_JournalIndex.png') -except TimeoutException, e: - browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) - logger.error('Error occured loading Journal index') - errNO += 1 - -browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) -url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_kernel_uri) -browser.get(url) - -try: - WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) - ) - browser.save_screenshot('/tmp/artifacts/Kibana_KernelIndex.png') -except TimeoutException, e: - browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) - logger.error('Error occured loading Kernel index') - errNO += 1 - -browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) -url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_logstash_uri) -browser.get(url) - -try: - WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) - ) - browser.save_screenshot('/tmp/artifacts/Kibana_LogstashIndex.png') -except TimeoutException, e: - browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) - logger.error('Error occured loading Logstash index') - errNO += 1 + try: + WebDriverWait(browser, 60).until( + EC.presence_of_element_located( + (By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/' + 'discover-app/div/div[2]/div[2]/div/div[2]/div[2]/' + 'doc-table/div/table/tbody/tr[1]/td[2]')) + ) + logger.info('{} index loaded successfully'.format(name)) + retry = 0 + except TimeoutException, e: + logger.error('Error occured loading {} index'.format(name)) + prefix = 'Error_' + browser.save_screenshot( + artifacts + '{}Kibana_{}.png'.format(prefix, name)) + browser.quit() + retry -= 1