Skip to content

Commit 6aa7ae5

Browse files
committed
Add ability to run tests in parallel [PULP-753]
1 parent b7327cf commit 6aa7ae5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+399
-411
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ jobs:
115115
PULP_ENABLED_PLUGINS: "${{ matrix.pulp_enabled_plugins }}"
116116
OAS_VERSION: "${{ matrix.oas_version }}"
117117
run: |
118-
.ci/run_container.sh make livetest
118+
.ci/run_container.sh make paralleltest
119119
...

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ test: | tests/cli.toml
4141
livetest: | tests/cli.toml
4242
python3 -m pytest -v tests pulp-glue/tests -m live
4343

44+
paralleltest: | tests/cli.toml
45+
python3 -m pytest -v tests pulp-glue/tests -m live -n 8
46+
4447
unittest:
4548
python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py -m "not live"
4649

cookiecutter/ci/{{ cookiecutter.__project_name }}/.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ jobs:
8787
OAS_VERSION: "${{ matrix.oas_version }}"
8888
{%- endraw %}
8989
run: |
90-
.ci/run_container.sh make {% if cookiecutter.unittests %}live{% endif %}test
90+
.ci/run_container.sh make {% if cookiecutter.unittests %}parallel{% endif %}test
9191
...

cookiecutter/ci/{{ cookiecutter.__project_name }}/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ test: | tests/cli.toml
6060
livetest: | tests/cli.toml
6161
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %} -m live
6262

63+
paralleltest: | tests/cli.toml
64+
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %} -m live -n 8
65+
6366
unittest:
6467
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %}
6568
{%- if cookiecutter.__app_label_suffix == "" %} cookiecutter/pulp_filter_extension.py {%- endif %} -m "not live"

