Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): fix wrong uri of head request #899

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions client/starwhale/base/bundle_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions client/tests/base/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down