Skip to content

Commit 87f2367

Browse files
committed
Review fixes #1
Changes: * Client.create_repository() now returns fully usable repository that was created with client attached * Also the create_repository() checks the created repository and reports if there is some discrepancy between requested repo and created/existing repo * IsoImporter -> FileImporter * fixed and updated tests * added `"importers": True` to search options for repos * fixed converter of `notes.signatures` on `Repository` - empty string is now converted to empty list, not to list with empty string ...this commit will be squashed
1 parent 4125b70 commit 87f2367

File tree

11 files changed

+183
-46
lines changed

11 files changed

+183
-46
lines changed

docs/api/files.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Repository
1414
.. autoclass:: pubtools.pulplib.FileSyncOptions()
1515
:members:
1616

17-
.. autoclass:: pubtools.pulplib.IsoImporter()
17+
.. autoclass:: pubtools.pulplib.FileImporter()
1818
:members:
1919

2020
Units

pubtools/pulplib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
MaintenanceEntry,
3434
Importer,
3535
YumImporter,
36-
IsoImporter,
36+
FileImporter,
3737
)
3838
from ._impl.fake import FakeController

pubtools/pulplib/_impl/client/client.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def search_repository(self, criteria=None):
278278
Each page will contain a collection of
279279
:class:`~pubtools.pulplib.Repository` objects.
280280
"""
281-
search_options = {"distributors": True}
281+
search_options = {"distributors": True, "importers": True}
282282
return self._search(
283283
Repository, "repositories", criteria=criteria, search_options=search_options
284284
)
@@ -1058,15 +1058,18 @@ def _do_sync(self, repo_id, sync_options):
10581058
def create_repository(self, repo):
10591059
"""Create a repository with initial data provided in the
10601060
argument. Importer for repository is automatically associated
1061-
if available. If repository already exists, only warning is logged.
1061+
if available. If repository already exists, warning is logged.
1062+
After repository has been successfully created or if repository already exists,
1063+
it is checked if expected and current repository configuration values are
1064+
correct.
10621065
10631066
Args:
10641067
repo (:class:`~pubtools.pulplib.Repository`)
10651068
A repository object used for creation.
10661069
10671070
Returns:
1068-
Future
1069-
A future which is resolved with a value of ``None`` once the
1071+
Future[Repository]
1072+
A future which is resolved with a value of ``Repository`` once the
10701073
repository has been created.
10711074
10721075
.. versionadded:: 2.39.0
@@ -1090,10 +1093,41 @@ def log_existing_repo(exception):
10901093

10911094
raise exception
10921095

1096+
def get_and_check_repo(_):
1097+
repo_on_server = self.get_repository(repo_id)
1098+
try:
1099+
assert (
1100+
repo_on_server.result() == repo
1101+
), "Repo exists on server with unexpected values"
1102+
except AssertionError:
1103+
if importer:
1104+
for attr in ["type_id", "config"]:
1105+
expected = getattr(repo.importer, attr)
1106+
current = getattr(repo_on_server.importer, attr)
1107+
if expected != current:
1108+
LOG.error(
1109+
"Repository %s contains wrong importer %s\n"
1110+
"\t expected: %s\n"
1111+
"\t current: %s\n",
1112+
repo_id,
1113+
attr,
1114+
expected,
1115+
current,
1116+
)
1117+
LOG.exception(
1118+
"Repository %s exists on server and contains unexpected values",
1119+
repo_id,
1120+
)
1121+
raise
1122+
1123+
return repo_on_server
1124+
10931125
LOG.debug("Creating repository %s", repo_id)
10941126
out = self._request_executor.submit(
10951127
self._do_request, method="POST", url=url, json=body
10961128
)
10971129

10981130
out = f_map(out, error_fn=log_existing_repo)
1099-
return f_map(out, lambda _: None)
1131+
out = f_flat_map(out, get_and_check_repo)
1132+
1133+
return f_proxy(out)

pubtools/pulplib/_impl/fake/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,4 @@ def create_repository(self, repo):
659659
]:
660660
self._state.repositories.append(repo)
661661

662-
return f_return(None)
662+
return self.get_repository(repo.id)

