Enhance validation for node groups handlers

Since the ability of node reconfiguration was added in 8.0 we need to
forbid adding node groups for cluster of version < 8.0 that
contains at least one deployed node.

Change-Id: If08622d5f60585073eb3a8e24e079f615f150448
Closes-Bug: #1530355
This commit is contained in:
Artem Roma 2016-01-06 12:27:37 +02:00
parent 3dbc827430
commit c292959585
2 changed files with 39 additions and 0 deletions

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from distutils.version import StrictVersion
from nailgun.api.v1.validators.base import BasicValidator
from nailgun import consts
from nailgun.db import db
@ -69,12 +71,28 @@ class NodeGroupValidator(BasicValidator):
"'default' flag for node group cannot be changed"
)
@classmethod
def _check_for_deployed_nodes(cls, cluster):
"""Check if nodes reconfiguration is allowed for cluster"""
env_version = cluster.release.environment_version
if not StrictVersion(env_version) >= StrictVersion('8.0'):
if any(objects.Cluster.get_nodes_by_status(
cluster,
consts.NODE_STATUSES.ready)):
raise errors.NotAllowed(
"Reconfiguration of nodes after the "
"deployment is allowed only for "
"environments 8.0 or greater."
)
@classmethod
def validate(cls, data):
data = cls.validate_json(data)
cluster = objects.Cluster.get_by_uid(
data['cluster_id'], fail_if_not_found=True)
cls._check_for_deployed_nodes(cluster)
cls._validate_unique_name(data)
if data.get('is_default'):

View File

@ -251,6 +251,27 @@ class TestNodeGroups(BaseIntegrationTest):
objects.NodeGroupCollection.get_by_cluster_id(
self.cluster['id']).count(), 2)
def test_creation_not_allowed_when_ready_nodes(self):
cluster = self.env.create(
release_kwargs={'version': '1111-7.0'},
nodes_kwargs=[{'status': consts.NODE_STATUSES.ready},
{'status': consts.NODE_STATUSES.error}]
)
resp = self.env.create_node_group(expect_errors=True,
cluster_id=cluster['id'])
self.assertEqual(resp.status_code, 403)
self.assertEqual(resp.json_body['message'],
"Reconfiguration of nodes after the "
"deployment is allowed only for "
"environments 8.0 or greater."
)
def test_creation_allowed_when_ready_nodes_for_80(self):
self.env.create_node(cluster_id=self.cluster['id'],
status=consts.NODE_STATUSES.ready)
resp = self.env.create_node_group(cluster_id=self.cluster['id'])
self.assertEqual(resp.status_code, 201)
def test_nodegroup_rename(self):
self.assertEquals(
1,