Merge "Fix master_lb_enabled for cluster creation"

This commit is contained in:
Zuul 2021-04-08 08:30:56 +00:00 committed by Gerrit Code Review
commit ab601bd7ab
2 changed files with 43 additions and 4 deletions

View File

@ -159,10 +159,16 @@ class CreateCluster(command.Command):
parser.add_argument(
'--master-lb-enabled',
dest='master_lb_enabled',
action='store_true',
default=False,
help=_('Indicates whether created clusters should have '
'a loadbalancer for API.'))
action='append_const',
default=[],
const=False,
help=_('Enable master LB creation on the new cluster'))
parser.add_argument(
'--master-lb-disabled',
dest='master_lb_enabled',
action='append_const',
const=False,
help=_('Disable master LB creation on the new cluster'))
return parser
@ -215,6 +221,20 @@ class CreateCluster(command.Command):
if parsed_args.master_lb_enabled:
args["master_lb_enabled"] = parsed_args.master_lb_enabled
if len(parsed_args.master_lb_enabled) > 1:
raise exceptions.InvalidAttribute(
'--master-lb-enabled and '
'--master-lb-disabled are '
'mutually exclusive and '
'should be specified only once.')
elif len(parsed_args.master_lb_enabled) == 1:
args['master_lb_enabled'] = parsed_args.master_lb_enabled[0]
if (not args['master_lb_enabled'] and
parsed_args.master_count > 1):
raise exceptions.InvalidAttribute(
'Master node count can only be one if master '
'loadbalancer is disabled.')
cluster = mag_client.clusters.create(**args)
print("Request to create cluster %s accepted"
% cluster.uuid)

View File

@ -125,6 +125,25 @@ class TestClusterCreate(TestCluster):
self.cmd.take_action(parsed_args)
self.clusters_mock.create.assert_called_with(**expected_args)
def test_cluster_create_with_lb_disabled(self):
"""Verifies master lb disabled properly parsed."""
expected_args = self._default_args
expected_args['master_lb_enabled'] = False
arglist = [
'--cluster-template', self._cluster.cluster_template_id,
'--master-lb-disabled',
self._cluster.name
]
verifylist = [
('cluster_template', self._cluster.cluster_template_id),
('master_lb_enabled', [False]),
('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):