Skip to content

Commit d726196

Browse files
authored
shift sequence, move code into own files (#477)
* shift sequence, move code into own files * pass along RunnerProperties so we can properly name the video file * beautify name * specify video including path in docker contanier * add up selenoid options
1 parent 9dfaf51 commit d726196

File tree

11 files changed

+189
-136
lines changed

11 files changed

+189
-136
lines changed

jenkins/common/gather_coredumps.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
if [ `ls -1 "$(pwd)/test_dir/core"* 2>/dev/null | wc -l ` -gt 0 ]; then
22
7z a coredumps "$(pwd)/test_dir/core"*
3-
printf "\nCoredumps found after testrun:\n $(ls -l "$(pwd)/test_dir/core"*)\n" >> "$(pwd)/test_dir/testfailures.txt"
3+
(
4+
cat "$(pwd)/test_dir/testfailures.txt";
5+
printf "\nCoredumps found after testrun:\n $(ls -l "$(pwd)/test_dir/core"*)\n"
6+
) > "$(pwd)/test_dir/testfailures.txt"
47
rm -f "$(pwd)/test_dir/core"*
58
mv coredumps.7z "$(pwd)/test_dir/"
69
echo "FAILED BY COREDUMP FOUND!"

release_tester/arangodb/starter/deployments/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(
159159
selenium_include_suites: list,
160160
testrun_name: str,
161161
):
162+
self.properties = properties
162163
load_scenarios()
163164
assert runner_type, "no runner no cry? no!"
164165
mem = psutil.virtual_memory()
@@ -261,6 +262,7 @@ def __init__(
261262

262263
self.selenium = init_selenium(
263264
runner_type,
265+
self.properties,
264266
selenium_worker,
265267
selenium_driver_args,
266268
selenium_include_suites,
Lines changed: 17 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,69 @@
11
#!/usr/bin/env python3
22
""" baseclass to manage selenium UI tests """
33

4-
import time
5-
6-
from selenium import webdriver
7-
from selenium.common.exceptions import SessionNotCreatedException
8-
94
from arangodb.starter.deployments import RunnerType
5+
from arangodb.starter.deployments.runner import RunnerProperties
6+
107
from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner, cleanup_temp_files
118

12-
# pylint: disable=import-outside-toplevel disable=too-many-locals disable=too-many-branches disable=too-many-statements
9+
# pylint: disable=import-outside-toplevel disable=too-many-locals
10+
# pylint: disable=too-many-branches disable=too-many-statements
11+
# pylint: disable=too-many-return-statements disable=too-many-arguments
1312
def init(
1413
runner_type: RunnerType,
14+
properties: RunnerProperties,
1515
selenium_worker: str,
1616
selenium_driver_args: list,
1717
selenium_include_suites: list,
1818
testrun_name: str,
1919
ssl: bool,
2020
) -> SeleniumRunner:
2121
"""build selenium testcase for runner_type"""
22-
if "_" in selenium_worker:
23-
sw_split = selenium_worker.split("_")
24-
driver_func = getattr(webdriver, sw_split[0])
25-
selenium_worker = sw_split[1].lower()
26-
worker_options = ""
27-
else:
28-
driver_func = getattr(webdriver, selenium_worker)
29-
worker_options = selenium_worker = selenium_worker.lower() + "_"
30-
if driver_func is None:
31-
raise Exception("webdriver " + selenium_worker + "unknown")
32-
33-
kwargs = {}
34-
is_headless = False
35-
if len(selenium_driver_args) > 0:
36-
opts_func = getattr(webdriver, selenium_worker)
37-
opts_func = getattr(opts_func, "options")
38-
opts_func = getattr(opts_func, "Options")
39-
options = opts_func()
40-
kwargs[worker_options + "options"] = options
41-
for opt in selenium_driver_args:
42-
split_opts = opt.split("=")
43-
if opt == "headless":
44-
is_headless = True
45-
elif len(split_opts) == 2:
46-
if split_opts[0] == "command_executor":
47-
is_headless = True
48-
kwargs["command_executor"] = split_opts[1]
49-
continue
50-
elif len(split_opts) >= 3:
51-
key = split_opts.pop(0)
52-
where_to_put = {}
53-
while len(split_opts) > 2:
54-
if split_opts[0] not in where_to_put:
55-
where_to_put[split_opts[0]] = {}
56-
where_to_put = where_to_put[split_opts[0]]
57-
if len(split_opts) == 2:
58-
val = split_opts[1]
59-
if val == "True":
60-
val = True
61-
elif val == "False":
62-
val = False
63-
where_to_put[split_opts[0]] = val
64-
options.set_capability(key, where_to_put)
65-
split_opts = []
66-
continue
67-
options.add_argument("--" + opt)
68-
69-
cleanup_temp_files(is_headless)
70-
driver = None
71-
count = 0
72-
while driver is None and count < 10:
73-
count += 1
74-
try:
75-
driver = driver_func(**kwargs)
76-
except TypeError:
77-
try:
78-
driver = driver_func.webdriver.WebDriver(**kwargs)
79-
except SessionNotCreatedException as ex:
80-
if count == 10:
81-
raise ex
82-
print("S: retrying to launch browser")
83-
cleanup_temp_files(is_headless)
84-
time.sleep(2)
85-
except SessionNotCreatedException as ex:
86-
if count == 10:
87-
raise ex
88-
print("S: retrying to launch browser")
89-
cleanup_temp_files(is_headless)
90-
time.sleep(2)
91-
if selenium_worker.lower() == "chrome":
92-
required_width = driver.execute_script("return document.body.parentNode.scrollWidth")
93-
required_height = driver.execute_script("return document.body.parentNode.scrollHeight")
94-
driver.set_window_size(required_width, required_height)
95-
22+
selenium_args = {
23+
"selenium_worker": selenium_worker,
24+
"selenium_driver_args": selenium_driver_args,
25+
}
9626
if runner_type == RunnerType.SINGLE:
9727
from arangodb.starter.deployments.selenium_deployments.single import (
9828
Single,
9929
)
10030

101-
return Single(driver, is_headless, testrun_name, ssl, selenium_include_suites)
31+
return Single(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
10232

10333
if runner_type == RunnerType.LEADER_FOLLOWER:
10434
from arangodb.starter.deployments.selenium_deployments.leaderfollower import (
10535
LeaderFollower,
10636
)
10737

108-
return LeaderFollower(driver, is_headless, testrun_name, ssl, selenium_include_suites)
38+
return LeaderFollower(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
10939

11040
if runner_type == RunnerType.ACTIVE_FAILOVER:
11141
from arangodb.starter.deployments.selenium_deployments.activefailover import (
11242
ActiveFailover,
11343
)
11444

115-
return ActiveFailover(driver, is_headless, testrun_name, ssl, selenium_include_suites)
45+
return ActiveFailover(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
11646

11747
if runner_type == RunnerType.CLUSTER:
11848
from arangodb.starter.deployments.selenium_deployments.cluster import Cluster
11949

120-
return Cluster(driver, is_headless, testrun_name, ssl, selenium_include_suites)
50+
return Cluster(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
12151

12252
if runner_type == RunnerType.DC2DC:
12353
from arangodb.starter.deployments.selenium_deployments.dc2dc import Dc2Dc
12454

125-
return Dc2Dc(driver, is_headless, testrun_name, ssl, selenium_include_suites)
55+
return Dc2Dc(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
12656

12757
if runner_type == RunnerType.DC2DCENDURANCE:
12858
from arangodb.starter.deployments.selenium_deployments.dc2dc_endurance import (
12959
Dc2DcEndurance,
13060
)
13161

132-
return Dc2DcEndurance(driver, is_headless, testrun_name, ssl, selenium_include_suites)
62+
return Dc2DcEndurance(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
13363

13464
if runner_type == RunnerType.NONE:
13565
from arangodb.starter.deployments.selenium_deployments.none import NoStarter
13666

137-
return NoStarter(driver, is_headless, testrun_name, ssl, selenium_include_suites)
67+
return NoStarter(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
13868

13969
raise Exception("unknown starter type")

release_tester/arangodb/starter/deployments/selenium_deployments/activefailover.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
""" test the UI of a active failover setup """
3+
from arangodb.starter.deployments.runner import RunnerProperties
34
from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner
45
from selenium_ui_test.test_suites.activefailover.after_install_test_suite import ActiveFailoverAfterInstallTestSuite
56
from selenium_ui_test.test_suites.activefailover.jam_1_test_suite import ActiveFailoverJamStepOneSuite
@@ -13,9 +14,9 @@
1314
class ActiveFailover(SeleniumRunner):
1415
"""check the active failover setup and its properties"""
1516

16-
def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
17+
def __init__(self, selenium_args, properties: RunnerProperties, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
1718
# pylint: disable=useless-super-delegation
18-
super().__init__(webdriver, is_headless, testrun_name, ssl, selenium_include_suites)
19+
super().__init__(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
1920
self.main_test_suite_list = [BasicTestSuite]
2021
self.after_install_test_suite_list = [ActiveFailoverAfterInstallTestSuite]
2122
self.wait_for_upgrade_test_suite_list = [ActiveFailoverWaitForUpgradeTestSuite]

release_tester/arangodb/starter/deployments/selenium_deployments/cluster.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
""" test the UI of a cluster setup """
3+
from arangodb.starter.deployments.runner import RunnerProperties
34
from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner
45
from selenium_ui_test.test_suites.basic_test_suite import BasicTestSuite
56
from selenium_ui_test.test_suites.cluster.wait_for_upgrade_test_suite import ClusterWaitForUpgradeTestSuite
@@ -10,9 +11,9 @@
1011
class Cluster(SeleniumRunner):
1112
"""check the leader follower setup and its properties"""
1213

13-
def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
14+
def __init__(self, selenium_args, properties: RunnerProperties, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
1415
# pylint: disable=useless-super-delegation
15-
super().__init__(webdriver, is_headless, testrun_name, ssl, selenium_include_suites)
16+
super().__init__(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
1617
self.is_cluster = True
1718
self.main_test_suite_list = [BasicTestSuite]
1819
self.wait_for_upgrade_test_suite_list = [ClusterWaitForUpgradeTestSuite]

release_tester/arangodb/starter/deployments/selenium_deployments/leaderfollower.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
""" test the UI of a leader follower setup """
3+
from arangodb.starter.deployments.runner import RunnerProperties
34
from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner
45

56
from selenium_ui_test.test_suites.basic_test_suite import BasicTestSuite
@@ -10,9 +11,9 @@
1011
class LeaderFollower(SeleniumRunner):
1112
"""check the leader follower setup and its properties"""
1213

13-
def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
14+
def __init__(self, selenium_args, properties: RunnerProperties, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
1415
# pylint: disable=useless-super-delegation
15-
super().__init__(webdriver, is_headless, testrun_name, ssl, selenium_include_suites)
16+
super().__init__(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
1617
self.main_test_suite_list = [BasicTestSuite]
1718
self.after_install_test_suite_list = [LeaderFollowerAfterInstallTestSuite]
1819
self.jam_test_suite_list = [LeaderFollowerJamStepOneSuite]

release_tester/arangodb/starter/deployments/selenium_deployments/none.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env python3
22
""" test the UI of a leader follower setup """
3+
from arangodb.starter.deployments.runner import RunnerProperties
34
from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner
45

56

67
class NoStarter(SeleniumRunner):
78
"""check the leader follower setup and its properties"""
89

9-
def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
10+
def __init__(self, selenium_args, properties: RunnerProperties, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
1011
# pylint: disable=useless-super-delegation
11-
super().__init__(webdriver, is_headless, testrun_name, ssl, selenium_include_suites)
12+
super().__init__(selenium_args, properties, testrun_name, ssl, selenium_include_suites)
1213

1314
def check_old(self, cfg, leader_follower=False, expect_follower_count=2, retry_count=10):
1415
"""check the integrity of the old system before the upgrade

release_tester/arangodb/starter/deployments/selenium_deployments/sbase.py

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
""" base class for arangodb starter deployment selenium frontend tests """
33
from abc import ABC
44
import logging
5-
import os
6-
from pathlib import Path
75
import re
8-
import shutil
96
import time
107

8+
from arangodb.starter.deployments.runner import RunnerProperties
9+
from arangodb.starter.deployments.selenium_deployments.selenoid_swiper import cleanup_temp_files
10+
from arangodb.starter.deployments.selenium_deployments.selenium_session_spawner import spawn_selenium_session
1111
from allure_commons._allure import attach
1212
from allure_commons.types import AttachmentType
1313
from reporting.reporting_utils import step
@@ -17,50 +17,21 @@
1717
FNRX = re.compile("[\n@]*")
1818

1919

20-
def cleanup_temp_files(is_headless):
21-
"""attempt to cleanup the selenoid docker contaires leftovers"""
22-
if is_headless and os.getuid() == 0:
23-
tmpdir = "/tmp" # tempfile.gettempdir()
24-
trashme_rx = "(?:% s)" % f"|{tmpdir}/".join(
25-
[
26-
"pulse-*",
27-
"xvfb-run.*",
28-
".X99-lock",
29-
".X11-unix",
30-
".org.chromium.Chromium.*",
31-
".com.google.Chrome.*",
32-
".org.chromium.Chromium.*",
33-
]
34-
)
35-
print(f"cleanup headless files: {str(trashme_rx)}")
36-
for one_tmp_file in Path(tmpdir).iterdir():
37-
print(f"checking {str(one_tmp_file)}")
38-
try:
39-
if re.match(trashme_rx, str(one_tmp_file)) and one_tmp_file.group() == "root":
40-
print(f"Purging: {str(one_tmp_file)}")
41-
if one_tmp_file.is_dir():
42-
shutil.rmtree(one_tmp_file)
43-
else:
44-
one_tmp_file.unlink()
45-
except FileNotFoundError:
46-
pass
4720

4821

4922
class SeleniumRunner(ABC):
5023
"abstract base class for selenium UI testing"
5124
# pylint: disable=line-too-long disable=too-many-public-methods disable=too-many-instance-attributes disable=too-many-arguments
52-
def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, selenium_include_suites: list[str]):
25+
def __init__(self,
26+
selenium_args,
27+
properties: RunnerProperties,
28+
testrun_name: str,
29+
ssl: bool,
30+
selenium_include_suites: list[str]):
5331
"""hi"""
5432
self.ssl = ssl
55-
self.is_headless = is_headless
5633
self.testrun_name = testrun_name
57-
self.webdriver = webdriver
58-
self.supports_console_flush = self.webdriver.capabilities["browserName"] == "chrome"
59-
self.original_window_handle = None
6034
self.state = ""
61-
time.sleep(3)
62-
self.webdriver.set_window_size(1600, 900)
63-
time.sleep(3)
6435
self.importer = None
6536
self.restorer = None
6637
self.ui_entrypoint_instance = None
@@ -73,6 +44,19 @@ def __init__(self, webdriver, is_headless: bool, testrun_name: str, ssl: bool, s
7344
self.jam_step_2_test_suite_list = []
7445
self.wait_for_upgrade_test_suite_list = []
7546
self.selenium_include_suites = selenium_include_suites
47+
mylist = list(
48+
selenium_args['selenium_driver_args'])
49+
mylist.append(
50+
f"selenoid:options=videoName={properties.short_name}_{testrun_name}.mp4".replace(
51+
'\n', '_').replace('@', '_')
52+
)
53+
selenium_args['selenium_driver_args'] = mylist
54+
(self.is_headless, self.webdriver) = spawn_selenium_session(**selenium_args)
55+
self.supports_console_flush = self.webdriver.capabilities["browserName"] == "chrome"
56+
self.original_window_handle = None
57+
time.sleep(3)
58+
self.webdriver.set_window_size(1600, 900)
59+
time.sleep(3)
7660

7761
def _cleanup_temp_files(self):
7862
cleanup_temp_files(self.is_headless)

0 commit comments

Comments
 (0)