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/3911-cl-store infer storage type from url #4061

Merged
merged 27 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
14 changes: 14 additions & 0 deletions codalab/lib/bundle_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,20 @@ def do_store_command(self, args):
"url": args.url,
"authentication": args.authentication,
}
if args.url.startswith("azfs://"):
if args.storage_type is None:
bundle_store_info["storage_type"] = "azure_blob"
elif args.storage_type != "azure_blob":
raise UsageError(
f"cl store storage type '{args.storage_format}' conflicts with storage format."
)
elif args.url.startswith("gs://"):
if args.storage_type is None:
bundle_store_info["storage_type"] = "gcs"
elif args.storage_type != "gcs":
raise UsageError(
f"cl store storage type '{args.storage_format}' conflicts with storage format."
)
new_bundle_store = client.create('bundle_stores', bundle_store_info)
print(new_bundle_store["id"], file=self.stdout)
elif args.command == 'ls':
Expand Down
57 changes: 57 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,64 @@ def test_upload_default_bundle_store(ctx):
uuid = _run_command([cl, 'upload', '-c', 'hello'])
check_contains(bundle_store_name, _run_command([cl, "info", uuid]))

@TestModule.register('store_add')
def test_store_add(ctx):
"""
Tests of command `cl store add` on different blob storage. (Not test --storage-format yet)
wwwjn marked this conversation as resolved.
Show resolved Hide resolved
1. Specify storage type and url
wwwjn marked this conversation as resolved.
Show resolved Hide resolved
2. Specify url but not specify storage type
3. Specify wrong storage type and url: expected exit -1
"""
# Create a new azure_blob bundle store, then delete it
bundle_store_name = os.getenv('CODALAB_DEFAULT_BUNDLE_STORE_NAME')
blob_id = _run_command(
[
cl,
"store",
"add",
"--name",
bundle_store_name,
'--storage-type',
'azure_blob',
'--url',
'azfs://devstoreaccount1/bundles',
]
)
check_contains("azure_blob", _run_command([cl, "store", "ls"]))
_run_command([cl, "store", "rm", blob_id])
# TODO: set CODALAB_GOOGLE_APPLICATION_CREDENTIALS and test gcp blob storage
epicfaace marked this conversation as resolved.
Show resolved Hide resolved

# create a new azure_blob but not specify storage type
wwwjn marked this conversation as resolved.
Show resolved Hide resolved
blob_id = _run_command(
[
cl,
"store",
"add",
"--name",
bundle_store_name,
'--url',
'azfs://devstoreaccount1/bundles',
]
)
check_contains("azure_blob", _run_command([cl, "store", "ls"]))
_run_command([cl, "store", "rm", blob_id])

# create a new azure_blob but specify wrong type
wwwjn marked this conversation as resolved.
Show resolved Hide resolved
blob_id = _run_command(
[
cl,
"store",
"add",
"--name",
bundle_store_name,
'--storage-type',
'disk', # the type does not aligns with url
wwwjn marked this conversation as resolved.
Show resolved Hide resolved
'--url',
'azfs://devstoreaccount1/bundles',
],
expected_exit_code=1,
)

@TestModule.register('download')
def test_download(ctx):
# Upload test files directory as archive to preserve everything invariant of the upload implementation
Expand Down