Skip to content

Commit 19b864e

Browse files
committed
robotest own container
1 parent 2e9ed10 commit 19b864e

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

wodoo/lib_composer.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from .tools import update_docker_service
4646
from .tools import autocleanpaper
4747
from .tools import sync_folder
48+
from .tools import _yamldump
4849

4950
import inspect
5051
import os
@@ -852,19 +853,6 @@ def post_process_complete_yaml_config(config, yml):
852853
return yml
853854

854855

855-
def _yamldump(content):
856-
import yaml
857-
858-
class NoAliasDumper(yaml.SafeDumper):
859-
def ignore_aliases(self, data):
860-
return True
861-
862-
file_content = yaml.dump(
863-
content, default_flow_style=False, sort_keys=False
864-
) # , Dumper=NoAliasDumper)
865-
return file_content
866-
867-
868856
def __run_docker_compose_config(config, contents, env):
869857
import yaml
870858

@@ -1287,7 +1275,6 @@ def _merge_odoo_dockerfile(config):
12871275
if not dockerfile:
12881276
continue
12891277
if "odoo/images/odoo" in dockerfile:
1290-
Path(config.files["odoo_docker_file"]).parent.mkdir(exist_ok=True, parents=True)
12911278
shutil.copy(dockerfile, config.files["odoo_docker_file"])
12921279
dockerfile1 = dockerfile
12931280
service["build"]["dockerfile"] = str(
@@ -1302,7 +1289,6 @@ def _merge_odoo_dockerfile(config):
13021289
click.secho(
13031290
f"Copying {dockerfile1} to {config.files['odoo_docker_file']}"
13041291
)
1305-
config.files["odoo_docker_file"].parent.mkdir(exist_ok=True, parents=True)
13061292
config.files["odoo_docker_file"].write_text(
13071293
Path(dockerfile1).read_text()
13081294
)

wodoo/lib_robot.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
from copy import deepcopy
23
import random
34
import time
45
import sys
@@ -18,6 +19,7 @@
1819
from .tools import abort
1920
from .tools import __assure_gitignore
2021
from .tools import _get_available_robottests
22+
from .tools import _yamldump
2123
from pathlib import Path
2224

2325
ROBOT_UTILS_GIT = "marcwimmer/odoo-robot_utils"
@@ -428,6 +430,10 @@ def params():
428430

429431
return params
430432

433+
unique_robotname = f"robot_{uuid.uuid4()}"
434+
# copy robot and seleniumdriver template to have an instance
435+
selenium_service_name = _clone_seleniumdriver_template(ctx, config, unique_robotname)
436+
431437
token = arrow.get().strftime("%Y-%m-%d_%H%M%S_") + str(uuid.uuid4())
432438
data = json.dumps(
433439
{
@@ -436,6 +442,7 @@ def params():
436442
"results_file": results_file or "",
437443
"debug": debug,
438444
"params": params(),
445+
"SELENIUM_SERVICE_NAME": selenium_service_name,
439446
}
440447
)
441448
data = base64.b64encode(data.encode("utf-8")).decode("utf8")
@@ -458,14 +465,22 @@ def params():
458465
env=os.environ,
459466
)
460467
else:
461-
__dcrun(config, params, pass_stdin=data, interactive=True)
468+
try:
469+
Commands.invoke(ctx, "up", daemon=True, machines=[selenium_service_name])
470+
__dcrun(config, params, pass_stdin=data, interactive=True)
471+
finally:
472+
# ensure that the seleniumdriver is stopped
473+
Commands.invoke(ctx, "kill", machines=[selenium_service_name])
474+
Commands.invoke(ctx, "remove", machines=[selenium_service_name])
475+
click.secho(
476+
f"Stopped seleniumdriver {selenium_service_name} container",
477+
fg="yellow",
478+
)
462479
del data
463480

464481
output_path = config.HOST_RUN_DIR / "odoo_outdir" / "robot_output"
465482
from .robo_helpers import _eval_robot_output
466483

467-
Commands.invoke(ctx, "restart", machines=["seleniumdriver"])
468-
469484
res = _eval_robot_output(
470485
config,
471486
output_path,
@@ -477,6 +492,16 @@ def params():
477492
)
478493
return res
479494

495+
def _clone_seleniumdriver_template(ctx, config, appendix):
496+
import yaml
497+
yml = yaml.safe_load(open(config.files['docker_compose'], "r"))
498+
499+
service_name = f"seleniumdriver_{appendix}"
500+
yml['services'][service_name] = deepcopy(yml['services']['seleniumdriver_template'])
501+
yml['services'][service_name]['container_name'] = service_name
502+
config.files['docker_compose'].write_text(_yamldump(yml))
503+
return service_name
504+
480505

481506
def _prepare_fresh_robotest(ctx):
482507
click.secho("Preparing fresh robo test.", fg="yellow")

wodoo/tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,3 +2057,16 @@ def choose_ip(ips):
20572057

20582058
def get_arch():
20592059
return platform.uname().machine # aarch64
2060+
2061+
def _yamldump(content):
2062+
import yaml
2063+
2064+
class NoAliasDumper(yaml.SafeDumper):
2065+
def ignore_aliases(self, data):
2066+
return True
2067+
2068+
file_content = yaml.dump(
2069+
content, default_flow_style=False, sort_keys=False
2070+
) # , Dumper=NoAliasDumper)
2071+
return file_content
2072+

0 commit comments

Comments
 (0)