Skip to content

Commit 263248f

Browse files
committed
Rewrite all remaining modules to glue
1 parent 55fa4bf commit 263248f

File tree

91 files changed

+234866
-152584
lines changed

Some content is hidden

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

91 files changed

+234866
-152584
lines changed

.ci/scripts/update_requirements.py

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,90 @@
11
import getopt
22
import re
33
import sys
4+
import typing as t
45
from pathlib import Path
56

67
from packaging.requirements import Requirement
78
from packaging.specifiers import SpecifierSet
89
from packaging.version import Version
910

1011

11-
def fix_requirements_file(path: Path, check: bool, name: str, specifier: SpecifierSet) -> None:
12+
def fix_requirements_file(path: Path, check: bool, specs: t.Dict[str, SpecifierSet]) -> None:
13+
changed = False
1214
lines = path.read_text().split("\n")
13-
for num, line in enumerate(lines):
14-
try:
15-
requirement = Requirement(line)
16-
except Exception:
17-
pass
18-
else:
15+
for name, specifier in specs.items():
16+
for num, line in enumerate(lines):
17+
try:
18+
requirement = Requirement(line)
19+
except Exception:
20+
# Ignore unparsable lines.
21+
continue
1922
if requirement.name == name:
2023
if requirement.specifier == specifier:
21-
print(f"{path} is up to date.")
2224
break
2325
elif check:
24-
print(f"{path} has unmatched pulp-glue requirement.")
26+
print(f"{path} has unmatched {name} requirement.")
2527
sys.exit(1)
2628
else:
2729
print(f"Update {path}.")
2830
requirement.specifier = specifier
2931
lines[num] = str(requirement)
30-
path.write_text("\n".join(lines))
32+
changed = True
3133
break
34+
else:
35+
print(f"{name} requirement missing from {path}.")
36+
sys.exit(1)
37+
38+
if changed:
39+
path.write_text("\n".join(lines))
3240
else:
33-
print(f"{name} requirement missing from {path}.")
34-
sys.exit(1)
41+
print(f"{path} is up to date.")
3542

3643

3744
def main(check: bool) -> None:
3845
pulp_glue_path = Path("plugins/module_utils/pulp_glue.py")
3946
requirements_path = Path("requirements.txt")
4047
lower_bounds_path = Path("lower_bounds_constraints.lock")
4148

49+
version_spec_regex = {
50+
"pulp-glue": re.compile(r"^\s*GLUE_VERSION_SPEC\s*=\s*\"(.*)\"$"),
51+
"pulp-glue-deb": re.compile(r"^\s*GLUE_DEB_VERSION_SPEC\s*=\s*\"(.*)\"$"),
52+
}
53+
version_specs: t.Dict[str, SpecifierSet] = {}
54+
lower_bounds_specs: t.Dict[str, SpecifierSet] = {}
55+
4256
with pulp_glue_path.open("r") as fp:
4357
for line in fp.readlines():
44-
if match := re.search(r"GLUE_VERSION_SPEC\s*=\s*\"(.*)\"", line):
45-
GLUE_VERSION_SPEC = SpecifierSet(match.group(1))
58+
for name, regex in version_spec_regex.items():
59+
if match := re.search(regex, line):
60+
version_spec = SpecifierSet(match.group(1))
61+
version_spec_regex.pop(name)
62+
version_specs[name] = version_spec
63+
64+
try:
65+
min_version = min(
66+
[
67+
Version(spec.version)
68+
for spec in version_spec
69+
if spec.operator == ">="
70+
]
71+
)
72+
lower_bounds_specs[name] = SpecifierSet(f"=={min_version}")
73+
except ValueError:
74+
print("No lower bound requirement specified for pulp-glue.")
75+
sys.exit(1)
76+
77+
break
78+
if not version_spec_regex:
79+
# We found them all.
4680
break
4781
else:
48-
print("GLUE_VERSION_SPEC not found!")
82+
keys = ", ".join(version_spec_regex.keys())
83+
print(f"Specs for {keys} not found!")
4984
sys.exit(1)
50-
try:
51-
min_version = min(
52-
[Version(spec.version) for spec in GLUE_VERSION_SPEC if spec.operator == ">="]
53-
)
54-
except ValueError:
55-
print("No lower bound requirement specified for pulp-glue.")
56-
sys.exit(1)
57-
lower_bounds_spec = SpecifierSet(f"=={min_version}")
5885

59-
fix_requirements_file(requirements_path, check, "pulp-glue", GLUE_VERSION_SPEC)
60-
fix_requirements_file(lower_bounds_path, check, "pulp-glue", lower_bounds_spec)
86+
fix_requirements_file(requirements_path, check, version_specs)
87+
fix_requirements_file(lower_bounds_path, check, lower_bounds_specs)
6188

