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
|
|
|
import yaml |
16
|
|
|
from mock import Mock, MagicMock |
17
|
|
|
|
18
|
|
|
from st2tests.base import BaseActionTestCase |
19
|
|
|
|
20
|
|
|
from list_sdk_verbs import ListSdkVerbs |
21
|
|
|
|
22
|
|
|
__all__ = [ |
23
|
|
|
'ListSdkVerbsTestCase' |
24
|
|
|
] |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class ListSdkVerbsTestCase(BaseActionTestCase): |
28
|
|
|
action_cls = ListSdkVerbs |
29
|
|
|
|
30
|
|
|
def test_run_no_config(self): |
31
|
|
|
self.assertRaises(ValueError, |
32
|
|
|
ListSdkVerbs, |
33
|
|
|
yaml.safe_load( |
34
|
|
|
self.get_fixture_content('blank.yaml'))) |
35
|
|
|
|
36
|
|
|
def test_run_is_instance(self): |
37
|
|
|
action = self.get_action_instance(yaml.safe_load( |
38
|
|
|
self.get_fixture_content('full.yaml'))) |
39
|
|
|
|
40
|
|
|
self.assertIsInstance(action, ListSdkVerbs) |
41
|
|
|
|
42
|
|
|
def test_run_connect_fail(self): |
43
|
|
|
action = self.get_action_instance(yaml.safe_load( |
44
|
|
|
self.get_fixture_content('full.yaml'))) |
45
|
|
|
|
46
|
|
|
action.connect = Mock(side_effect=ValueError( |
47
|
|
|
'Orion host details not in the config.yaml')) |
48
|
|
|
|
49
|
|
|
self.assertRaises(ValueError, |
50
|
|
|
action.run, |
51
|
|
|
"orion") |
52
|
|
|
|
53
|
|
|
def test_run_listsdk_verbs(self): |
54
|
|
|
expected = {'Entities': []} |
55
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
56
|
|
|
'Method': "Unmanage"}) |
57
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
58
|
|
|
'Method': "Remanage"}) |
59
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
60
|
|
|
'Method': "PollNow"}) |
61
|
|
|
|
62
|
|
|
query_data = yaml.safe_load(self.get_fixture_content( |
63
|
|
|
"results_sdk_verbs.yaml")) |
64
|
|
|
|
65
|
|
|
action = self.get_action_instance(yaml.safe_load( |
66
|
|
|
self.get_fixture_content('full.yaml'))) |
67
|
|
|
|
68
|
|
|
action.connect = MagicMock(return_value=True) |
69
|
|
|
action.query = MagicMock(return_value=query_data) |
70
|
|
|
|
71
|
|
|
result = action.run("orion") |
72
|
|
|
|
73
|
|
|
self.assertEqual(result, expected) |
74
|
|
|
|
75
|
|
|
def test_run_listsdk_verbs_filtered(self): |
76
|
|
|
expected = {'Entities': []} |
77
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
78
|
|
|
'Method': "Unmanage"}) |
79
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
80
|
|
|
'Method': "Remanage"}) |
81
|
|
|
expected['Entities'].append({'Entity': "Orion.Nodes", |
82
|
|
|
'Method': "PollNow"}) |
83
|
|
|
|
84
|
|
|
query_data = yaml.safe_load(self.get_fixture_content( |
85
|
|
|
"results_sdk_verbs.yaml")) |
86
|
|
|
|
87
|
|
|
action = self.get_action_instance(yaml.safe_load( |
88
|
|
|
self.get_fixture_content('full.yaml'))) |
89
|
|
|
|
90
|
|
|
action.connect = MagicMock(return_value=True) |
91
|
|
|
action.query = MagicMock(return_value=query_data) |
92
|
|
|
|
93
|
|
|
result = action.run("orion", "PollNow") |
94
|
|
|
|
95
|
|
|
self.assertEqual(result, expected) |
96
|
|
|
|