Skip to content

Commit

Permalink
fix(SPSTRAT-464): Update staged regex & add arg
Browse files Browse the repository at this point in the history
This commit fix an issue with the staged dir regex as the starmap
dir should be a child of the staged dir, and it's not part of its base
directory. The validation whether the base staged dir contains or not a
directory named `starmap` will be done in the task.

It also adds the missing argument `--offline` which prevents the
`pubtools-marketplacesvm` to invoke the StArMap server when
`--repo-file` is set and a mapping is not found

Signed-off-by: Jonathan Gangi <[email protected]>
  • Loading branch information
JAVGan committed Nov 28, 2024
1 parent b57665f commit bdb3b59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def parse_args():

def get_source_url(stagedirs):
for item in stagedirs:
if not re.match(r"^/[^,]{0,4000}\/*starmap\/*$", item):
if not re.match(r"^/(\w++\/*)+$", item):
raise ValueError("Not a valid staging directory: %s" % item)

return f"staged:{','.join(stagedirs)}"
Expand All @@ -82,7 +82,7 @@ def settings_to_args(parsed):
"starmap_file": "--repo-file",
"source": "",
}
out = []
out = ["--offline"] # The "offline" arg is used to prevent invoking a StArMap server
if parsed.nochannel:
out.append("--pre-push")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_dry_run(caplog, mock_mkt_env_vars):
assert "This is a dry-run!" in caplog.messages
assert (
"Would have run: pubtools-marketplacesvm-marketplace-push "
"--repo-file mapping.yaml "
"--offline --repo-file mapping.yaml "
"staged:/test1/starmap,/test2/starmap"
) in caplog.messages

Expand All @@ -68,13 +68,14 @@ def test_basic_command(mock_run, caplog, mock_mkt_env_vars):
assert "This is a dry-run!" not in caplog.messages
assert (
"Running pubtools-marketplacesvm-marketplace-push "
"--repo-file mapping.yaml "
"--offline --repo-file mapping.yaml "
"staged:/test1/starmap,/test2/starmap"
) in caplog.messages

mock_run.assert_called_once_with(
[
"pubtools-marketplacesvm-marketplace-push",
"--offline",
"--repo-file",
"mapping.yaml",
"staged:/test1/starmap,/test2/starmap",
Expand Down Expand Up @@ -102,13 +103,14 @@ def test_basic_command_nochannel(mock_run, caplog, mock_mkt_env_vars):
assert "This is a dry-run!" not in caplog.messages
assert (
"Running pubtools-marketplacesvm-marketplace-push "
"--pre-push --repo-file mapping.yaml "
"--offline --pre-push --repo-file mapping.yaml "
"staged:/test1/starmap,/test2/starmap"
) in caplog.messages

mock_run.assert_called_once_with(
[
"pubtools-marketplacesvm-marketplace-push",
"--offline",
"--pre-push",
"--repo-file",
"mapping.yaml",
Expand All @@ -121,9 +123,9 @@ def test_basic_command_nochannel(mock_run, caplog, mock_mkt_env_vars):
@pytest.mark.parametrize(
"stageddirs",
[
["/foo/bar/starmap"],
["/starmap/", "/tmp/starmap/"],
["/a/b/c/d/e/f/g/h/i/starmap", "/a1/a2/a3/starmap/", "/starmap"],
["/foo/bar/"],
["/a", "/tmp/foo/"],
["/a/b/c/d/e/f/g/h/i", "/a1/a2/a3/", "/f"],
],
)
def test_get_source_url(stageddirs):
Expand All @@ -134,12 +136,7 @@ def test_get_source_url(stageddirs):

@pytest.mark.parametrize(
"stageddirs",
[
["/"],
["/foo/bar"],
["/some/staged/dir"],
["/starmap/another_dir"],
],
[["foo"], ["foo/bar"], ["//////////"], [r"/\/\/\/\/\/\/"]],
)
def test_get_source_url_invalid(stageddirs):
err = "Not a valid staging directory:"
Expand Down

0 comments on commit bdb3b59

Please sign in to comment.