Merge "No new NGs for clusters without an api_address"

This commit is contained in:
Zuul 2019-10-24 08:29:25 +00:00 committed by Gerrit Code Review
commit 476b18fd5e
3 changed files with 18 additions and 0 deletions

View File

@ -292,6 +292,10 @@ class NodeGroupController(base.Controller):
policy.enforce(context, 'nodegroup:create', action='nodegroup:create')
cluster = api_utils.get_resource('Cluster', cluster_id)
# Before we start, we need to check that the cluster has an
# api_address. If not, just fail.
if 'api_address' not in cluster or not cluster.api_address:
raise exception.ClusterAPIAddressUnavailable()
cluster_ngs = [ng.name for ng in cluster.nodegroups]
if nodegroup.name in cluster_ngs:
raise exception.NodeGroupAlreadyExists(name=nodegroup.name,

View File

@ -466,3 +466,7 @@ class NgOperationInProgress(Invalid):
class InvalidClusterTemplateForUpgrade(Conflict):
message = _("Cluster Template is not valid for upgrade: %(reason)s")
class ClusterAPIAddressUnavailable(Conflict):
message = _("Cluster API address is not available yet")

View File

@ -353,6 +353,16 @@ class TestPost(NodeGroupControllerTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(406, response.status_int)
def test_create_ng_cluster_no_api_address(self):
# Remove the api address from the cluster and make sure
# that the request is not accepted.
self.cluster.api_address = None
self.cluster.save()
ng_dict = apiutils.nodegroup_post_data()
response = self.post_json(self.url, ng_dict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_int)
class TestDelete(NodeGroupControllerTest):