Skip to content

Commit

Permalink
Use LocalExecutor in tag-docker [CLOUDDST-19927] (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyzheng authored Aug 16, 2023
1 parent 61276cc commit b42c089
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 197 deletions.
14 changes: 2 additions & 12 deletions pubtools/_quay/tag_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import requests

from .command_executor import ContainerExecutor
from .command_executor import LocalExecutor
from .exceptions import (
BadPushItem,
InvalidTargetSettings,
Expand Down Expand Up @@ -91,8 +91,6 @@ def verify_target_settings(self):
"iib_index_image",
"iib_krb_principal",
"quay_operator_repository",
"skopeo_image",
"docker_settings",
]
for setting in required_settings:
if setting not in self.target_settings:
Expand Down Expand Up @@ -728,15 +726,7 @@ def run(self):
self.hub, self.task_id, self.target_settings, self.target_name
)

with ContainerExecutor(
self.target_settings["skopeo_image"],
self.target_settings.get("docker_host") or "unix://var/run/docker.sock",
self.target_settings.get("docker_timeout"),
self.target_settings.get("docker_tls_verify") or False,
self.target_settings.get("docker_cert_path") or None,
self.target_settings.get("skopeo_executor_username") or None,
self.target_settings.get("skopeo_executor_password") or None,
) as executor:
with LocalExecutor() as executor:
executor.skopeo_login(
self.quay_host,
self.target_settings["dest_quay_user"],
Expand Down
30 changes: 16 additions & 14 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,15 @@ def mock_fetch_missing_push_items_digests_sf(push_items, target):
push_docker.run()


@mock.patch("pubtools._quay.command_executor.APIClient")
@mock.patch("subprocess.Popen")
@mock.patch("pubtools._quay.signature_handler._ManifestClaimsRunner")
@mock.patch("pubtools._quay.signature_remover.run_entrypoint")
@mock.patch("pubtools._quay.signature_handler.run_entrypoint")
def test_tag_docker_multiarch_merge_ml(
mock_run_entrypoint_sig_handler,
mock_run_entrypoint_sig_remover,
mock_claims_runner,
mock_api_client,
mock_popen,
target_settings,
tag_docker_push_item_add_integration,
tag_docker_push_item_remove_no_src_integration,
Expand Down Expand Up @@ -599,8 +599,8 @@ def test_tag_docker_multiarch_merge_ml(
[],
]

mock_api_client.return_value.exec_start.return_value = b"Login Succeeded"
mock_api_client.return_value.exec_inspect.return_value = {"ExitCode": 0}
mock_popen.return_value.communicate.return_value = ("Login Succeeded", "err")
mock_popen.return_value.returncode = 0

src_manifest_list_missing = deepcopy(src_manifest_list)
src_manifest_list_missing["manifests"] = src_manifest_list_missing["manifests"][:2]
Expand Down Expand Up @@ -701,6 +701,7 @@ def test_tag_docker_multiarch_merge_ml(
tag_docker_instance.run()


@mock.patch("subprocess.Popen")
@mock.patch("pubtools._quay.command_executor.APIClient")
@mock.patch("pubtools._quay.command_executor.RemoteExecutor._run_cmd")
@mock.patch("pubtools._quay.signature_handler._ManifestClaimsRunner")
Expand All @@ -712,6 +713,7 @@ def test_tag_docker_source_copy_untag(
mock_claims_runner,
mock_run_cmd,
mock_api_client,
mock_popen,
target_settings,
tag_docker_push_item_add_integration,
tag_docker_push_item_remove_no_src_integration,
Expand Down Expand Up @@ -743,17 +745,17 @@ def test_tag_docker_source_copy_untag(
[],
]

mock_api_client.return_value.exec_start.side_effect = [
b"something",
b"Login Succeeded",
b'{"Architecture": "amd64"}',
b'{"Architecture": "amd64"}',
b'{"Architecture": "amd64"}',
b"dest-quay-user",
b"finished tagging",
b'{"Architecture": "amd64"}',
]
mock_api_client.return_value.exec_start.return_value = b"Login Succeeded"
mock_api_client.return_value.exec_inspect.return_value = {"ExitCode": 0}
mock_popen.return_value.communicate.side_effect = [
("something", "err"),
("Login Succeeded", "err"),
('{"Architecture": "amd64"}', "err"),
('{"Architecture": "amd64"}', "err"),
('{"Architecture": "amd64"}', "err"),
('{"Architecture": "amd64"}', "err"),
]
mock_popen.return_value.returncode = 0

with requests_mock.Mocker() as m:
m.get(
Expand Down
Loading

0 comments on commit b42c089

Please sign in to comment.