Completed
Pull Request — master (#487)
by
unknown
03:03
created

NodeCreateTestCase.test_run_connect_fail()   A

Complexity

Conditions 1

Size

Total Lines 12

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 12
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_create import NodeCreate
20
from lib.utils import is_ip
21
22
23
__all__ = [
24
    'NodeCreateTestCase'
25
]
26
27
28
class NodeCreateTestCase(OrionBaseActionTestCase):
29
    __test__ = True
30
    action_cls = NodeCreate
31
32
    def test_run_is_ip_v4(self):
33
        self.assertTrue(is_ip("172.16.0.1"))
34
        self.assertTrue(is_ip("1762:0:0:0:0:B03:1:AF18"))
35
        self.assertFalse(is_ip("172.16.0.300"))
36
        self.assertFalse(is_ip("1762:%:0:0:0:B03:1:AF18"))
37
38
    def test_run_connect_fail(self):
39
        action = self.setup_connect_fail()
40
        self.assertRaises(ValueError,
41
                          action.run,
42
                          "router1",
43
                          "192.168.0.1",
44
                          "orion",
45
                          None,
46
                          "snmpv2",
47
                          "internal",
48
                          None,
49
                          "snmp")
50
51
    def test_run_node_caption_exists(self):
52
        action = self.setup_node_exists()
53
        self.assertRaises(ValueError,
54
                          action.run,
55
                          "router1",
56
                          "192.168.0.1",
57
                          "orion",
58
                          None,
59
                          "snmpv2",
60
                          "internal",
61
                          None,
62
                          "snmp")
63
64
    def test_run_node_ip_exists(self):
65
        query_data = []
66
        query_data.append(self.query_no_results)
67
        query_data.append(self.query_npm_node)
68
        query_data.append(self.query_ncm_node)
69
70
        action = self.get_action_instance(config=self.full_config)
71
72
        action.connect = MagicMock(return_value=True)
73
        action.query = MagicMock(side_effect=query_data)
74
        action.invoke = MagicMock(return_value=None)
75
        action.create = MagicMock(return_value=None)
76
77
        self.assertRaises(ValueError,
78
                          action.run,
79
                          "router2",
80
                          "192.168.0.1",
81
                          "orion",
82
                          None,
83
                          "snmpv2",
84
                          "internal",
85
                          None,
86
                          "snmp")
87
88
    def test_run_poller_is_none(self):
89
        expected = {'node_id': '6', 'platform': 'orion'}
90
91
        query_data = self.query_no_results
92
93
        action = self.get_action_instance(config=self.full_config)
94
95
        action.connect = MagicMock(return_value=True)
96
        action.query = MagicMock(return_value=query_data)
97
        action.invoke = MagicMock(return_value=None)
98
        action.get_engine_id = MagicMock(return_value=2)
99
        action.create = MagicMock(
100
            return_value="swis://orionr/Orion/Orion.Nodes/NodeID=6")
101
102
        result = action.run("router2",
103
                            "192.168.0.1",
104
                            "orion",
105
                            None,
106
                            "snmpv2",
107
                            "internal",
108
                            None,
109
                            "snmp")
110
        self.assertEqual(result, expected)
111
112
    def test_run_node_additonal_poller(self):
113
        expected = {'node_id': '6', 'platform': 'orion'}
114
115
        query_data = [self.query_no_results,
116
                      self.query_no_results,
117
                      {'results': [{'EngineID': 2}]}]
118
119
        action = self.get_action_instance(config=self.full_config)
120
121
        action.connect = MagicMock(return_value=True)
122
        action.query = MagicMock(side_effect=query_data)
123
        action.invoke = MagicMock(return_value=None)
124
        action.create = MagicMock(
125
            return_value="swis://orionr/Orion/Orion.Nodes/NodeID=6")
126
127
        result = action.run("router2",
128
                            "192.168.0.1",
129
                            "orion",
130
                            "additonal1",
131
                            "snmpv2",
132
                            "internal",
133
                            None,
134
                            "snmp")
135
        self.assertEqual(result, expected)
136