예제 #1
0
    def test_validate_delete_default_node_group_error(self):
        default_ng = objects.Cluster.get_default_group(self.cluster)

        with self.assertRaises(errors.CannotDelete) as err:
            NodeGroupValidator.validate_delete(data={}, instance=default_ng)

        self.assertEqual(err.exception.message,
                         'Default node group cannot be deleted.')
예제 #2
0
    def test_validate_delete_default_node_group_error(self):
        default_ng = objects.Cluster.get_default_group(self.cluster)

        with self.assertRaises(errors.CannotDelete) as err:
            NodeGroupValidator.validate_delete(data={}, instance=default_ng)

        self.assertEqual(err.exception.message,
                         'Default node group cannot be deleted.')
예제 #3
0
    def test_validate_updating_cluster_id_not_allowed(self):
        ng = objects.Cluster.get_default_group(self.cluster)

        data = json.dumps({'cluster_id': -1, 'name': ng.name})
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate_update(data, ng)

        self.assertEqual(
            err.exception.message,
            "Node group cannot be assigned to other cluster "
            "after creation.")
예제 #4
0
    def test_validate_create_node_group_with_default_flag_fail(self):
        data = json.dumps({
            'cluster_id': self.cluster['id'],
            'name': 'test',
            'is_default': True
        })
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate(data)

        self.assertEqual(err.exception.message,
                         "Default node group is created only by Nailgun.")
예제 #5
0
    def test_validate_updating_cluster_id_not_allowed(self):
        ng = objects.Cluster.get_default_group(self.cluster)

        data = json.dumps({'cluster_id': -1, 'name': ng.name})
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate_update(data, ng)

        self.assertEqual(
            err.exception.message,
            "Node group cannot be assigned to other cluster "
            "after creation."
        )
예제 #6
0
    def test_validate_create_node_group_with_default_flag_fail(self):
        data = json.dumps(
            {'cluster_id': self.cluster['id'],
             'name': 'test',
             'is_default': True}
        )
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate(data)

        self.assertEqual(
            err.exception.message,
            "Default node group is created only by Nailgun."
        )
예제 #7
0
    def test_delete_non_default_node_group_error(self):
        node_group = self.env.create_node_group(api=False,
                                                cluster_id=self.cluster.id)
        self.env.create_node(group_id=node_group.id)
        self.env.create_node(group_id=node_group.id,
                             status=consts.NODE_STATUSES.error)

        with self.assertRaises(errors.CannotDelete) as err:
            NodeGroupValidator.validate_delete(data={}, instance=node_group)

        self.assertEqual(err.exception.message,
                         'Node group can be deleted only when all its nodes '
                         'are in bootstrap state.')
예제 #8
0
    def test_delete_non_default_node_group_error(self):
        node_group = self.env.create_node_group(api=False,
                                                cluster_id=self.cluster.id)
        self.env.create_node(group_id=node_group.id)
        self.env.create_node(group_id=node_group.id,
                             status=consts.NODE_STATUSES.error)

        with self.assertRaises(errors.CannotDelete) as err:
            NodeGroupValidator.validate_delete(data={}, instance=node_group)

        self.assertEqual(err.exception.message,
                         'Node group can be deleted only when all its nodes '
                         'are in bootstrap state.')
예제 #9
0
    def test_validate_updating_node_group_default_flag_not_allowed(self):
        ng = objects.Cluster.get_default_group(self.cluster)

        data = json.dumps({
            'cluster_id': self.cluster['id'],
            'name': ng.name,
            'is_default': not (ng.is_default)
        })
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate_update(data, ng)

        self.assertEqual(err.exception.message,
                         "'default' flag for node group cannot be changed")
예제 #10
0
    def test_validate_updating_node_group_default_flag_not_allowed(self):
        ng = objects.Cluster.get_default_group(self.cluster)

        data = json.dumps(
            {'cluster_id': self.cluster['id'],
             'name': ng.name,
             'is_default': not(ng.is_default)}
        )
        with self.assertRaises(errors.NotAllowed) as err:
            NodeGroupValidator.validate_update(data, ng)

        self.assertEqual(
            err.exception.message,
            "'default' flag for node group cannot be changed"
        )