def test_get_proper_message(self):
        limits = LimitsMixin()
        limits.messages = [
            {"type": "min", "value": "1", "message": "Message for min_1"},
            {"type": "min", "value": "2", "message": "Message for min_2"},
            {"type": "max", "value": "5", "message": "Message for max_5"},
            {"type": "max", "value": "8", "message": "Message for max_8"},
        ]

        self.assertEqual(limits._get_message("min"), "Message for min_2")

        self.assertEqual(limits._get_message("max"), "Message for max_5")
Beispiel #2
0
    def test_get_proper_message(self):
        limits = LimitsMixin()
        limits.messages = [
            {'type': 'min', 'value': '1', 'message': 'Message for min_1'},
            {'type': 'min', 'value': '2', 'message': 'Message for min_2'},
            {'type': 'max', 'value': '5', 'message': 'Message for max_5'},
            {'type': 'max', 'value': '8', 'message': 'Message for max_8'}
        ]

        self.assertEqual(
            limits._get_message('min'), 'Message for min_2')

        self.assertEqual(
            limits._get_message('max'), 'Message for max_5')
Beispiel #3
0
    def test_get_proper_message(self):
        limits = LimitsMixin()
        limits.messages = [
            {'type': 'min', 'value': '1', 'message': 'Message for min_1'},
            {'type': 'min', 'value': '2', 'message': 'Message for min_2'},
            {'type': 'max', 'value': '5', 'message': 'Message for max_5'},
            {'type': 'max', 'value': '8', 'message': 'Message for max_8'}
        ]

        self.assertEqual(
            limits._get_message('min'), 'Message for min_2')

        self.assertEqual(
            limits._get_message('max'), 'Message for max_5')
Beispiel #4
0
    def test_check_node_limits(self):
        roles = self.data.get('roles_meta')
        attributes = self.data.get('attributes')

        for role, data in six.iteritems(roles):
            result = LimitsMixin().check_node_limits(
                models={'settings': attributes},
                nodes=self.env.nodes,
                role=role,
                limits=data.get('limits'))

            if role == 'cinder':
                self.assertTrue(result.get('valid'))

            if role == 'controller':
                self.assertFalse(result.get('valid'))
                self.assertEqual(
                    result.get('messages'),
                    'Default message')

            if role == 'mongo':
                self.assertFalse(result.get('valid'))
                self.assertEqual(
                    result.get('messages'),
                    'At least 4 MongoDB node can be added if spam')
    def test_check_override(self):
        roles = self.data.get("roles_meta")
        attributes = self.data.get("attributes")

        limits = LimitsMixin()
        # Set nodes count to 4
        limits.count = 4
        limits.limit_reached = True
        limits.models = {"settings": attributes}
        limits.nodes = self.env.nodes
        # Set "cinder" role to working on
        limits.role = "cinder"
        limits.limit_types = ["max"]
        limits.checked_limit_types = {}
        limits.limit_values = {"max": None}
        override_data = roles["cinder"]["limits"]["overrides"][0]

        result = limits._check_override(override_data)
        self.assertEqual(result[0]["message"], "At most one role_1 node can be added")
Beispiel #6
0
    def test_check_override(self):
        roles = self.data.get('roles_meta')
        attributes = self.data.get('attributes')

        limits = LimitsMixin()
        # Set nodes count to 4
        limits.count = 4
        limits.limit_reached = True
        limits.models = {'settings': attributes}
        limits.nodes = self.env.nodes
        # Set "cinder" role to working on
        limits.role = 'cinder'
        limits.limit_types = ['max']
        limits.checked_limit_types = {}
        limits.limit_values = {'max': None}
        override_data = roles['cinder']['limits']['overrides'][0]

        result = limits._check_override(override_data)
        self.assertEqual(
            result[0]['message'], 'At most one role_1 node can be added')
Beispiel #7
0
    def test_check_node_limits(self):
        roles = self.data.get('roles_meta')
        attributes = self.data.get('attributes')

        for role, data in six.iteritems(roles):
            result = LimitsMixin().check_node_limits(
                models={'settings': attributes},
                nodes=self.env.nodes,
                role=role,
                limits=data.get('limits'))

            if role == 'cinder':
                self.assertTrue(result.get('valid'))

            if role == 'controller':
                self.assertFalse(result.get('valid'))
                self.assertEqual(
                    result.get('messages'),
                    'Default message')

            if role == 'mongo':
                self.assertFalse(result.get('valid'))
                self.assertEqual(
                    result.get('messages'),
                    'At least 4 MongoDB node can be added if spam')
    def test_check_node_limits(self):
        roles = self.data.get("roles_meta")
        attributes = self.data.get("attributes")

        for role, data in six.iteritems(roles):
            result = LimitsMixin().check_node_limits(
                models={"settings": attributes}, nodes=self.env.nodes, role=role, limits=data.get("limits")
            )

            if role == "cinder":
                self.assertTrue(result.get("valid"))

            if role == "controller":
                self.assertFalse(result.get("valid"))
                self.assertEqual(result.get("messages"), "Default message")

            if role == "mongo":
                self.assertFalse(result.get("valid"))
                self.assertEqual(result.get("messages"), "At least 4 MongoDB node can be added if spam")
Beispiel #9
0
    def test_check_override(self):
        roles = self.data.get('roles_meta')
        attributes = self.data.get('attributes')

        limits = LimitsMixin()
        # Set nodes count to 4
        limits.count = 4
        limits.limit_reached = True
        limits.models = {'settings': attributes}
        limits.nodes = self.env.nodes
        # Set "cinder" role to working on
        limits.role = 'cinder'
        limits.limit_types = ['max']
        limits.checked_limit_types = {}
        limits.limit_values = {'max': None}
        override_data = roles['cinder']['limits']['overrides'][0]

        result = limits._check_override(override_data)
        self.assertEqual(
            result[0]['message'], 'At most one role_1 node can be added')