From 0f03836628f28cc7c7d1452cfc55f8ff2e3e3331 Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Fri, 9 Jun 2017 15:21:09 +0000 Subject: [PATCH] Add --docker-volume-size for cluster-create Add a docker-volume-size override parameter on cluster-create to override the value present on the cluster template. Partial-Bug: #1697648 Change-Id: Ib4d4af20dc5bb5fe631802dabe73d8ee341899b1 --- magnumclient/tests/v1/test_clusters.py | 11 ++++++++ magnumclient/tests/v1/test_clusters_shell.py | 25 +++++++++++++------ .../tests/v1/test_clustertemplates.py | 20 ++++++++++++++- magnumclient/v1/clusters.py | 1 + magnumclient/v1/clusters_shell.py | 9 ++++++- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/magnumclient/tests/v1/test_clusters.py b/magnumclient/tests/v1/test_clusters.py index 793cb887..35d4e3b3 100644 --- a/magnumclient/tests/v1/test_clusters.py +++ b/magnumclient/tests/v1/test_clusters.py @@ -263,6 +263,17 @@ class ClusterManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertTrue(cluster) + def test_cluster_create_with_docker_volume_size(self): + cluster_with_volume_size = dict() + cluster_with_volume_size.update(CREATE_CLUSTER) + cluster_with_volume_size['docker_volume_size'] = 20 + cluster = self.mgr.create(**cluster_with_volume_size) + expect = [ + ('POST', '/v1/clusters', {}, cluster_with_volume_size), + ] + self.assertEqual(expect, self.api.calls) + self.assertTrue(cluster) + def test_cluster_create_with_discovery_url(self): cluster_with_discovery = dict() cluster_with_discovery.update(CREATE_CLUSTER) diff --git a/magnumclient/tests/v1/test_clusters_shell.py b/magnumclient/tests/v1/test_clusters_shell.py index 862edabf..3b56b387 100644 --- a/magnumclient/tests/v1/test_clusters_shell.py +++ b/magnumclient/tests/v1/test_clusters_shell.py @@ -26,6 +26,7 @@ class FakeCluster(Cluster): Cluster.__init__(self, manager=manager, info=info) self.uuid = kwargs.get('uuid', 'x') self.keypair = kwargs.get('keypair', 'x') + self.docker_volume_size = kwargs.get('docker_volume_size', 3) self.name = kwargs.get('name', 'x') self.cluster_template_id = kwargs.get('cluster_template_id', 'x') self.stack_id = kwargs.get('stack_id', 'x') @@ -56,6 +57,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument): def _get_expected_args_create(self, cluster_template_id, name=None, master_count=1, node_count=1, create_timeout=60, keypair=None, + docker_volume_size=None, discovery_url=None): expected_args = {} expected_args['name'] = name @@ -65,6 +67,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument): expected_args['create_timeout'] = create_timeout expected_args['discovery_url'] = discovery_url expected_args['keypair'] = keypair + expected_args['docker_volume_size'] = docker_volume_size return expected_args @@ -90,14 +93,8 @@ class ShellTest(shell_test_base.TestCommandLineArgument): mock_list.return_value = [FakeCluster()] self._test_arg_success( 'cluster-list --fields status,status,status,name', - keyword=('\n| uuid | name | keypair | node_count | ' - 'master_count | status |\n')) - # Output should be - # +------+------+---------+--------------+--------------+--------+ - # | uuid | name | keypair | node_count | master_count | status | - # +------+------+---------+--------------+--------------+--------+ - # | x | x | x | x | x | x | - # +------+------+---------+--------------+--------------+--------+ + keyword=('\n| uuid | name | keypair | docker_volume_size | ' + 'node_count | master_count | status |\n')) expected_args = self._get_expected_args_list() mock_list.assert_called_once_with(**expected_args) @@ -152,6 +149,12 @@ class ShellTest(shell_test_base.TestCommandLineArgument): keypair='x') mock_create.assert_called_with(**expected_args) + self._test_arg_success('cluster-create --cluster-template xxx ' + '--docker-volume-size 20') + expected_args = self._get_expected_args_create('xxx', + docker_volume_size=20) + mock_create.assert_called_with(**expected_args) + self._test_arg_success('cluster-create test ' '--cluster-template xxx') expected_args = self._get_expected_args_create('xxx', @@ -271,6 +274,12 @@ class ShellTest(shell_test_base.TestCommandLineArgument): self._mandatory_arg_error) mock_create.assert_not_called() + @mock.patch('magnumclient.v1.clusters.ClusterManager.create') + def test_cluster_create_failure_only_docker_volume_size(self, mock_create): + self._test_arg_failure('cluster-create --docker_volume_size 20', + self._mandatory_arg_error) + mock_create.assert_not_called() + @mock.patch('magnumclient.v1.clusters.ClusterManager.create') def test_cluster_create_failure_only_node_count(self, mock_create): self._test_arg_failure('cluster-create --node-count 1', diff --git a/magnumclient/tests/v1/test_clustertemplates.py b/magnumclient/tests/v1/test_clustertemplates.py index aa88f1ba..7b4d35af 100644 --- a/magnumclient/tests/v1/test_clustertemplates.py +++ b/magnumclient/tests/v1/test_clustertemplates.py @@ -61,7 +61,7 @@ CLUSTERTEMPLATE2 = { 'network_driver': 'flannel', 'volume_driver': 'cinder', 'dns_nameserver': '8.8.1.2', - 'docker_volume_size': '50', + 'docker_volume_size': '71', 'docker_storage_driver': 'overlay', 'coe': 'kubernetes', 'labels': 'key2=val2,key22=val22', @@ -385,6 +385,24 @@ class ClusterTemplateManagerTest(testtools.TestCase): self.assertEqual(CLUSTERTEMPLATE1['docker_storage_driver'], cluster_template.docker_storage_driver) + def test_clustertemplate_create_with_docker_volume_size(self): + cluster_template_with_docker_volume_size = dict() + cluster_template_with_docker_volume_size.update(CREATE_CLUSTERTEMPLATE) + cluster_template_with_docker_volume_size['docker_volume_size'] = 11 + + cluster_template = self.mgr.create( + **cluster_template_with_docker_volume_size) + expect = [ + ('POST', '/v1/clustertemplates', {}, + cluster_template_with_docker_volume_size), + ] + self.assertEqual(expect, self.api.calls) + self.assertTrue(cluster_template) + self.assertEqual(CLUSTERTEMPLATE1['docker_volume_size'], + cluster_template.docker_volume_size) + self.assertEqual(CLUSTERTEMPLATE1['docker_storage_driver'], + cluster_template.docker_storage_driver) + def test_clustertemplate_create_fail(self): CREATE_CLUSTERTEMPLATE_FAIL = copy.deepcopy(CREATE_CLUSTERTEMPLATE) CREATE_CLUSTERTEMPLATE_FAIL["wrong_key"] = "wrong" diff --git a/magnumclient/v1/clusters.py b/magnumclient/v1/clusters.py index 5f41c1fb..a88a826f 100644 --- a/magnumclient/v1/clusters.py +++ b/magnumclient/v1/clusters.py @@ -19,6 +19,7 @@ CREATION_ATTRIBUTES = baseunit.CREATION_ATTRIBUTES CREATION_ATTRIBUTES.append('cluster_template_id') CREATION_ATTRIBUTES.append('create_timeout') CREATION_ATTRIBUTES.append('keypair') +CREATION_ATTRIBUTES.append('docker_volume_size') class Cluster(baseunit.BaseTemplate): diff --git a/magnumclient/v1/clusters_shell.py b/magnumclient/v1/clusters_shell.py index d75e1ab3..b89336a1 100644 --- a/magnumclient/v1/clusters_shell.py +++ b/magnumclient/v1/clusters_shell.py @@ -70,7 +70,8 @@ def do_cluster_list(cs, args): sort_key=args.sort_key, sort_dir=args.sort_dir) columns = [ - 'uuid', 'name', 'keypair', 'node_count', 'master_count', 'status' + 'uuid', 'name', 'keypair', 'docker_volume_size', 'node_count', + 'master_count', 'status' ] columns += utils._get_list_table_columns_and_formatters( args.fields, clusters, @@ -108,6 +109,11 @@ def do_cluster_list(cs, args): metavar='', default=None, help=_('Name of the keypair to use for this cluster.')) +@utils.arg('--docker-volume-size', + metavar='', + type=int, + default=None, + help=_('The size in GB for the docker volume to use')) @utils.arg('--node-count', metavar='', type=int, @@ -138,6 +144,7 @@ def do_cluster_create(cs, args): opts['name'] = args.positional_name or args.name opts['cluster_template_id'] = cluster_template.uuid opts['keypair'] = args.keypair + opts['docker_volume_size'] = args.docker_volume_size opts['node_count'] = args.node_count opts['master_count'] = args.master_count opts['discovery_url'] = args.discovery_url