Browse Source

No new NGs for clusters without an api_address

With this change, the nodegroup api controller raises an exception
if the user tries to create a nodegroup in a cluster that does not
have an api_address yet. If the nodegroup is created without the
cluster's API address as an input then the new nodes will not be
able to join the cluster.

Change-Id: If3b168d7f756a055b80d38a4f80cedc97f1b47e8
story: 2006716
task: 37087
tags/10.0.0.0rc1
Theodoros Tsioutsias 10 months ago
parent
commit
23ca0d3c66
3 changed files with 18 additions and 0 deletions
  1. +4
    -0
      magnum/api/controllers/v1/nodegroup.py
  2. +4
    -0
      magnum/common/exception.py
  3. +10
    -0
      magnum/tests/unit/api/controllers/v1/test_nodegroup.py

+ 4
- 0
magnum/api/controllers/v1/nodegroup.py 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,


+ 4
- 0
magnum/common/exception.py 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")

+ 10
- 0
magnum/tests/unit/api/controllers/v1/test_nodegroup.py 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):



Loading…
Cancel
Save