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
This commit is contained in:
Ricardo Rocha 2017-06-12 09:50:27 +00:00
parent 31dc867725
commit 57dc025007
4 changed files with 33 additions and 0 deletions

View File

@ -274,6 +274,17 @@ class ClusterManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(cluster)
def test_cluster_create_with_labels(self):
cluster_with_labels = dict()
cluster_with_labels.update(CREATE_CLUSTER)
cluster_with_labels['labels'] = "key=val"
cluster = self.mgr.create(**cluster_with_labels)
expect = [
('POST', '/v1/clusters', {}, cluster_with_labels),
]
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)

View File

@ -27,6 +27,7 @@ class FakeCluster(Cluster):
self.uuid = kwargs.get('uuid', 'x')
self.keypair = kwargs.get('keypair', 'x')
self.docker_volume_size = kwargs.get('docker_volume_size', 3)
self.labels = kwargs.get('labels', 'key=val')
self.name = kwargs.get('name', 'x')
self.cluster_template_id = kwargs.get('cluster_template_id', 'x')
self.stack_id = kwargs.get('stack_id', 'x')
@ -58,6 +59,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
master_count=1, node_count=1,
create_timeout=60, keypair=None,
docker_volume_size=None,
labels={},
discovery_url=None):
expected_args = {}
expected_args['name'] = name
@ -69,6 +71,8 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args['keypair'] = keypair
if docker_volume_size is not None:
expected_args['docker_volume_size'] = docker_volume_size
if labels is not None:
expected_args['labels'] = labels
return expected_args
@ -154,6 +158,11 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
'--docker-volume-size 20')
expected_args = self._get_expected_args_create('xxx',
docker_volume_size=20)
self._test_arg_success('cluster-create --cluster-template xxx '
'--labels key=val')
expected_args = self._get_expected_args_create('xxx',
labels={'key': 'val'})
mock_create.assert_called_with(**expected_args)
self._test_arg_success('cluster-create test '
@ -281,6 +290,11 @@ 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_labels(self, mock_create):
self._test_arg_failure('cluster-create --labels key=val',
self._mandatory_arg_error)
@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',

View File

@ -20,6 +20,7 @@ CREATION_ATTRIBUTES.append('cluster_template_id')
CREATION_ATTRIBUTES.append('create_timeout')
CREATION_ATTRIBUTES.append('keypair')
CREATION_ATTRIBUTES.append('docker_volume_size')
CREATION_ATTRIBUTES.append('labels')
class Cluster(baseunit.BaseTemplate):

View File

@ -105,6 +105,11 @@ def do_cluster_list(cs, args):
metavar='<docker-volume-size>',
type=int,
help=_('The size in GB for the docker volume to use'))
@utils.arg('--labels', metavar='<KEY1=VALUE1,KEY2=VALUE2;KEY3=VALUE3...>',
action='append', default=[],
help=_('Arbitrary labels in the form of key=value pairs '
'to associate with a cluster. '
'May be used multiple times.'))
@utils.arg('--node-count',
metavar='<node-count>',
type=int,
@ -137,6 +142,8 @@ def do_cluster_create(cs, args):
opts['keypair'] = args.keypair
if args.docker_volume_size is not None:
opts['docker_volume_size'] = args.docker_volume_size
if args.labels is not None:
opts['labels'] = magnum_utils.handle_labels(args.labels)
opts['node_count'] = args.node_count
opts['master_count'] = args.master_count
opts['discovery_url'] = args.discovery_url