Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Jun 21, 2024
1 parent d318d9b commit 5ac73f8
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 1 deletion.
1 change: 0 additions & 1 deletion pulp_container/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,4 @@ def filter(remote, element_list, tags=False):
if any(fnmatch.fnmatch(item, pattern) for pattern in include)
]


return element_list
140 changes: 140 additions & 0 deletions pulp_container/tests/functional/api/test_remote_filter2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import fnmatch
import time
import subprocess
import pytest
import re

from uuid import uuid4

from pulp_container.app.exceptions import InvalidRequest
from pulp_container.tests.functional.constants import (
REGISTRY_V2,
REGISTRY_V2_FEED_URL,
PULP_HELLO_WORLD_REPO,
PULP_FIXTURE_1,
)

# try:
# import debugpy
# debugpy.listen(('0.0.0.0',5678))
# debugpy.wait_for_client()
# except:
# pass


@pytest.fixture
def pull_through_distribution(
gen_object_with_cleanup,
container_pull_through_remote_api,
container_pull_through_distribution_api,
):
def _pull_through_distribution(includes, excludes):
remote = gen_object_with_cleanup(
container_pull_through_remote_api,
{
"name": str(uuid4()),
"url": REGISTRY_V2_FEED_URL,
"includes": includes,
"excludes": excludes,
},
)
distribution = gen_object_with_cleanup(
container_pull_through_distribution_api,
{"name": str(uuid4()), "base_path": str(uuid4()), "remote": remote.pulp_href},
)
return distribution

return _pull_through_distribution


@pytest.fixture
def pull_and_verify(
add_to_cleanup,
capfd,
container_pull_through_distribution_api,
container_distribution_api,
container_repository_api,
container_remote_api,
container_tag_api,
registry_client,
local_registry,
):
def _pull_and_verify(images, pull_through_distribution, includes, excludes):
tags_to_verify = []
distr = pull_through_distribution(includes, excludes)
for _, image_path in enumerate(images, start=1):
local_image_path = f"{distr.base_path}/{image_path}"

# 1. pull remote content through the pull-through distribution
if any(re.match(".*pulp.*", pattern) for pattern in excludes):
with pytest.raises(subprocess.CalledProcessError) as e:
local_registry.pull(local_image_path)
assert (
re.search(
".*No repository found for the defined remote filters.*",
capfd.readouterr().err,
)
is not None
)
continue
local_registry.pull(local_image_path)

# when the client pulls the image, a repository, distribution, and remote is created in
# the background; therefore, scheduling the cleanup for these entities is necessary
path, tag = local_image_path.split(":")
tags_to_verify.append(tag)
repository = container_repository_api.list(name=path).results[0]
add_to_cleanup(container_repository_api, repository.pulp_href)
remote = container_remote_api.list(name=path).results[0]
add_to_cleanup(container_remote_api, remote.pulp_href)
distribution = container_distribution_api.list(name=path).results[0]
add_to_cleanup(container_distribution_api, distribution.pulp_href)

pull_through_distribution = container_pull_through_distribution_api.list(
name=distr.name
).results[0]

assert [distribution.pulp_href] == pull_through_distribution.distributions

return _pull_and_verify


@pytest.mark.skip()
def test_manifest_list_pull(delete_orphans_pre, pull_through_distribution, pull_and_verify):
images = [f"{PULP_HELLO_WORLD_REPO}:latest", f"{PULP_HELLO_WORLD_REPO}:linux"]
includes = []
excludes = []
pull_and_verify(images, pull_through_distribution, includes, excludes)
excludes = []
pull_and_verify(images, pull_through_distribution, includes, excludes)


@pytest.mark.skip()
def test_no_filter(delete_orphans_pre, pull_through_distribution, pull_and_verify):
images = [f"{PULP_FIXTURE_1}:manifest_a", f"{PULP_FIXTURE_1}:manifest_b"]
includes = []
excludes = []
pull_and_verify(images, pull_through_distribution, includes, excludes)


@pytest.mark.skip()
def test_filter_exclude_with_regex(delete_orphans_pre, pull_through_distribution, pull_and_verify):
images = [f"{PULP_FIXTURE_1}:manifest_a", f"{PULP_FIXTURE_1}:manifest_b"]
includes = []
excludes = ["pulp*"]
pull_and_verify(images, pull_through_distribution, includes, excludes)


@pytest.mark.skip()
def test_filter_exclude(delete_orphans_pre, pull_through_distribution, pull_and_verify):
images = [f"{PULP_FIXTURE_1}:manifest_a", f"{PULP_FIXTURE_1}:manifest_b"]
includes = []
excludes = ["pulp/test-fixture-1"]
pull_and_verify(images, pull_through_distribution, includes, excludes)


def test_filter_include_and_exclude(delete_orphans_pre, pull_through_distribution, pull_and_verify):
images = [f"{PULP_FIXTURE_1}:manifest_a", f"{PULP_FIXTURE_1}:manifest_b"]
includes = ["pulp*"]
excludes = ["pulp/test-fixture-1"]
pull_and_verify(images, pull_through_distribution, includes, excludes)
72 changes: 72 additions & 0 deletions pulp_container/tests/functional/api/test_remote_filter3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import pytest
import re

from pulpcore.client.pulp_container import ContainerRepositorySyncURL
from pulpcore.tests.functional import PulpTaskError
from pulp_container.tests.functional.constants import (
REGISTRY_V2_FEED_URL,
PULP_HELLO_WORLD_REPO,
)


@pytest.fixture
def pull_and_verify(
add_to_cleanup,
capsys,
container_repository_api,
container_remote_api,
container_tag_api,
delete_orphans_pre,
monitor_task,
):
def _pull_and_verify(excludes, includes):
repository = container_repository_api.create({"name": "foo"})
add_to_cleanup(container_repository_api, repository.pulp_href)
remote = container_remote_api.create(
{
"name": "foo",
"url": REGISTRY_V2_FEED_URL,
"upstream_name": PULP_HELLO_WORLD_REPO,
"excludes": excludes,
"includes": includes,
}
)
add_to_cleanup(container_remote_api, remote.pulp_href)
sync_data = ContainerRepositorySyncURL(remote=remote.pulp_href)
sync_response = container_repository_api.sync(repository.pulp_href, sync_data)
if any(re.match(".*pulp.*", pattern) for pattern in excludes):
with pytest.raises(PulpTaskError) as e:
monitor_task(sync_response.task)
if (
re.search(
".*No repository found for the defined remote filters.*",
str(e.value),
)
is not None
):
return 0
monitor_task(sync_response.task)
tags = container_tag_api.list().results
return len(tags)

return _pull_and_verify


def test_filter_with_regex(pull_and_verify):
test = pull_and_verify(includes=[], excludes={"*pulp*": ""})
assert test == 0


def test_filter(pull_and_verify):
test = pull_and_verify(includes=[], excludes={"pulp/hello-world": ""})
assert test == 0


def test_filter_multiple_excludes(pull_and_verify):
test = pull_and_verify(includes=[], excludes={"pulp": "", "*hello*": ""})
assert test == 0


def test_empty_filters(pull_and_verify):
test = pull_and_verify(includes=[], excludes=[])
assert test == 2

0 comments on commit 5ac73f8

Please sign in to comment.