Support the option volume_binds of docker run

Change-Id: I9e9dca7e42b48b4503fed390343f125f1cdec874
Implements: blueprint support-volume-binds
This commit is contained in:
Feng Shengqin 2017-10-14 15:32:55 +08:00
parent 7010aabb8b
commit c19ffb5a02
2 changed files with 11 additions and 6 deletions

View File

@ -200,12 +200,13 @@ def parse_command(command):
def parse_mounts(mounts):
err_msg = ("Invalid mounts argument '%s'. mounts arguments must be of "
"the form --mount source=<volume>,destination=<path>. Or use "
"--mount size=<size>,destination=<path> to create a new volume "
"the form --mount type=<local|cinder>,source=<volume>,"
"destination=<path>. Or use --mount type=<local|cinder>,"
"size=<size>,destination=<path> to create a new volume "
"and mount to the container")
parsed_mounts = []
for mount in mounts:
mount_info = {"source": "", "destination": "", "size": ""}
mount_info = {"type": "", "source": "", "destination": "", "size": ""}
for mnt in mount.split(","):
try:
k, v = mnt.split("=", 1)
@ -220,11 +221,15 @@ def parse_mounts(mounts):
else:
raise apiexec.CommandError(err_msg % mnt)
if mount_info['type'] not in ["local", "cinder"]:
raise apiexec.CommandError(err_msg % mnt)
if not mount_info['destination']:
raise apiexec.CommandError(err_msg % mnt)
if not mount_info['source'] and not mount_info['size']:
raise apiexec.CommandError(err_msg % mnt)
if mount_info['type'] == 'cinder':
if not mount_info['source'] and not mount_info['size']:
raise apiexec.CommandError(err_msg % mnt)
parsed_mounts.append(mount_info)
return parsed_mounts

View File

@ -166,7 +166,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
self, mock_run, mock_show_container):
mock_run.return_value = 'container'
self._test_arg_success(
'run --mount source=s,destination=d x')
'run --mount type=local,source=s,destination=d x')
mock_show_container.assert_called_once_with('container')
def test_zun_container_run_with_mount_invalid_format(self):