Skip to content

Commit 7d32c62

Browse files
authored
Merge pull request #213 from glisignoli/209_deb_repository_default_remote
Added option for a default deb remote on a repository
2 parents 7f92ccb + 87fc970 commit 7d32c62

26 files changed

+45434
-20053
lines changed

plugins/modules/deb_repository.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
description:
2020
- Description of the repository
2121
type: str
22+
remote:
23+
description:
24+
- An optional remote to use by default when syncing
25+
type: str
2226
extends_documentation_fragment:
2327
- pulp.squeezer.pulp.entity_state
2428
- pulp.squeezer.pulp
@@ -46,6 +50,16 @@
4650
description: A brand new repository with a description
4751
state: present
4852
53+
- name: Create a deb repository with a default remote set
54+
pulp.squeezer.deb_repository:
55+
pulp_url: https://pulp.example.org
56+
username: admin
57+
password: password
58+
name: new_repo_with_remote
59+
description: A brand new repository with a remote set
60+
remote: my_remote
61+
state: present
62+
4963
- name: Delete a deb repository
5064
pulp.squeezer.deb_repository:
5165
pulp_url: https://pulp.example.org
@@ -77,7 +91,10 @@
7791

7892
try:
7993
from pulp_glue.deb import __version__ as pulp_glue_deb_version
80-
from pulp_glue.deb.context import PulpAptRepositoryContext
94+
from pulp_glue.deb.context import PulpAptRemoteContext, PulpAptRepositoryContext
95+
96+
# In pulp-glue <0.35 this is needed for idempotent removal of the remote.
97+
PulpAptRepositoryContext.NULLABLES.add("remote")
8198

8299
assert_version(GLUE_DEB_VERSION_SPEC, pulp_glue_deb_version, "pulp-glue-deb")
83100
PULP_GLUE_DEB_IMPORT_ERR = None
@@ -95,11 +112,21 @@ def main():
95112
argument_spec={
96113
"name": {},
97114
"description": {},
115+
"remote": {},
98116
},
99117
required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])],
100118
) as module:
119+
remote_name = module.params["remote"]
101120
natural_key = {"name": module.params["name"]}
102121
desired_attributes = {}
122+
123+
if remote_name is not None:
124+
if remote_name:
125+
remote_ctx = PulpAptRemoteContext(module.pulp_ctx, entity={"name": remote_name})
126+
desired_attributes["remote"] = remote_ctx.pulp_href
127+
else:
128+
desired_attributes["remote"] = ""
129+
103130
if module.params["description"] is not None:
104131
desired_attributes["description"] = module.params["description"]
105132

