|
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 StartDiscovery(BaseActionAliasTestCase): |
|
19
|
|
|
action_alias_name = "start_discovery" |
|
20
|
|
|
|
|
21
|
|
|
def test_start_discovery(self): |
|
22
|
|
|
format_string = self.action_alias_db.formats[0]['representation'][0] |
|
23
|
|
|
format_strings = self.action_alias_db.get_format_strings() |
|
24
|
|
|
|
|
25
|
|
|
command = "orion start discovery name run-import nodes 192.168.1.1 snmp public,private platform orion" # NOQA |
|
26
|
|
|
expected_parameters = { |
|
27
|
|
|
'name': "run-import", |
|
28
|
|
|
'nodes': "192.168.1.1", |
|
29
|
|
|
'poller': 'primary', |
|
30
|
|
|
'snmp_communities': "public,private", |
|
31
|
|
|
'platform': "orion" |
|
32
|
|
|
} |
|
33
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
34
|
|
|
command=command, |
|
35
|
|
|
parameters=expected_parameters) |
|
36
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
37
|
|
|
format_strings=format_strings, |
|
38
|
|
|
command=command) |
|
39
|
|
|
|
|
40
|
|
|
def test_start_discovery_poller(self): |
|
41
|
|
|
format_string = self.action_alias_db.formats[0]['representation'][0] |
|
42
|
|
|
format_strings = self.action_alias_db.get_format_strings() |
|
43
|
|
|
|
|
44
|
|
|
command = "orion start discovery name run-import nodes 192.168.1.1 snmp public,private platform orion poller2" # NOQA |
|
45
|
|
|
expected_parameters = { |
|
46
|
|
|
'name': "run-import", |
|
47
|
|
|
'nodes': "192.168.1.1", |
|
48
|
|
|
'poller': 'poller2', |
|
49
|
|
|
'snmp_communities': "public,private", |
|
50
|
|
|
'platform': "orion" |
|
51
|
|
|
} |
|
52
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
53
|
|
|
command=command, |
|
54
|
|
|
parameters=expected_parameters) |
|
55
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
56
|
|
|
format_strings=format_strings, |
|
57
|
|
|
command=command) |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
class NcmConfigDownloadActionAliasTestCase(BaseActionAliasTestCase): |
|
61
|
|
|
action_alias_name = 'ncm_config_download' |
|
62
|
|
|
|
|
63
|
|
|
def test_ncm_config_download_alias(self): |
|
64
|
|
|
format_string = self.action_alias_db.formats[0]['representation'][0] |
|
65
|
|
|
format_strings = self.action_alias_db.get_format_strings() |
|
66
|
|
|
|
|
67
|
|
|
command = "orion ncm config-download orion router1" |
|
68
|
|
|
expected_parameters = { |
|
69
|
|
|
'platform': 'orion', |
|
70
|
|
|
'node': 'router1' |
|
71
|
|
|
} |
|
72
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
73
|
|
|
command=command, |
|
74
|
|
|
parameters=expected_parameters) |
|
75
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
76
|
|
|
format_strings=format_strings, |
|
77
|
|
|
command=command) |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
class NodeStatusActionAliasTestCase(BaseActionAliasTestCase): |
|
81
|
|
|
action_alias_name = 'node_status' |
|
82
|
|
|
|
|
83
|
|
|
def test_node_status_alias(self): |
|
84
|
|
|
format_strings = self.action_alias_db.get_format_strings() |
|
85
|
|
|
|
|
86
|
|
|
format_string = self.action_alias_db.formats[0]['representation'][0] |
|
87
|
|
|
command = "orion node status orion router1" |
|
88
|
|
|
expected_parameters = { |
|
89
|
|
|
'platform': 'orion', |
|
90
|
|
|
'node': 'router1' |
|
91
|
|
|
} |
|
92
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
93
|
|
|
command=command, |
|
94
|
|
|
parameters=expected_parameters) |
|
95
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
96
|
|
|
format_strings=format_strings, |
|
97
|
|
|
command=command) |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
class NodeCreateActionAliasTestCase(BaseActionAliasTestCase): |
|
101
|
|
|
action_alias_name = 'node_create' |
|
102
|
|
|
|
|
103
|
|
|
def test_node_create_alias(self): |
|
104
|
|
|
format_strings = self.action_alias_db.get_format_strings() |
|
105
|
|
|
|
|
106
|
|
|
# First Format 'orion node create' |
|
107
|
|
|
format_string = self.action_alias_db.formats[0]['representation'][0] |
|
108
|
|
|
command = """ |
|
109
|
|
|
orion node create router1 ip 192.168.0.1 snmp read platform orion |
|
110
|
|
|
""" |
|
111
|
|
|
expected_parameters = { |
|
112
|
|
|
'ip_address': "192.168.0.1", |
|
113
|
|
|
'node': 'router1', |
|
114
|
|
|
'platform': 'orion', |
|
115
|
|
|
'poller': 'primary', |
|
116
|
|
|
'std_community': 'read' |
|
117
|
|
|
} |
|
118
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
119
|
|
|
command=command, |
|
120
|
|
|
parameters=expected_parameters) |
|
121
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
122
|
|
|
format_strings=format_strings, |
|
123
|
|
|
command=command) |
|
124
|
|
|
|
|
125
|
|
|
command = """ |
|
126
|
|
|
orion node create router1 ip 192.168.0.1 platform orion poller1 |
|
127
|
|
|
""" |
|
128
|
|
|
expected_parameters = { |
|
129
|
|
|
'ip_address': "192.168.0.1", |
|
130
|
|
|
'node': 'router1', |
|
131
|
|
|
'platform': 'orion', |
|
132
|
|
|
'poller': 'poller1', |
|
133
|
|
|
'std_community': None |
|
134
|
|
|
} |
|
135
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
136
|
|
|
command=command, |
|
137
|
|
|
parameters=expected_parameters) |
|
138
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
139
|
|
|
format_strings=format_strings, |
|
140
|
|
|
command=command) |
|
141
|
|
|
|
|
142
|
|
|
command = "orion node create router1 ip 192.168.0.1 snmp read" |
|
143
|
|
|
expected_parameters = { |
|
144
|
|
|
'ip_address': "192.168.0.1", |
|
145
|
|
|
'node': 'router1', |
|
146
|
|
|
'platform': None, |
|
147
|
|
|
'poller': 'primary', |
|
148
|
|
|
'std_community': 'read' |
|
149
|
|
|
} |
|
150
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
151
|
|
|
command=command, |
|
152
|
|
|
parameters=expected_parameters) |
|
153
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
154
|
|
|
format_strings=format_strings, |
|
155
|
|
|
command=command) |
|
156
|
|
|
|
|
157
|
|
|
command = "orion node create router1 ip 192.168.0.1" |
|
158
|
|
|
expected_parameters = { |
|
159
|
|
|
'ip_address': "192.168.0.1", |
|
160
|
|
|
'node': 'router1', |
|
161
|
|
|
'platform': None, |
|
162
|
|
|
'poller': 'primary', |
|
163
|
|
|
'std_community': None |
|
164
|
|
|
} |
|
165
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
166
|
|
|
command=command, |
|
167
|
|
|
parameters=expected_parameters) |
|
168
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
169
|
|
|
format_strings=format_strings, |
|
170
|
|
|
command=command) |
|
171
|
|
|
|
|
172
|
|
|
# Second format 'create orion node' |
|
173
|
|
|
format_string = self.action_alias_db.formats[1]['representation'][0] |
|
174
|
|
|
|
|
175
|
|
|
command = """ |
|
176
|
|
|
create orion node router1 at 192.168.0.1 with read on orion poller1 |
|
177
|
|
|
""" |
|
178
|
|
|
expected_parameters = { |
|
179
|
|
|
'ip_address': "192.168.0.1", |
|
180
|
|
|
'node': 'router1', |
|
181
|
|
|
'platform': 'orion', |
|
182
|
|
|
'poller': 'poller1', |
|
183
|
|
|
'std_community': 'read' |
|
184
|
|
|
} |
|
185
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
186
|
|
|
command=command, |
|
187
|
|
|
parameters=expected_parameters) |
|
188
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
189
|
|
|
format_strings=format_strings, |
|
190
|
|
|
command=command) |
|
191
|
|
|
|
|
192
|
|
|
command = "create orion node router1 at 192.168.0.1 with read" |
|
193
|
|
|
expected_parameters = { |
|
194
|
|
|
'ip_address': "192.168.0.1", |
|
195
|
|
|
'node': 'router1', |
|
196
|
|
|
'platform': None, |
|
197
|
|
|
'poller': 'primary', |
|
198
|
|
|
'std_community': 'read' |
|
199
|
|
|
} |
|
200
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
201
|
|
|
command=command, |
|
202
|
|
|
parameters=expected_parameters) |
|
203
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
204
|
|
|
format_strings=format_strings, |
|
205
|
|
|
command=command) |
|
206
|
|
|
|
|
207
|
|
|
command = "create orion node router1 at 192.168.0.1 on orion" |
|
208
|
|
|
expected_parameters = { |
|
209
|
|
|
'ip_address': "192.168.0.1", |
|
210
|
|
|
'node': 'router1', |
|
211
|
|
|
'platform': 'orion', |
|
212
|
|
|
'poller': 'primary', |
|
213
|
|
|
'std_community': None |
|
214
|
|
|
} |
|
215
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
216
|
|
|
command=command, |
|
217
|
|
|
parameters=expected_parameters) |
|
218
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
219
|
|
|
format_strings=format_strings, |
|
220
|
|
|
command=command) |
|
221
|
|
|
|
|
222
|
|
|
command = "create orion node router1 at 192.168.0.1" |
|
223
|
|
|
expected_parameters = { |
|
224
|
|
|
'ip_address': "192.168.0.1", |
|
225
|
|
|
'node': 'router1', |
|
226
|
|
|
'platform': None, |
|
227
|
|
|
'poller': 'primary', |
|
228
|
|
|
'std_community': None |
|
229
|
|
|
} |
|
230
|
|
|
self.assertExtractedParametersMatch(format_string=format_string, |
|
231
|
|
|
command=command, |
|
232
|
|
|
parameters=expected_parameters) |
|
233
|
|
|
self.assertCommandMatchesExactlyOneFormatString( |
|
234
|
|
|
format_strings=format_strings, |
|
235
|
|
|
command=command) |
|
236
|
|
|
|