6289

6390
if __name__ == "__main__":

lower_bounds_constraints.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pulp-glue==0.29.2
2+
pulp-glue-deb==0.3.0

plugins/module_utils/pulp_glue.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@
1010

1111
from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib
1212

13+
GLUE_VERSION_SPEC = ">=0.29.2,<0.31"
14+
GLUE_DEB_VERSION_SPEC = ">=0.3.0,<0.4"
15+
16+
17+
def assert_version(spec, version, name):
18+
if not SpecifierSet(spec, prereleases=True).contains(version):
19+
raise ImportError(f"Installed '{name}' version '{version}' is not in '{spec}'.")
20+
21+
1322
try:
1423
from packaging.requirements import SpecifierSet
1524
from pulp_glue.common import __version__ as pulp_glue_version
1625
from pulp_glue.common.context import PulpContext, PulpException, PulpNoWait
1726
from pulp_glue.common.openapi import BasicAuthProvider
1827

19-
GLUE_VERSION_SPEC = ">=0.29.2,<0.31"
20-
if not SpecifierSet(GLUE_VERSION_SPEC, prereleases=True).contains(pulp_glue_version):
21-
raise ImportError(
22-
f"Installed 'pulp-glue' version '{pulp_glue_version}' is not in '{GLUE_VERSION_SPEC}'."
23-
)
24-
28+
assert_version(GLUE_VERSION_SPEC, pulp_glue_version, "pulp-glue")
2529
PULP_CLI_IMPORT_ERR = None
2630
except ImportError:
2731
PULP_CLI_IMPORT_ERR = traceback.format_exc()

plugins/modules/access_policy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
try:
126126
from pulp_glue.core.context import PulpAccessPolicyContext
127127

128-
PULP_CLI_IMPORT_ERR = None
128+
PULP_GLUE_IMPORT_ERR = None
129129
except ImportError:
130-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
130+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
131131
PulpAccessPolicyContext = None
132132

133133

