Completed
Push — master ( f1a13c...e53aa3 )
by Tomaz
20s
created

NodeStatusTestCase.test_run_basic_config()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
15
from mock import MagicMock
16
17
from orion_base_action_test_case import OrionBaseActionTestCase
18
19
from node_status import NodeStatus
20
21
__all__ = [
22
    'NodeStatusTestCase'
23
]
24
25
26
class NodeStatusTestCase(OrionBaseActionTestCase):
27
    __test__ = True
28
    action_cls = NodeStatus
29
30
    def test_run_connect_fail(self):
31
        action = self.setup_connect_fail()
32
        self.assertRaises(ValueError, action.run, "router1", "orion")
33
34
    def test_run_node_not_found(self):
35
        action = self.setup_query_blank_results()
36
        self.assertRaises(ValueError, action.run, "router1", "orion")
37
38
    def test_run_node_status_up(self):
39
        expected = {'node': 'router1 (NodeId: 1; ip: 192.168.0.1)',
40
                    'status': "Up",
41
                    'color': "#00ad52"}
42
43
        query_data = []
44
        query_data.append(self.query_npm_node)
45
        query_data.append(self.query_ncm_node)
46
        query_data.append({'results': [{'Status': 1}]})
47
48
        action = self.get_action_instance(config=self.full_config)
49
        action.connect = MagicMock(return_value=True)
50
        action.query = MagicMock(side_effect=query_data)
51
52
        result = action.run("router1", "orion")
53
        self.assertEqual(result, expected)
54
55
    def test_run_node_status_down(self):
56
        expected = {'node': 'router1 (NodeId: 1; ip: 192.168.0.1)',
57
                    'status': "Down",
58
                    'color': "#eb0000"}
59
60
        query_data = []
61
        query_data.append(self.query_npm_node)
62
        query_data.append(self.query_ncm_node)
63
        query_data.append({'results': [{'Status': 2}]})
64
65
        action = self.get_action_instance(config=self.full_config)
66
        action.connect = MagicMock(return_value=True)
67
        action.query = MagicMock(side_effect=query_data)
68
69
        result = action.run("router1", "orion")
70
        self.assertEqual(result, expected)
71
72
    def test_run_node_status_unknown(self):
73
        expected = {'node': 'router1 (NodeId: 1; ip: 192.168.0.1)',
74
                    'status': "Unknown",
75
                    'color': None}
76
77
        query_data = []
78
        query_data.append(self.query_npm_node)
79
        query_data.append(self.query_ncm_node)
80
        query_data.append({'results': [{'Status': 0}]})
81
82
        action = self.get_action_instance(config=self.full_config)
83
        action.connect = MagicMock(return_value=True)
84
        action.query = MagicMock(side_effect=query_data)
85
86
        result = action.run("router1", "orion")
87
        self.assertEqual(result, expected)
88
89
    def test_run_node_status_warning(self):
90
        expected = {'node': 'router1 (NodeId: 1; ip: 192.168.0.1)',
91
                    'status': "Warning",
92
                    'color': "#e89e0e"}
93
94
        query_data = []
95
        query_data.append(self.query_npm_node)
96
        query_data.append(self.query_ncm_node)
97
        query_data.append({'results': [{'Status': 3}]})
98
99
        action = self.get_action_instance(config=self.full_config)
100
        action.connect = MagicMock(return_value=True)
101
        action.query = MagicMock(side_effect=query_data)
102
103
        result = action.run("router1", "orion")
104
        self.assertEqual(result, expected)
105