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

Issue 3200 #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions python/kserve/kserve/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,12 @@ def _download_s3(uri, temp_dir: str):
# Objects: churn, churn-pickle, churn-pickle-logs
bucket_path_last_part = bucket_path.split("/")[-1]
object_last_path = obj.key.split("/")[-1]
bucket_path_parent_part = bucket_path.rsplit("/", 1)[0]

if bucket_path == obj.key:
target_key = obj.key.rsplit("/", 1)[-1]
exact_obj_found = True
elif object_last_path.startswith(bucket_path_last_part):
target_key = obj.key.replace(bucket_path_parent_part, "", 1).lstrip("/")
elif bucket_path_last_part and object_last_path.startswith(bucket_path_last_part):
target_key = object_last_path
else:
target_key = obj.key.replace(bucket_path, "").lstrip("/")

Expand Down
19 changes: 19 additions & 0 deletions python/kserve/kserve/storage/test/test_s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,22 @@ def test_update_with_storage_spec_s3(monkeypatch):

# revert changes
os.environ = previous_env


@mock.patch(STORAGE_MODULE + '.boto3')
def test_target_startswith_parent_folder_name(mock_storage):
bucket_name = 'foo'
paths = ["model.pkl", "a/model.pkl", "conda.yaml"]
object_paths = ['test/artifacts/model/' + p for p in paths]

# when
mock_boto3_bucket = create_mock_boto3_bucket(mock_storage, object_paths)
Storage._download_s3(
f's3://{bucket_name}/test/artifacts/model', 'dest_path')

# then
arg_list = get_call_args(mock_boto3_bucket.download_file.call_args_list)
assert arg_list[0] == expected_call_args_list(
'test/artifacts/model', 'dest_path', paths)[0]
mock_boto3_bucket.objects.filter.assert_called_with(
Prefix='test/artifacts/model')
Loading