@@ -136,7 +136,7 @@ def main():
136136
context_class=PulpAccessPolicyContext,
137137
entity_singular="access_policy",
138138
entity_plural="access_policies",
139-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
139+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
140140
argument_spec={
141141
"viewset_name": {},
142142
"statements": {

plugins/modules/ansible_distribution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
)
100100
from pulp_glue.core.context import PulpContentGuardContext
101101

102-
PULP_CLI_IMPORT_ERR = None
102+
PULP_GLUE_IMPORT_ERR = None
103103
except ImportError:
104-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
104+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
105105
PulpAnsibleDistributionContext = None
106106

107107

@@ -110,7 +110,7 @@ def main():
110110
context_class=PulpAnsibleDistributionContext,
111111
entity_singular="distribution",
112112
entity_plural="distributions",
113-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
113+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
114114
argument_spec={
115115
"name": {},
116116
"base_path": {},

plugins/modules/ansible_remote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
)
126126
from pulp_glue.common.context import PulpRemoteContext
127127

128-
PULP_CLI_IMPORT_ERR = None
128+
PULP_GLUE_IMPORT_ERR = None
129129
except ImportError:
130-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
130+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
131131
PulpRemoteContext = None
132132

133133

@@ -157,7 +157,7 @@ def represent(self, entity):
157157
def main():
158158
with PulpAnsibleRemoteAnsibleModule(
159159
context_class=PulpRemoteContext,
160-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
160+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
161161
argument_spec={
162162
"content_type": {"choices": ["collection", "role"], "default": "collection"},
163163
"policy": {"choices": ["immediate"]},

plugins/modules/ansible_repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
try:
7676
from pulp_glue.ansible.context import PulpAnsibleRepositoryContext
7777

78-
PULP_CLI_IMPORT_ERR = None
78+
PULP_GLUE_IMPORT_ERR = None
7979
except ImportError:
80-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
80+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
8181
PulpAnsibleRepositoryContext = None
8282

8383

@@ -86,7 +86,7 @@ def main():
8686
context_class=PulpAnsibleRepositoryContext,
8787
entity_singular="repository",
8888
entity_plural="repositories",
89-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
89+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
9090
argument_spec={
9191
"name": {},
9292
"description": {},

plugins/modules/ansible_role.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
from pulp_glue.ansible.context import PulpAnsibleRoleContext
8181
from pulp_glue.core.context import PulpArtifactContext
8282

83-
PULP_CLI_IMPORT_ERR = None
83+
PULP_GLUE_IMPORT_ERR = None
8484
except ImportError:
85-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
85+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
8686
PulpAnsibleRoleContext = None
8787

8888

@@ -91,7 +91,7 @@ def main():
9191
context_class=PulpAnsibleRoleContext,
9292
entity_singular="content",
9393
entity_plural="contents",
94-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
94+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
9595
argument_spec={
9696
"name": {},
9797
"namespace": {},

plugins/modules/ansible_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575
PulpAnsibleRoleRemoteContext,
7676
)
7777

78-
PULP_CLI_IMPORT_ERR = None
78+
PULP_GLUE_IMPORT_ERR = None
7979
except ImportError:
80-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
80+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
8181

8282

8383
def main():
8484
with PulpAnsibleModule(
85-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
85+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
8686
argument_spec={
8787
"content_type": {"choices": ["collection", "role"], "default": "collection"},
8888
"remote": {"required": False},

plugins/modules/artifact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
from pulp_glue.common.context import PulpEntityNotFound
9393
from pulp_glue.core.context import PulpArtifactContext as _PulpArtifactContext
9494

95-
PULP_CLI_IMPORT_ERR = None
95+
PULP_GLUE_IMPORT_ERR = None
9696

9797
# Patch the Context to make converge call upload
9898
# It's a case study at this point. Eventually glue should handle this.
@@ -133,7 +133,7 @@ def converge(self, desired_attributes, defaults=None):
133133
return False, entity, entity
134134

135135
except ImportError:
136-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
136+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
137137
PulpArtifactContext = None
138138

139139

@@ -142,7 +142,7 @@ def main():
142142
context_class=PulpArtifactContext,
143143
entity_singular="artifact",
144144
entity_plural="artifacts",
145-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
145+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
146146
argument_spec={
147147
"file": {"type": "path"},
148148
"sha256": {},

plugins/modules/container_distribution.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104
)
105105
from pulp_glue.core.context import PulpContentGuardContext
106106

107-
PULP_CLI_IMPORT_ERR = None
107+
PULP_GLUE_IMPORT_ERR = None
108108
except ImportError:
109-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
109+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
110110
PulpContainerDistributionContext = None
111111

112112

@@ -115,7 +115,7 @@ def main():
115115
context_class=PulpContainerDistributionContext,
116116
entity_singular="distribution",
117117
entity_plural="distributions",
118-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
118+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
119119
argument_spec={
120120
"name": {},
121121
"base_path": {},
@@ -132,7 +132,6 @@ def main():
132132
repository_name = module.params["repository"]
133133
version = module.params["version"]
134134
content_guard_name = module.params["content_guard"]
135-
private = module.params["private"]
136135

137136
natural_key = {"name": module.params["name"]}
138137
desired_attributes = {

plugins/modules/container_remote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@
9191
try:
9292
from pulp_glue.container.context import PulpContainerRemoteContext
9393

94-
PULP_CLI_IMPORT_ERR = None
94+
PULP_GLUE_IMPORT_ERR = None
9595
except ImportError:
96-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
96+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
9797
PulpContainerRemoteContext = None
9898

9999

100100
def main():
101101
with PulpRemoteAnsibleModule(
102102
context_class=PulpContainerRemoteContext,
103-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
103+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
104104
argument_spec={
105105
"exclude_tags": {"type": "list", "elements": "str"},
106106
"include_tags": {"type": "list", "elements": "str"},

plugins/modules/container_repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
try:
7676
from pulp_glue.container.context import PulpContainerRepositoryContext
7777

78-
PULP_CLI_IMPORT_ERR = None
78+
PULP_GLUE_IMPORT_ERR = None
7979
except ImportError:
80-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
80+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
8181
PulpContainerRepositoryContext = None
8282

8383

@@ -86,7 +86,7 @@ def main():
8686
context_class=PulpContainerRepositoryContext,
8787
entity_singular="repository",
8888
entity_plural="repositories",
89-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
89+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
9090
argument_spec={
9191
"name": {},
9292
"description": {},

plugins/modules/container_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@
6666
PulpContainerRepositoryContext,
6767
)
6868

69-
PULP_CLI_IMPORT_ERR = None
69+
PULP_GLUE_IMPORT_ERR = None
7070
except ImportError:
71-
PULP_CLI_IMPORT_ERR = traceback.format_exc()
71+
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
7272

7373

7474
def main():
7575
with PulpAnsibleModule(
76-
import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
76+
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
7777
argument_spec={
7878
"remote": {"required": False},
7979
"repository": {"required": True},

0 commit comments

Comments
 (0)