-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathtest_runner.py
146 lines (121 loc) · 3.85 KB
/
test_runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# coding: utf-8
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing libs
from tests.support.unit import TestCase
from tests.support.mixins import AdaptedConfigurationTestCaseMixin
# Import Salt libs
import salt.runner
class RunnerModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
# This is really an integration test since it needs a salt-master running
eauth_creds = {
'username': 'saltdev_auto',
'password': 'saltdev',
'eauth': 'auto',
}
def setUp(self):
'''
Configure an eauth user to test with
'''
self.runner = salt.runner.RunnerClient(self.get_config('client_config'))
def test_eauth(self):
'''
Test executing master_call with lowdata
The choice of using error.error for this is arbitrary and should be
changed to some mocked function that is more testing friendly.
'''
low = {
'client': 'runner',
'fun': 'error.error',
}
low.update(self.eauth_creds)
self.runner.master_call(**low)
def test_token(self):
'''
Test executing master_call with lowdata
The choice of using error.error for this is arbitrary and should be
changed to some mocked function that is more testing friendly.
'''
import salt.auth
auth = salt.auth.LoadAuth(self.get_config('client_config'))
token = auth.mk_token(self.eauth_creds)
self.runner.master_call(**{
'client': 'runner',
'fun': 'error.error',
'token': token['token'],
})
def test_cmd_sync(self):
low = {
'client': 'runner',
'fun': 'error.error',
}
low.update(self.eauth_creds)
self.runner.cmd_sync(low)
def test_cmd_async(self):
low = {
'client': 'runner',
'fun': 'error.error',
}
low.update(self.eauth_creds)
self.runner.cmd_async(low)
def test_cmd_sync_w_arg(self):
low = {
'fun': 'test.arg',
'foo': 'Foo!',
'bar': 'Bar!',
}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low)
self.assertEqual(ret['kwargs']['foo'], 'Foo!')
self.assertEqual(ret['kwargs']['bar'], 'Bar!')
def test_wildcard_auth(self):
low = {
'username': 'the_s0und_of_t3ch',
'password': 'willrockyou',
'eauth': 'auto',
'fun': 'test.arg',
'foo': 'Foo!',
'bar': 'Bar!',
}
self.runner.cmd_sync(low)
def test_full_return_kwarg(self):
low = {'fun': 'test.arg'}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low, full_return=True)
self.assertIn('success', ret['data'])
def test_cmd_sync_arg_kwarg_parsing(self):
low = {
'client': 'runner',
'fun': 'test.arg',
'arg': [
'foo',
'bar=off',
'baz={qux: 123}'
],
'kwarg': {
'quux': 'Quux',
},
'quuz': 'on',
}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low)
self.assertEqual(ret, {
'args': ['foo'],
'kwargs': {
'bar': False,
'baz': {
'qux': 123,
},
'quux': 'Quux',
'quuz': 'on',
},
})
def test_invalid_kwargs_are_ignored(self):
low = {
'client': 'runner',
'fun': 'test.metasyntactic',
'thiskwargisbad': 'justpretendimnothere',
}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low)
self.assertEqual(ret[0], 'foo')