pulpcore/cli/container/distribution.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pulp_glue.common.context import (
55
EntityDefinition,
66
EntityFieldDefinition,
7+
PluginRequirement,
78
PulpEntityContext,
89
PulpRepositoryContext,
910
)
@@ -114,6 +115,10 @@ def update(
114115

115116
distribution: EntityDefinition = distribution_ctx.entity
116117
body: EntityDefinition = {}
118+
non_blocking = not (
119+
base_path is not None
120+
or distribution_ctx.pulp_ctx.has_plugin(PluginRequirement("core", specifier="<3.24.0"))
121+
)
117122

118123
if private is not None:
119124
body["private"] = private
@@ -134,16 +139,18 @@ def update(
134139
repository = t.cast(PulpEntityContext, repository)
135140
if version is not None:
136141
if distribution["repository"]:
137-
distribution_ctx.update(body={"repository": ""}, non_blocking=True)
142+
distribution_ctx.update(body={"repository": ""}, non_blocking=non_blocking)
138143
body["repository_version"] = f"{repository.pulp_href}versions/{version}/"
139144
else:
140145
if distribution["repository_version"]:
141-
distribution_ctx.update(body={"repository_version": ""}, non_blocking=True)
146+
distribution_ctx.update(
147+
body={"repository_version": ""}, non_blocking=non_blocking
148+
)
142149
body["repository"] = repository.pulp_href
143150
elif version is not None:
144151
# keep current repository, change version
145152
if distribution["repository"]:
146-
distribution_ctx.update(body={"repository": ""}, non_blocking=True)
153+
distribution_ctx.update(body={"repository": ""}, non_blocking=non_blocking)
147154
body["repository_version"] = f'{distribution["repository"]}versions/{version}/'
148155
elif distribution["repository_version"]:
149156
# 'dummy' vars are to get us around a mypy/1.2 complaint about '_'

pulpcore/cli/core/task.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def cancel(
153153
states.append("running")
154154
if states:
155155
tasks = task_ctx.list(limit=1 << 64, offset=0, parameters={"state__in": states})
156+
if pulp_ctx.api._dry_run:
157+
raise click.ClickException(
158+
_("Trying to cancel {} tasks in safe-mode, aborting").format(len(tasks))
159+
)
156160
for task in tasks:
157161
task_ctx.cancel(task["pulp_href"], background=True)
158162
for task in tasks:

test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Test requirements
22
pytest>=7.0.0,<8.5
3+
pytest-xdist
34
pytest-subtests>=0.12.0,<0.15
45
python-gnupg>=0.5.0,<0.6
56
trustme>=1.1.0,<1.3

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def pulp_cli_vars(pulp_cli_vars: t.Dict[str, str]) -> t.Dict[str, str]:
1414
result.update(
1515
{
1616
"FILE_REMOTE_URL": urljoin(PULP_FIXTURES_URL, "/file/PULP_MANIFEST"),
17+
"FILE_REMOTE2_URL": urljoin(PULP_FIXTURES_URL, "/file2/PULP_MANIFEST"),
1718
"FILE_LARGE_REMOTE_URL": urljoin(PULP_FIXTURES_URL, "/file-perf/PULP_MANIFEST"),
1819
"CONTAINER_REMOTE_URL": "https://quay.io",
1920
"CONTAINER_IMAGE": "libpod/alpine",

tests/scripts/pulp_ansible/test_content.sh

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,34 @@ set -eu
77
pulp debug has-plugin --name "ansible" || exit 23
88

99
cleanup() {
10-
pulp ansible repository destroy --name "cli_test_ansible_repository" || true
11-
pulp ansible repository destroy --name "cli_test_ansible_repository_verify" || true
12-
pulp ansible repository destroy --name "cli_test_ansible_repository_upload" || true
10+
pulp ansible repository destroy --name "cli_test_ansible_content_repository" || true
11+
pulp ansible repository destroy --name "cli_test_ansible_content_repository_verify" || true
12+
pulp ansible repository destroy --name "cli_test_ansible_content_repository_upload" || true
1313
}
1414
trap cleanup EXIT
1515

16-
pulp orphan cleanup --protection-time 0
1716

1817
if pulp debug has-plugin --name "ansible" --specifier ">=0.15.0"
1918
then
2019
gpg --output pulp_pubkey.key --armor --export "pulp-fixture-signing-key"
21-
expect_succ pulp ansible repository create --name "cli_test_ansible_repository_verify" --gpgkey @pulp_pubkey.key
20+
expect_succ pulp ansible repository create --name "cli_test_ansible_content_repository_verify" --gpgkey @pulp_pubkey.key
2221
else
23-
expect_succ pulp ansible repository create --name "cli_test_ansible_repository_verify"
22+
expect_succ pulp ansible repository create --name "cli_test_ansible_content_repository_verify"
2423
fi
2524

2625
# Test ansible collection-version upload
2726
wget "https://galaxy.ansible.com/download/ansible-posix-1.3.0.tar.gz"
2827
sha256=$(sha256sum ansible-posix-1.3.0.tar.gz | cut -d' ' -f1)
2928

30-
expect_succ pulp ansible repository create --name "cli_test_ansible_repository_upload"
31-
expect_succ pulp ansible content upload --file "ansible-posix-1.3.0.tar.gz" --repository "cli_test_ansible_repository_upload"
29+
expect_succ pulp ansible repository create --name "cli_test_ansible_content_repository_upload"
30+
expect_succ pulp ansible content upload --file "ansible-posix-1.3.0.tar.gz" --repository "cli_test_ansible_content_repository_upload"
3231
expect_succ pulp artifact list --sha256 "$sha256"
3332
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
3433
expect_succ pulp ansible content list --name "posix" --namespace "ansible" --version "1.3.0"
3534
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
3635
content_href="$(echo "$OUTPUT" | jq -r .[0].pulp_href)"
3736
expect_succ pulp ansible content show --href "$content_href"
38-
expect_succ pulp ansible repository content list --repository "cli_test_ansible_repository_upload" --version 1
37+
expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository_upload" --version 1
3938
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
4039

4140
# Test ansible role upload
@@ -57,29 +56,29 @@ then
5756
tar --extract --file="ansible-posix-1.3.0.tar.gz" "MANIFEST.json"
5857
collection_path="$(realpath 'MANIFEST.json')"
5958
signature_path="$("$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")"/assets/sign_detached.sh "$collection_path" | jq -r .signature)"
60-
expect_succ pulp ansible content --type "signature" upload --file "$signature_path" --collection "$content_href" --repository "cli_test_ansible_repository_verify"
59+
expect_succ pulp ansible content --type "signature" upload --file "$signature_path" --collection "$content_href" --repository "cli_test_ansible_content_repository_verify"
6160
expect_succ pulp ansible content --type "signature" list --collection "$content_href" --pubkey-fingerprint "0C1A894EBB86AFAE218424CADDEF3019C2D4A8CF"
6261
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
6362
content3_href="$(echo "$OUTPUT" | jq -r .[0].pulp_href)"
6463
expect_succ pulp ansible content --type "signature" show --href "$content3_href"
6564
fi
6665

6766
# New content commands
68-
expect_succ pulp ansible repository create --name "cli_test_ansible_repository"
69-
expect_succ pulp ansible repository content add --repository "cli_test_ansible_repository" --name "posix" --namespace "ansible" --version "1.3.0"
70-
expect_succ pulp ansible repository content list --repository "cli_test_ansible_repository" --version 1
67+
expect_succ pulp ansible repository create --name "cli_test_ansible_content_repository"
68+
expect_succ pulp ansible repository content add --repository "cli_test_ansible_content_repository" --name "posix" --namespace "ansible" --version "1.3.0"
69+
expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository" --version 1
7170
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
72-
expect_succ pulp ansible repository content --type "role" add --repository "cli_test_ansible_repository" --name "kubernetes-modules" --namespace "ansible" --version "0.0.1"
73-
expect_succ pulp ansible repository content --type "role" list --repository "cli_test_ansible_repository" --version 2
71+
expect_succ pulp ansible repository content --type "role" add --repository "cli_test_ansible_content_repository" --name "kubernetes-modules" --namespace "ansible" --version "0.0.1"
72+
expect_succ pulp ansible repository content --type "role" list --repository "cli_test_ansible_content_repository" --version 2
7473
test "$(echo "$OUTPUT" | jq -r length)" -eq "1"
7574

7675
if pulp debug has-plugin --name "core" --specifier ">=3.11.0"
7776
then
78-
expect_succ pulp ansible repository content list --repository "cli_test_ansible_repository" --version 2 --all-types
77+
expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository" --version 2 --all-types
7978
test "$(echo "$OUTPUT" | jq -r length)" -eq "2"
8079
fi
8180

82-
expect_succ pulp ansible repository content remove --repository "cli_test_ansible_repository" --href "$content_href"
83-
expect_succ pulp ansible repository content remove --repository "cli_test_ansible_repository" --href "$content2_href"
84-
expect_succ pulp ansible repository content list --repository "cli_test_ansible_repository"
81+
expect_succ pulp ansible repository content remove --repository "cli_test_ansible_content_repository" --href "$content_href"
82+
expect_succ pulp ansible repository content remove --repository "cli_test_ansible_content_repository" --href "$content2_href"
83+
expect_succ pulp ansible repository content list --repository "cli_test_ansible_content_repository"
8584
test "$(echo "$OUTPUT" | jq -r length)" -eq "0"

tests/scripts/pulp_ansible/test_distribution.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ set -eu
77
pulp debug has-plugin --name "ansible" || exit 23
88

99
cleanup() {
10-
pulp ansible repository destroy --name "cli_test_ansible_repository" || true
10+
pulp ansible repository destroy --name "cli_test_ansible_distribution_repository" || true
1111
pulp ansible distribution destroy --name "cli_test_ansible_distro" || true
1212
pulp ansible distribution destroy --name "cli_test_ansible_ver_distro" || true
1313
}
1414
trap cleanup EXIT
1515

16-
expect_succ pulp ansible repository create --name "cli_test_ansible_repository"
16+
expect_succ pulp ansible repository create --name "cli_test_ansible_distribution_repository"
1717

1818
expect_succ pulp ansible distribution create --name "cli_test_ansible_distro" \
1919
--base-path "cli_test_ansible_distro" \
20-
--repository "cli_test_ansible_repository"
20+
--repository "cli_test_ansible_distribution_repository"
2121

2222
expect_succ pulp ansible distribution create --name "cli_test_ansible_ver_distro" \
2323
--base-path "cli_test_ansible_ver_distro" \
24-
--repository "cli_test_ansible_repository" \
24+
--repository "cli_test_ansible_distribution_repository" \
2525
--version "0"
2626

2727
expect_succ pulp ansible distribution list

0 commit comments

Comments
 (0)