Skip to content

Commit d77676d

Browse files
authored
Merge pull request #11 from larsks/fix/patch-rsync-script
Avoid comparing embedded script in unit tests
2 parents e625dbf + 714758c commit d77676d

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

build_yaml.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# pyright: reportExplicitAny=false
22
from typing import Any
33

4+
rsync_script = """
5+
set -e
6+
export RSYNC_RSH='oc rsh -c {devcontainer}'
7+
8+
mkdir -p {job_name}
9+
10+
rsync -q --archive --no-owner --no-group --omit-dir-times \
11+
--numeric-ids {devpod_name}:{getlist_path} {job_name}/getlist
12+
rsync -q -r --archive --no-owner --no-group \
13+
--omit-dir-times --numeric-ids --files-from={job_name}/getlist \
14+
{devpod_name}:{context_dir}/ {job_name}/
15+
find {job_name} -mindepth 1 -maxdepth 1 > {job_name}/gotlist
16+
17+
(
18+
cd {job_name} && {cmdline} |& tee {job_name}.log
19+
)
20+
21+
rsync -q --archive --no-owner --no-group \
22+
--omit-dir-times --no-relative --numeric-ids \
23+
--exclude-from={job_name}/gotlist \
24+
{job_name} {devpod_name}:{jobs_dir}
25+
"""
26+
427

528
def build_job_body(
629
job_name: str,
@@ -39,30 +62,7 @@ def build_job_body(
3962
command = [
4063
"/bin/bash",
4164
"-c",
42-
(
43-
f"""
44-
set -e
45-
export RSYNC_RSH='oc rsh -c {devcontainer}'
46-
47-
mkdir -p {job_name}
48-
49-
rsync -q --archive --no-owner --no-group --omit-dir-times \
50-
--numeric-ids {devpod_name}:{getlist_path} {job_name}/getlist
51-
rsync -q -r --archive --no-owner --no-group \
52-
--omit-dir-times --numeric-ids --files-from={job_name}/getlist \
53-
{devpod_name}:{context_dir}/ {job_name}/
54-
find {job_name} -mindepth 1 -maxdepth 1 > {job_name}/gotlist
55-
56-
(
57-
cd {job_name} && {cmdline} |& tee {job_name}.log
58-
)
59-
60-
rsync -q --archive --no-owner --no-group \
61-
--omit-dir-times --no-relative --numeric-ids \
62-
--exclude-from={job_name}/gotlist \
63-
{job_name} {devpod_name}:{jobs_dir}
64-
"""
65-
),
65+
rsync_script.format_map(locals()),
6666
]
6767
else:
6868
command = ["/bin/bash", "-c", cmdline]

tests/test_br.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
import argparse
66

7+
import build_yaml
78
from br import CreateJobCommand
89
from tests.helpers import DictToObject
910

@@ -78,12 +79,12 @@ def test_create_job_nowait(
7879
"containers": [
7980
{
8081
"name": "job-v100-123-container",
81-
"image": "image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/csw-run-f25:latest",
8282
"command": [
8383
"/bin/bash",
8484
"-c",
85-
f"\nset -e\nexport RSYNC_RSH='oc rsh -c container1'\n\nmkdir -p job-v100-123\n\nrsync -q --archive --no-owner --no-group --omit-dir-times --numeric-ids testhost:{tempdir}/jobs/job-v100-123/getlist job-v100-123/getlist\nrsync -q -r --archive --no-owner --no-group --omit-dir-times --numeric-ids --files-from=job-v100-123/getlist testhost:{tempdir}/ job-v100-123/\nfind job-v100-123 -mindepth 1 -maxdepth 1 > job-v100-123/gotlist\n\n(\n cd job-v100-123 && |& tee job-v100-123.log\n)\n\nrsync -q --archive --no-owner --no-group --omit-dir-times --no-relative --numeric-ids --exclude-from=job-v100-123/gotlist job-v100-123 testhost:{tempdir}/jobs\n",
86-
],
85+
f"testcommand {' '.join(args.command).strip()}",
86+
],
87+
"image": "image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/csw-run-f25:latest",
8788
"resources": {
8889
"requests": {"nvidia.com/gpu": "1"},
8990
"limits": {"nvidia.com/gpu": "1"},
@@ -95,6 +96,7 @@ def test_create_job_nowait(
9596
},
9697
}
9798

99+
build_yaml.rsync_script = "testcommand {cmdline}"
98100
CreateJobCommand.run(args)
99101

100102
assert mock_create.call_args.args[0] == expected

0 commit comments

Comments
 (0)