Skip to content

Commit ded674e

Browse files
committed
Implement policy option for images.pull
Fixes: containers#564 Signed-off-by: Nicola Sella <[email protected]>
1 parent 7e834d3 commit ded674e

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

podman/domain/containers_run.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def run(
4444
side. Default: False.
4545
4646
Keyword Args:
47-
- See the create() method for keyword arguments.
47+
- These args are directly used to pull an image when the image is not found
48+
platform (str) – Platform in the format os[/arch[/variant]]
49+
policy (str) - Pull policy. "missing" (default), "always", "never", "newer"
50+
- See the create() method for other keyword arguments.
4851
4952
Returns:
5053
- When detach is True, return a Container
@@ -66,7 +69,11 @@ def run(
6669
try:
6770
container = self.create(image=image, command=command, **kwargs)
6871
except ImageNotFound:
69-
self.podman_client.images.pull(image, platform=kwargs.get("platform"))
72+
self.podman_client.images.pull(
73+
image,
74+
platform=kwargs.get("platform"),
75+
policy=kwargs.get("policy", "missing"),
76+
)
7077
container = self.create(image=image, command=command, **kwargs)
7178

7279
container.start()

podman/domain/images_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def pull(
337337
decode (bool) – Decode the JSON data from the server into dicts.
338338
Only applies with ``stream=True``
339339
platform (str) – Platform in the format os[/arch[/variant]]
340+
policy (str) - Pull policy. "always" (default), "missing", "never", "newer"
340341
progress_bar (bool) - Display a progress bar with the image pull progress (uses
341342
the compat endpoint). Default: False
342343
tls_verify (bool) - Require TLS verification. Default: True.
@@ -365,6 +366,7 @@ def pull(
365366
}
366367

367368
params = {
369+
"policy": kwargs.get("policy", "always"),
368370
"reference": repository,
369371
"tlsVerify": kwargs.get("tls_verify", True),
370372
"compatMode": kwargs.get("compatMode", True),

podman/tests/unit/test_imagesmanager.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,27 @@ def test_pull_2x(self, mock):
649649
images[1].id, "c4b16966ecd94ffa910eab4e630e24f259bf34a87e924cd4b1434f267b0e354e"
650650
)
651651

652+
@requests_mock.Mocker()
653+
def test_pull_policy(self, mock):
654+
image_id = "sha256:326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab"
655+
mock.post(
656+
tests.LIBPOD_URL + "/images/pull?reference=quay.io%2ffedora%3Alatest&policy=missing",
657+
json={
658+
"error": "",
659+
"id": image_id,
660+
"images": [image_id],
661+
"stream": "",
662+
},
663+
)
664+
mock.get(
665+
tests.LIBPOD_URL + "/images"
666+
"/sha256%3A326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab/json",
667+
json=FIRST_IMAGE,
668+
)
669+
670+
image = self.client.images.pull("quay.io/fedora:latest", policy="missing")
671+
self.assertEqual(image.id, image_id)
672+
652673
@requests_mock.Mocker()
653674
def test_list_with_name_parameter(self, mock):
654675
"""Test that name parameter is correctly converted to a reference filter"""

0 commit comments

Comments
 (0)