Add runner_async endpoint to salnado

Feature for #25427
This commit is contained in:
Thomas Jackson 2015-07-15 09:05:16 -07:00
parent b043fa9b05
commit bc32f66b98
2 changed files with 31 additions and 1 deletions

View file

@ -216,6 +216,7 @@ class SaltClientsMixIn(object):
'local_batch': local_client.cmd_batch,
'local_async': local_client.run_job,
'runner': salt.runner.RunnerClient(opts=self.application.opts).async,
'runner_async': None, # empty, since we use the same client as `runner`
}
return SaltClientsMixIn.__saltclients
@ -717,7 +718,7 @@ class SaltAPIHandler(BaseSaltAPIHandler, SaltClientsMixIn): # pylint: disable=W
Content-Type: application/json
Content-Legnth: 83
{"clients": ["local", "local_batch", "local_async","runner"], "return": "Welcome"}
{"clients": ["local", "local_batch", "local_async", "runner", "runner_async"], "return": "Welcome"}
'''
ret = {"clients": self.saltclients.keys(),
"return": "Welcome"}
@ -1031,6 +1032,15 @@ class SaltAPIHandler(BaseSaltAPIHandler, SaltClientsMixIn): # pylint: disable=W
except TimeoutException:
raise tornado.gen.Return('Timeout waiting for runner to execute')
@tornado.gen.coroutine
def _disbatch_runner_async(self, chunk):
'''
Disbatch runner client_async commands
'''
f_call = {'args': [chunk['fun'], chunk]}
pub_data = self.saltclients['runner'](chunk['fun'], chunk)
raise tornado.gen.Return(pub_data)
class MinionSaltAPIHandler(SaltAPIHandler): # pylint: disable=W0223
'''

View file

@ -54,6 +54,7 @@ class TestSaltAPIHandler(SaltnadoTestCase):
response_obj = json.loads(response.body)
self.assertEqual(response_obj['clients'],
['runner',
'runner_async',
'local_async',
'local',
'local_batch']
@ -303,6 +304,25 @@ class TestSaltAPIHandler(SaltnadoTestCase):
self.assertEqual(len(response_obj['return']), 1)
self.assertEqual(set(response_obj['return'][0]), set(['minion', 'sub_minion']))
# runner_async tests
def test_simple_local_runner_async_post(self):
low = [{'client': 'runner_async',
'fun': 'manage.up',
}]
response = self.fetch('/',
method='POST',
body=json.dumps(low),
headers={'Content-Type': self.content_type_map['json'],
saltnado.AUTH_TOKEN_HEADER: self.token['token']},
connect_timeout=10,
request_timeout=10,
)
response_obj = json.loads(response.body)
self.assertIn('return', response_obj)
self.assertEqual(1, len(response_obj['return']))
self.assertIn('jid', response_obj['return'][0])
self.assertIn('tag', response_obj['return'][0])
@skipIf(HAS_TORNADO is False, 'Tornado must be installed to run these tests')
@skipIf(HAS_ZMQ_IOLOOP is False, 'PyZMQ version must be >= 14.0.1 to run these tests.')