plugins/modules/deb_sync.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
description:
1717
- Name of the remote to synchronize
1818
type: str
19-
required: true
19+
required: false
2020
repository:
2121
description:
2222
- Name of the repository
@@ -35,7 +35,18 @@
3535
"""
3636

3737
EXAMPLES = r"""
38-
- name: Sync deb remote into repository
38+
- name: Sync deb repository with a remote set
39+
pulp.squeezer.deb_sync:
40+
pulp_url: https://pulp.example.org
41+
username: admin
42+
password: password
43+
repository: repo_1
44+
register: sync_result
45+
- name: Report synched repository version
46+
debug:
47+
var: sync_result.repository_version
48+
49+
- name: Sync deb specific remote into repository
3950
pulp.squeezer.deb_sync:
4051
pulp_url: https://pulp.example.org
4152
username: admin
@@ -79,7 +90,7 @@ def main():
7990
with PulpAnsibleModule(
8091
import_errors=[("pulp-glue-deb", PULP_GLUE_DEB_IMPORT_ERR)],
8192
argument_spec={
82-
"remote": {"required": True},
93+
"remote": {"required": False},
8394
"repository": {"required": True},
8495
"mirror": {"type": "bool", "default": False},
8596
},

tests/fixtures/deb_repository-0.yml

Lines changed: 21666 additions & 9377 deletions
Large diffs are not rendered by default.

tests/fixtures/deb_repository-1.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ interactions:
22
- request:
33
body: null
44
headers:
5-
Accept:
6-
- application/json
5+
? !!python/object/apply:multidict._multidict.istr
6+
- Accept
7+
: - application/json
78
Accept-Encoding:
89
- gzip, deflate
910
Connection:
1011
- keep-alive
11-
User-Agent:
12-
- Squeezer/0.1.0-dev
12+
? !!python/object/apply:multidict._multidict.istr
13+
- User-Agent
14+
: - Squeezer/0.2.0-dev
1315
method: GET
1416
uri: http://pulp.example.org/pulp/api/v3/repositories/deb/apt/?name=test_deb_repository&offset=0&limit=1
1517
response:
1618
body:
17-
string: '{"count":1,"next":null,"previous":null,"results":[{"pulp_href":"/pulp/api/v3/repositories/deb/apt/0194a2a7-599f-71a6-ab5b-32eacd760782/","prn":"prn:deb.aptrepository:0194a2a7-599f-71a6-ab5b-32eacd760782","pulp_created":"2025-01-26T12:47:44.032982Z","pulp_last_updated":"2025-01-26T12:47:44.035818Z","versions_href":"/pulp/api/v3/repositories/deb/apt/0194a2a7-599f-71a6-ab5b-32eacd760782/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/deb/apt/0194a2a7-599f-71a6-ab5b-32eacd760782/versions/0/","name":"test_deb_repository","description":null,"retain_repo_versions":null,"remote":null,"publish_upstream_release_fields":true,"signing_service":null,"signing_service_release_overrides":{}}]}'
19+
string: '{"count":0,"next":null,"previous":null,"results":[]}'
1820
headers:
1921
Access-Control-Expose-Headers:
2022
- Correlation-ID
@@ -23,15 +25,15 @@ interactions:
2325
Connection:
2426
- keep-alive
2527
Content-Length:
26-
- '715'
28+
- '52'
2729
Content-Type:
2830
- application/json
2931
Correlation-ID:
30-
- 4a1f0260c5404050b720c244b437e9d0
32+
- 44bbfa20b78444cb843d0a8becc762f7
3133
Cross-Origin-Opener-Policy:
3234
- same-origin
3335
Date:
34-
- Sun, 26 Jan 2025 12:47:44 GMT
36+
- Tue, 22 Jul 2025 20:27:01 GMT
3537
Referrer-Policy:
3638
- same-origin
3739
Server:
@@ -45,4 +47,60 @@ interactions:
4547
status:
4648
code: 200
4749
message: OK
50+
- request:
51+
body: '{"description": null, "name": "test_deb_repository"}'
52+
headers:
53+
? !!python/object/apply:multidict._multidict.istr
54+
- Accept
55+
: - application/json
56+
Accept-Encoding:
57+
- gzip, deflate
58+
Connection:
59+
- keep-alive
60+
Content-Length:
61+
- '52'
62+
Correlation-Id:
63+
- 44bbfa20b78444cb843d0a8becc762f7
64+
? !!python/object/apply:multidict._multidict.istr
65+
- User-Agent
66+
: - Squeezer/0.2.0-dev
67+
content-type:
68+
- application/json
69+
method: POST
70+
uri: http://pulp.example.org/pulp/api/v3/repositories/deb/apt/
71+
response:
72+
body:
73+
string: '{"pulp_href":"/pulp/api/v3/repositories/deb/apt/019833d1-7312-7d75-a4d6-471cf990c527/","prn":"prn:deb.aptrepository:019833d1-7312-7d75-a4d6-471cf990c527","pulp_created":"2025-07-22T20:27:01.272750Z","pulp_last_updated":"2025-07-22T20:27:01.298768Z","versions_href":"/pulp/api/v3/repositories/deb/apt/019833d1-7312-7d75-a4d6-471cf990c527/versions/","pulp_labels":{},"latest_version_href":"/pulp/api/v3/repositories/deb/apt/019833d1-7312-7d75-a4d6-471cf990c527/versions/0/","name":"test_deb_repository","description":null,"retain_repo_versions":null,"remote":null,"publish_upstream_release_fields":true,"signing_service":null,"signing_service_release_overrides":{}}'
74+
headers:
75+
Access-Control-Expose-Headers:
76+
- Correlation-ID
77+
Allow:
78+
- GET, POST, HEAD, OPTIONS
79+
Connection:
80+
- keep-alive
81+
Content-Length:
82+
- '663'
83+
Content-Type:
84+
- application/json
85+
Correlation-ID:
86+
- 44bbfa20b78444cb843d0a8becc762f7
87+
Cross-Origin-Opener-Policy:
88+
- same-origin
89+
Date:
90+
- Tue, 22 Jul 2025 20:27:01 GMT
91+
Location:
92+
- /pulp/api/v3/repositories/deb/apt/019833d1-7312-7d75-a4d6-471cf990c527/
93+
Referrer-Policy:
94+
- same-origin
95+
Server:
96+
- nginx/1.22.1
97+
Vary:
98+
- Accept
99+
X-Content-Type-Options:
100+
- nosniff
101+
X-Frame-Options:
102+
- DENY
103+
status:
104+
code: 201
105+
message: Created
48106
version: 1

0 commit comments

Comments
 (0)