From 75ce8fc013f6befc102d580651ea92e152b6f8bf Mon Sep 17 00:00:00 2001 From: Jialei Date: Wed, 10 Aug 2022 18:57:22 +0800 Subject: [PATCH] fix(client): fix wrong uri of head request --- client/starwhale/base/bundle_copy.py | 20 +++++++++++--------- client/tests/base/test_copy.py | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/starwhale/base/bundle_copy.py b/client/starwhale/base/bundle_copy.py index 7392bf294c..0509b69dfd 100644 --- a/client/starwhale/base/bundle_copy.py +++ b/client/starwhale/base/bundle_copy.py @@ -82,14 +82,11 @@ def _do_validate(self) -> None: def _check_cloud_obj_existed(self, uri: URI) -> bool: # TODO: add more params for project # TODO: tune controller api, use unified params name + url = self._get_remote_instance_rc_url(True) ok, _ = self.do_http_request_simple_ret( - path=self._get_remote_instance_rc_url(), + path=url, method=HTTPMethod.HEAD, instance_uri=uri, - params={ - _query_param_map[self.typ]: f"{self.bundle_name}:{self.bundle_version}", - "project": uri.project, - }, ignore_status_codes=[HTTPStatus.NOT_FOUND], ) return ok @@ -113,12 +110,17 @@ def _is_existed(self, uri: URI) -> bool: else: return self._get_target_path(uri).exists() - def _get_remote_instance_rc_url(self) -> str: + def _get_remote_instance_rc_url(self, for_head: bool = False) -> str: _obj = self.src_uri.object + project = self.dest_uri.project if self.src_uri.instance_type == InstanceType.CLOUD: - return f"/project/{self.src_uri.project}/{self.typ}/{_obj.name}/version/{_obj.version}/file" - else: - return f"/project/{self.dest_uri.project}/{self.typ}/{_obj.name}/version/{_obj.version}/file" + project = self.src_uri.project + base = [f"/project/{project}/{self.typ}/{_obj.name}/version/{_obj.version}"] + if not for_head: + # uri for head request contains no 'file' + base.append("file") + + return "/".join(base) def _do_upload_bundle_tar(self, progress: Progress) -> None: file_path = self._get_target_path(self.src_uri) diff --git a/client/tests/base/test_copy.py b/client/tests/base/test_copy.py index 7e8b350a4a..22fd4e2a8c 100644 --- a/client/tests/base/test_copy.py +++ b/client/tests/base/test_copy.py @@ -30,7 +30,7 @@ def setUp(self) -> None: def test_upload_bundle_file(self, rm: Mocker) -> None: rm.request( HTTPMethod.HEAD, - "http://1.1.1.1:8182/api/v1/project/project/model/mnist/version/abcdefg1234/file", + "http://1.1.1.1:8182/api/v1/project/project/model/mnist/version/abcdefg1234", json={"message": "not found"}, status_code=HTTPStatus.NOT_FOUND, ) @@ -58,7 +58,7 @@ def test_upload_bundle_file(self, rm: Mocker) -> None: def test_download_bundle_file(self, rm: Mocker) -> None: rm.request( HTTPMethod.HEAD, - "http://1.1.1.1:8182/api/v1/project/1/model/mnist/version/latest/file", + "http://1.1.1.1:8182/api/v1/project/1/model/mnist/version/latest", json={"message": "existed"}, status_code=HTTPStatus.OK, ) @@ -86,7 +86,7 @@ def test_download_bundle_file(self, rm: Mocker) -> None: def test_upload_bundle_dir(self, rm: Mocker) -> None: rm.request( HTTPMethod.HEAD, - "http://1.1.1.1:8182/api/v1/project/project/dataset/mnist/version/abcde/file", + "http://1.1.1.1:8182/api/v1/project/project/dataset/mnist/version/abcde", json={"message": "already existed"}, status_code=HTTPStatus.OK, ) @@ -121,7 +121,7 @@ def test_upload_bundle_dir(self, rm: Mocker) -> None: def test_download_bundle_dir(self, rm: Mocker) -> None: rm.request( HTTPMethod.HEAD, - "http://1.1.1.1:8182/api/v1/project/1/dataset/mnist/version/latest/file", + "http://1.1.1.1:8182/api/v1/project/1/dataset/mnist/version/latest", json={"message": "existed"}, status_code=HTTPStatus.OK, )