Merge "Avoid empty values in 'mounts' options"
This commit is contained in:
commit
5f2b402d55
@ -205,7 +205,8 @@ def parse_mounts(mounts):
|
||||
"and mount to the container")
|
||||
parsed_mounts = []
|
||||
for mount in mounts:
|
||||
mount_info = {"source": "", "destination": "", "size": ""}
|
||||
keys = ["source", "destination", "size"]
|
||||
mount_info = {}
|
||||
for mnt in mount.split(","):
|
||||
try:
|
||||
k, v = mnt.split("=", 1)
|
||||
@ -213,17 +214,17 @@ def parse_mounts(mounts):
|
||||
v = v.strip()
|
||||
except ValueError:
|
||||
raise apiexec.CommandError(err_msg % mnt)
|
||||
if k in mount_info:
|
||||
if mount_info[k]:
|
||||
if k in keys:
|
||||
if mount_info.get(k):
|
||||
raise apiexec.CommandError(err_msg % mnt)
|
||||
mount_info[k] = v
|
||||
else:
|
||||
raise apiexec.CommandError(err_msg % mnt)
|
||||
|
||||
if not mount_info['destination']:
|
||||
if not mount_info.get('destination'):
|
||||
raise apiexec.CommandError(err_msg % mnt)
|
||||
|
||||
if not mount_info['source'] and not mount_info['size']:
|
||||
if not mount_info.get('source') and not mount_info.get('size'):
|
||||
raise apiexec.CommandError(err_msg % mnt)
|
||||
|
||||
parsed_mounts.append(mount_info)
|
||||
|
@ -199,7 +199,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
self._test_arg_success(
|
||||
'run --mount source=s,destination=d x')
|
||||
mock_show_container.assert_called_once_with('container')
|
||||
mounts = [{'source': 's', 'destination': 'd', 'size': ''}]
|
||||
mounts = [{'source': 's', 'destination': 'd'}]
|
||||
mock_run.assert_called_with(
|
||||
**_get_container_args(image='x', mounts=mounts))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user