Completed
Pull Request — master (#466)
by
unknown
02:38
created

test_node_status_alias()   A

Complexity

Conditions 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 16
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 st2tests.base import BaseActionAliasTestCase
16
17
18
class NcmConfigDownloadActionAliasTestCase(BaseActionAliasTestCase):
19
    action_alias_name = 'ncm_config_download'
20
21
    def test_ncm_config_download_alias(self):
22
        format_string = self.action_alias_db.formats[0]['representation'][0]
23
24
        command = "orion ncm config-download orion router1"
25
        expected_parameters = {
26
            'platform': 'orion',
27
            'node': 'router1'
28
        }
29
        self.assertExtractedParametersMatch(format_string=format_string,
30
                                            command=command,
31
                                            parameters=expected_parameters)
32
33
34
class NodeStatusActionAliasTestCase(BaseActionAliasTestCase):
35
    action_alias_name = 'node_status'
36
37
    def test_node_status_alias(self):
38
        format_string = self.action_alias_db.formats[0]['representation'][0]
39
        format_strings = self.action_alias_db.formats[0]['representation']
40
41
        command = "orion node status orion router1"
42
        expected_parameters = {
43
            'platform': 'orion',
44
            'node': 'router1'
45
        }
46
        self.assertExtractedParametersMatch(format_string=format_string,
47
                                            command=command,
48
                                            parameters=expected_parameters)
49
50
        self.assertCommandMatchesExactlyOneFormatString(
51
            format_strings=format_strings,
52
            command=command)
53
54
55
class NodeCreateActionAliasTestCase(BaseActionAliasTestCase):
56
    action_alias_name = 'node_create'
57
58
    def test_node_create_alias(self):
59
        format_strings = []
60
61
        print self.action_alias_db.formats
62
        for repre in self.action_alias_db.formats:
63
            for string in repre['representation']:
64
                format_strings.append(string)
65
66
        # First Format 'orion node create'
67
        format_string = self.action_alias_db.formats[0]['representation'][0]
68
69
        command = "orion node create router1 ip 192.168.0.1 snmp read platform orion"
70
        expected_parameters = {
71
            'ip_address': "192.168.0.1",
72
            'node': 'router1',
73
            'platform': 'orion',
74
            'std_community': 'read'
75
        }
76
        self.assertExtractedParametersMatch(format_string=format_string,
77
                                            command=command,
78
                                            parameters=expected_parameters)
79
80
        self.assertCommandMatchesExactlyOneFormatString(
81
            format_strings=format_strings,
82
            command=command)
83
84
        command = "orion node create router1 ip 192.168.0.1 platform orion"
85
        expected_parameters = {
86
            'ip_address': "192.168.0.1",
87
            'node': 'router1',
88
            'platform': 'orion',
89
            'std_community': None
90
        }
91
        self.assertExtractedParametersMatch(format_string=format_string,
92
                                            command=command,
93
                                            parameters=expected_parameters)
94
95
        self.assertCommandMatchesExactlyOneFormatString(
96
            format_strings=format_strings,
97
            command=command)
98
99
        command = "orion node create router1 ip 192.168.0.1 snmp read"
100
        expected_parameters = {
101
            'ip_address': "192.168.0.1",
102
            'node': 'router1',
103
            'platform': None,
104
            'std_community': 'read'
105
        }
106
        self.assertExtractedParametersMatch(format_string=format_string,
107
                                            command=command,
108
                                            parameters=expected_parameters)
109
110
        self.assertCommandMatchesExactlyOneFormatString(
111
            format_strings=format_strings,
112
            command=command)
113
114
        command = "orion node create router1 ip 192.168.0.1"
115
        expected_parameters = {
116
            'ip_address': "192.168.0.1",
117
            'node': 'router1',
118
            'platform': None,
119
            'std_community': None
120
        }
121
        self.assertExtractedParametersMatch(format_string=format_string,
122
                                            command=command,
123
                                            parameters=expected_parameters)
124
125
        self.assertCommandMatchesExactlyOneFormatString(
126
            format_strings=format_strings,
127
            command=command)
128
129
        # Second format 'create orion node'
130
        format_string = self.action_alias_db.formats[1]['representation'][0]
131
132
        command = "create orion node router1 at 192.168.0.1 with read on poller1"
133
        expected_parameters = {
134
            'ip_address': "192.168.0.1",
135
            'node': 'router1',
136
            'platform': 'poller1',
137
            'std_community': 'read'
138
        }
139
        self.assertExtractedParametersMatch(format_string=format_string,
140
                                            command=command,
141
                                            parameters=expected_parameters)
142
143
        self.assertCommandMatchesExactlyOneFormatString(
144
            format_strings=format_strings,
145
            command=command)
146
147
        command = "create orion node router1 at 192.168.0.1 with read"
148
        expected_parameters = {
149
            'ip_address': "192.168.0.1",
150
            'node': 'router1',
151
            'platform': None,
152
            'std_community': 'read'
153
        }
154
        self.assertExtractedParametersMatch(format_string=format_string,
155
                                            command=command,
156
                                            parameters=expected_parameters)
157
158
        self.assertCommandMatchesExactlyOneFormatString(
159
            format_strings=format_strings,
160
            command=command)
161
162
        command = "create orion node router1 at 192.168.0.1 on poller1"
163
        expected_parameters = {
164
            'ip_address': "192.168.0.1",
165
            'node': 'router1',
166
            'platform': 'poller1',
167
            'std_community': None
168
        }
169
        self.assertExtractedParametersMatch(format_string=format_string,
170
                                            command=command,
171
                                            parameters=expected_parameters)
172
173
        self.assertCommandMatchesExactlyOneFormatString(
174
            format_strings=format_strings,
175
            command=command)
176
177
        command = "create orion node router1 at 192.168.0.1"
178
        expected_parameters = {
179
            'ip_address': "192.168.0.1",
180
            'node': 'router1',
181
            'platform': None,
182
            'std_community': None
183
        }
184
        self.assertExtractedParametersMatch(format_string=format_string,
185
                                            command=command,
186
                                            parameters=expected_parameters)
187
188
        self.assertCommandMatchesExactlyOneFormatString(
189
            format_strings=format_strings,
190
            command=command)
191