summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Rocha <rocha.porto@gmail.com>2017-06-12 09:50:27 +0000
committerRicardo Rocha <rocha.porto@gmail.com>2017-09-27 12:16:47 +0000
commit57dc025007615bcab04c3f010c7c704778cf255b (patch)
tree8b1dc828cfd47c9bca41290b5bbb7d8aa00eaf49
parent31dc867725d93dad0369a15525b068ee6d5534b0 (diff)
Add --labels for cluster-create
Add a labels override parameter on cluster-create to override the value present on the cluster template. Partial-Bug: #1697651 Depends-On: I8990c78433dcbbca5bc4aa121678b02636346802 Change-Id: I39f3423f6889ce93021248223600e342f4217cec
Notes
Notes (review): Code-Review+2: Spyros Trigazis (strigazi) <strigazi@gmail.com> Code-Review+2: Madhuri Kumari <madhuri.kumari@intel.com> Workflow+1: Spyros Trigazis (strigazi) <strigazi@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 27 Sep 2017 12:35:15 +0000 Reviewed-on: https://review.openstack.org/473343 Project: openstack/python-magnumclient Branch: refs/heads/master
-rw-r--r--magnumclient/tests/v1/test_clusters.py11
-rw-r--r--magnumclient/tests/v1/test_clusters_shell.py14
-rw-r--r--magnumclient/v1/clusters.py1
-rw-r--r--magnumclient/v1/clusters_shell.py7
4 files changed, 33 insertions, 0 deletions
diff --git a/magnumclient/tests/v1/test_clusters.py b/magnumclient/tests/v1/test_clusters.py
index c4426db..dc1a100 100644
--- a/magnumclient/tests/v1/test_clusters.py
+++ b/magnumclient/tests/v1/test_clusters.py
@@ -274,6 +274,17 @@ class ClusterManagerTest(testtools.TestCase):
274 self.assertEqual(expect, self.api.calls) 274 self.assertEqual(expect, self.api.calls)
275 self.assertTrue(cluster) 275 self.assertTrue(cluster)
276 276
277 def test_cluster_create_with_labels(self):
278 cluster_with_labels = dict()
279 cluster_with_labels.update(CREATE_CLUSTER)
280 cluster_with_labels['labels'] = "key=val"
281 cluster = self.mgr.create(**cluster_with_labels)
282 expect = [
283 ('POST', '/v1/clusters', {}, cluster_with_labels),
284 ]
285 self.assertEqual(expect, self.api.calls)
286 self.assertTrue(cluster)
287
277 def test_cluster_create_with_discovery_url(self): 288 def test_cluster_create_with_discovery_url(self):
278 cluster_with_discovery = dict() 289 cluster_with_discovery = dict()
279 cluster_with_discovery.update(CREATE_CLUSTER) 290 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 fd7f568..866e514 100644
--- a/magnumclient/tests/v1/test_clusters_shell.py
+++ b/magnumclient/tests/v1/test_clusters_shell.py
@@ -27,6 +27,7 @@ class FakeCluster(Cluster):
27 self.uuid = kwargs.get('uuid', 'x') 27 self.uuid = kwargs.get('uuid', 'x')
28 self.keypair = kwargs.get('keypair', 'x') 28 self.keypair = kwargs.get('keypair', 'x')
29 self.docker_volume_size = kwargs.get('docker_volume_size', 3) 29 self.docker_volume_size = kwargs.get('docker_volume_size', 3)
30 self.labels = kwargs.get('labels', 'key=val')
30 self.name = kwargs.get('name', 'x') 31 self.name = kwargs.get('name', 'x')
31 self.cluster_template_id = kwargs.get('cluster_template_id', 'x') 32 self.cluster_template_id = kwargs.get('cluster_template_id', 'x')
32 self.stack_id = kwargs.get('stack_id', 'x') 33 self.stack_id = kwargs.get('stack_id', 'x')
@@ -58,6 +59,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
58 master_count=1, node_count=1, 59 master_count=1, node_count=1,
59 create_timeout=60, keypair=None, 60 create_timeout=60, keypair=None,
60 docker_volume_size=None, 61 docker_volume_size=None,
62 labels={},
61 discovery_url=None): 63 discovery_url=None):
62 expected_args = {} 64 expected_args = {}
63 expected_args['name'] = name 65 expected_args['name'] = name
@@ -69,6 +71,8 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
69 expected_args['keypair'] = keypair 71 expected_args['keypair'] = keypair
70 if docker_volume_size is not None: 72 if docker_volume_size is not None:
71 expected_args['docker_volume_size'] = docker_volume_size 73 expected_args['docker_volume_size'] = docker_volume_size
74 if labels is not None:
75 expected_args['labels'] = labels
72 76
73 return expected_args 77 return expected_args
74 78
@@ -154,6 +158,11 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
154 '--docker-volume-size 20') 158 '--docker-volume-size 20')
155 expected_args = self._get_expected_args_create('xxx', 159 expected_args = self._get_expected_args_create('xxx',
156 docker_volume_size=20) 160 docker_volume_size=20)
161
162 self._test_arg_success('cluster-create --cluster-template xxx '
163 '--labels key=val')
164 expected_args = self._get_expected_args_create('xxx',
165 labels={'key': 'val'})
157 mock_create.assert_called_with(**expected_args) 166 mock_create.assert_called_with(**expected_args)
158 167
159 self._test_arg_success('cluster-create test ' 168 self._test_arg_success('cluster-create test '
@@ -282,6 +291,11 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
282 mock_create.assert_not_called() 291 mock_create.assert_not_called()
283 292
284 @mock.patch('magnumclient.v1.clusters.ClusterManager.create') 293 @mock.patch('magnumclient.v1.clusters.ClusterManager.create')
294 def test_cluster_create_failure_only_labels(self, mock_create):
295 self._test_arg_failure('cluster-create --labels key=val',
296 self._mandatory_arg_error)
297
298 @mock.patch('magnumclient.v1.clusters.ClusterManager.create')
285 def test_cluster_create_failure_only_node_count(self, mock_create): 299 def test_cluster_create_failure_only_node_count(self, mock_create):
286 self._test_arg_failure('cluster-create --node-count 1', 300 self._test_arg_failure('cluster-create --node-count 1',
287 self._mandatory_arg_error) 301 self._mandatory_arg_error)
diff --git a/magnumclient/v1/clusters.py b/magnumclient/v1/clusters.py
index a88a826..163f30b 100644
--- a/magnumclient/v1/clusters.py
+++ b/magnumclient/v1/clusters.py
@@ -20,6 +20,7 @@ CREATION_ATTRIBUTES.append('cluster_template_id')
20CREATION_ATTRIBUTES.append('create_timeout') 20CREATION_ATTRIBUTES.append('create_timeout')
21CREATION_ATTRIBUTES.append('keypair') 21CREATION_ATTRIBUTES.append('keypair')
22CREATION_ATTRIBUTES.append('docker_volume_size') 22CREATION_ATTRIBUTES.append('docker_volume_size')
23CREATION_ATTRIBUTES.append('labels')
23 24
24 25
25class Cluster(baseunit.BaseTemplate): 26class Cluster(baseunit.BaseTemplate):
diff --git a/magnumclient/v1/clusters_shell.py b/magnumclient/v1/clusters_shell.py
index 3e95fb5..0480214 100644
--- a/magnumclient/v1/clusters_shell.py
+++ b/magnumclient/v1/clusters_shell.py
@@ -105,6 +105,11 @@ def do_cluster_list(cs, args):
105 metavar='<docker-volume-size>', 105 metavar='<docker-volume-size>',
106 type=int, 106 type=int,
107 help=_('The size in GB for the docker volume to use')) 107 help=_('The size in GB for the docker volume to use'))
108@utils.arg('--labels', metavar='<KEY1=VALUE1,KEY2=VALUE2;KEY3=VALUE3...>',
109 action='append', default=[],
110 help=_('Arbitrary labels in the form of key=value pairs '
111 'to associate with a cluster. '
112 'May be used multiple times.'))
108@utils.arg('--node-count', 113@utils.arg('--node-count',
109 metavar='<node-count>', 114 metavar='<node-count>',
110 type=int, 115 type=int,
@@ -137,6 +142,8 @@ def do_cluster_create(cs, args):
137 opts['keypair'] = args.keypair 142 opts['keypair'] = args.keypair
138 if args.docker_volume_size is not None: 143 if args.docker_volume_size is not None:
139 opts['docker_volume_size'] = args.docker_volume_size 144 opts['docker_volume_size'] = args.docker_volume_size
145 if args.labels is not None:
146 opts['labels'] = magnum_utils.handle_labels(args.labels)
140 opts['node_count'] = args.node_count 147 opts['node_count'] = args.node_count
141 opts['master_count'] = args.master_count 148 opts['master_count'] = args.master_count
142 opts['discovery_url'] = args.discovery_url 149 opts['discovery_url'] = args.discovery_url