Set --labels default to None on cluster create

Set the default value for --labels to None, so the cluster template value is
used when no explicit labels argument is given on cluster create.

Closes-Bug: #1697651
Change-Id: I284db3f32cd5c8b6541d60c2a86d7d693ffbedea
This commit is contained in:
Ricardo Rocha 2017-10-09 11:54:17 +00:00
parent 58ae37ea03
commit 5e9f07b77c
5 changed files with 26 additions and 5 deletions

View File

@ -74,7 +74,6 @@ class CreateCluster(command.Command):
parser.add_argument('--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 '
'template. May be used multiple times.'))

View File

@ -110,7 +110,7 @@ class FakeClusterTemplate(object):
ct_info = {
'links': [],
'insecure_registry': None,
'labels': {},
'labels': None,
'updated_at': None,
'floating_ip_enabled': True,
'fixed_subnet': None,

View File

@ -43,7 +43,6 @@ class TestClusterCreate(TestCluster):
'create_timeout': 60,
'discovery_url': None,
'docker_volume_size': None,
'labels': {},
'flavor_id': None,
'keypair': None,
'master_count': 1,
@ -94,6 +93,29 @@ class TestClusterCreate(TestCluster):
self.assertRaises(magnum_fakes.MagnumParseException,
self.check_parser, self.cmd, arglist, verifylist)
def test_cluster_create_with_labels(self):
"""Verifies labels are properly parsed when given as argument."""
expected_args = self._default_args
expected_args['labels'] = {
'arg1': 'value1', 'arg2': 'value2'
}
arglist = [
'--cluster-template', self._cluster.cluster_template_id,
'--labels', 'arg1=value1',
'--labels', 'arg2=value2',
self._cluster.name
]
verifylist = [
('cluster_template', self._cluster.cluster_template_id),
('labels', ['arg1=value1', 'arg2=value2']),
('name', self._cluster.name)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.clusters_mock.create.assert_called_with(**expected_args)
class TestClusterDelete(TestCluster):

View File

@ -59,7 +59,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
master_count=1, node_count=1,
create_timeout=60, keypair=None,
docker_volume_size=None,
labels={},
labels=None,
discovery_url=None):
expected_args = {}
expected_args['name'] = name

View File

@ -106,7 +106,7 @@ def do_cluster_list(cs, args):
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=[],
action='append',
help=_('Arbitrary labels in the form of key=value pairs '
'to associate with a cluster. '
'May be used multiple times.'))