pubtools/pulplib/_impl/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ContainerSyncOptions,
1111
YumSyncOptions,
1212
Importer,
13-
IsoImporter,
13+
FileImporter,
1414
YumImporter,
1515
)
1616
from .unit import (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .base import Repository, PublishOptions, SyncOptions, Importer
22
from .container import ContainerImageRepository, ContainerSyncOptions
33
from .yum import YumRepository, YumSyncOptions, YumImporter
4-
from .file import FileRepository, FileSyncOptions, IsoImporter
4+
from .file import FileRepository, FileSyncOptions, FileImporter

pubtools/pulplib/_impl/model/repository/base.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
from frozenlist2 import frozenlist
99
from more_executors.futures import f_proxy, f_map, f_flat_map
1010

11+
from frozendict.core import frozendict # pylint: disable=no-name-in-module
1112
from .repo_lock import RepoLock
1213
from ..attr import pulp_attrib, PULP2_FIELD, PULP2_MUTABLE
1314
from ..common import PulpObject, Deletable, DetachedException
14-
from ..convert import frozenlist_or_none_converter
15+
from ..convert import frozenlist_or_none_converter, frozendict_or_none_converter
1516
from ..distributor import Distributor
1617
from ...criteria import Criteria, Matcher
1718
from ...schema import load_schema
@@ -47,7 +48,12 @@ class Importer(PulpObject):
4748
"""
4849
Type id of the importer.
4950
"""
50-
config = pulp_attrib(default=None, type=dict, pulp_field="config")
51+
config = pulp_attrib(
52+
default=attr.Factory(frozendict),
53+
type=frozendict,
54+
converter=frozendict_or_none_converter,
55+
pulp_field="config",
56+
)
5157
"""
5258
Configuration dictionary of the importer.
5359
"""
@@ -283,7 +289,7 @@ class Repository(PulpObject, Deletable):
283289
default=attr.Factory(frozenlist),
284290
type=list,
285291
pulp_field="notes.signatures",
286-
pulp_py_converter=lambda sigs: sigs.split(","),
292+
pulp_py_converter=lambda sigs: sigs.split(",") if sigs else [],
287293
py_pulp_converter=",".join,
288294
converter=lambda keys: frozenlist([k.strip() for k in keys]),
289295
)
@@ -383,7 +389,7 @@ class Repository(PulpObject, Deletable):
383389
"""
384390
An object of :class:`~pubtools.pulplib.Importer` that is associated with the repository.
385391
386-
.. versionadded:: 2.39.0
392+
.. versionadded:: 2.39.0
387393
"""
388394

389395
@distributors.validator

pubtools/pulplib/_impl/model/repository/file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@attr.s(kw_only=True, frozen=True)
17-
class IsoImporter(Importer):
17+
class FileImporter(Importer):
1818
type_id = pulp_attrib(
1919
default="iso_importer", type=str, pulp_field="importer_type_id"
2020
)
@@ -60,14 +60,14 @@ class FileRepository(Repository):
6060
)
6161

6262
importer = pulp_attrib(
63-
default=IsoImporter(),
64-
type=IsoImporter,
63+
default=FileImporter(),
64+
type=FileImporter,
6565
pulp_field="importers",
66-
pulp_py_converter=IsoImporter._from_data,
67-
py_pulp_converter=IsoImporter._to_data,
66+
pulp_py_converter=FileImporter._from_data,
67+
py_pulp_converter=FileImporter._to_data,
6868
)
6969
"""
70-
An object of :class:`~pubtools.pulplib.IsoImporter` that is associated with the repository.
70+
An object of :class:`~pubtools.pulplib.FileImporter` that is associated with the repository.
7171
7272
.. versionadded:: 2.39.0
7373
"""

pubtools/pulplib/_impl/model/repository/yum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class YumRepository(Repository):
123123
"""
124124
An object of :class:`~pubtools.pulplib.YumImporter` that is associated with the repository.
125125
126-
.. versionadded:: 2.39.0
126+
.. versionadded:: 2.39.0
127127
"""
128128

129129
def get_binary_repository(self):

tests/fake/test_fake_create_repo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def test_create_repository():
66
controller = FakeController()
77

88
client = controller.client
9-
client.create_repository(Repository(id="repo1"))
10-
client.create_repository(Repository(id="repo2"))
9+
repo_1 = client.create_repository(Repository(id="repo1"))
10+
repo_2 = client.create_repository(Repository(id="repo2"))
1111

1212
# adding already existing repository has no effect
13-
client.create_repository(Repository(id="repo1"))
13+
_ = client.create_repository(Repository(id="repo1"))
1414
# The change should be reflected in the controller,
1515
# with two repositories present
16-
assert controller.repositories == [Repository(id="repo1"), Repository(id="repo2")]
16+
assert controller.repositories == [repo_1.result(), repo_2.result()]

0 commit comments

Comments
 (0)