2013-12-20 03:45:49 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-12-20 03:45:49 +00:00
|
|
|
# Import Salt Testing libs
|
2017-02-27 15:59:04 +00:00
|
|
|
import tests.integration as integration
|
2013-12-20 03:45:49 +00:00
|
|
|
|
|
|
|
# Import Salt libs
|
|
|
|
import salt.runner
|
|
|
|
|
|
|
|
|
2014-10-07 11:19:58 +00:00
|
|
|
class RunnerModuleTest(integration.TestCase, integration.AdaptedConfigurationTestCaseMixIn):
|
2014-07-15 20:09:09 +00:00
|
|
|
eauth_creds = {
|
|
|
|
'username': 'saltdev_auto',
|
|
|
|
'password': 'saltdev',
|
|
|
|
'eauth': 'auto',
|
|
|
|
}
|
|
|
|
|
2013-12-20 03:45:49 +00:00
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Configure an eauth user to test with
|
|
|
|
'''
|
2014-10-07 11:19:58 +00:00
|
|
|
self.runner = salt.runner.RunnerClient(self.get_config('client_config'))
|
2013-12-20 03:45:49 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
'''
|
2014-07-15 20:09:09 +00:00
|
|
|
low = {
|
2013-12-20 03:45:49 +00:00
|
|
|
'client': 'runner',
|
|
|
|
'fun': 'error.error',
|
2014-07-15 20:09:09 +00:00
|
|
|
}
|
|
|
|
low.update(self.eauth_creds)
|
|
|
|
|
|
|
|
self.runner.master_call(**low)
|
2013-12-20 03:45:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-10-07 11:19:58 +00:00
|
|
|
auth = salt.auth.LoadAuth(self.get_config('client_config'))
|
2014-07-15 20:09:09 +00:00
|
|
|
token = auth.mk_token(self.eauth_creds)
|
2013-12-20 03:45:49 +00:00
|
|
|
|
|
|
|
self.runner.master_call(**{
|
|
|
|
'client': 'runner',
|
|
|
|
'fun': 'error.error',
|
|
|
|
'token': token['token'],
|
|
|
|
})
|
|
|
|
|
2014-07-15 20:09:36 +00:00
|
|
|
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)
|
|
|
|
|
2014-10-02 18:00:01 +00:00
|
|
|
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!')
|
|
|
|
|
2014-10-03 00:11:29 +00:00
|
|
|
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)
|
2017-02-18 02:31:57 +00:00
|
|
|
|
|
|
|
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'])
|
2017-03-08 16:04:26 +00:00
|
|
|
|
2017-02-18 01:33:41 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
})
|