From c19ffb5a0201081da36f58366185b450f818990b Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Sat, 14 Oct 2017 15:32:55 +0800 Subject: [PATCH] Support the option volume_binds of docker run Change-Id: I9e9dca7e42b48b4503fed390343f125f1cdec874 Implements: blueprint support-volume-binds --- zunclient/common/utils.py | 15 ++++++++++----- zunclient/tests/unit/v1/test_containers_shell.py | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/zunclient/common/utils.py b/zunclient/common/utils.py index 2876e20b..8ade57b2 100644 --- a/zunclient/common/utils.py +++ b/zunclient/common/utils.py @@ -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=,destination=. Or use " - "--mount size=,destination= to create a new volume " + "the form --mount type=,source=," + "destination=. Or use --mount type=," + "size=,destination= 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 diff --git a/zunclient/tests/unit/v1/test_containers_shell.py b/zunclient/tests/unit/v1/test_containers_shell.py index 25616c13..5220ffe3 100644 --- a/zunclient/tests/unit/v1/test_containers_shell.py +++ b/zunclient/tests/unit/v1/test_containers_shell.py @@ -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):