def ping_call_params(self): self.msg = message.Message(body=test_ctxt.MSG['body'], agent=test_ctxt.MSG['agent'], config=self.config) return dict(agent='discovery', action='ping', msg=self.msg, config=self.config)
def test_message_raises_improperly_configured(config, filter_): '''Tests :py:class:`pymco.message.Message` raises :py:exc:`pymco.exc.ImproperlyConfigured` if configuration doesn't contain all required information.''' with pytest.raises(exc.ImproperlyConfigured): message.Message(body='ping', agent='discovery', config={}, filter_=dict(filter_))
def msg(config, filter_): '''Creates a new :py:class:`pymco.message.Message` instance.''' # Importing here since py-cov will ignore code imported on conftest files # imports from pymco import message with mock.patch('time.time') as time: with mock.patch('hashlib.sha1') as sha1: time.return_value = ctxt.MSG['msgtime'] sha1.return_value.hexdigest.return_value = ctxt.MSG['requestid'] msg_ = message.Message(body=ctxt.MSG['body'], agent=ctxt.MSG['agent'], filter_=filter_, config=config) time.assert_called_once_with() sha1.return_value.hexdigest.assert_called_once_with() return msg_
def test_symbols(self): body = { ':agent': 'demo', ':action': 'mounts', ':caller': 'user=rafaduran', ':data': { ':process_results': True }, } msg = message.Message(body=body, agent='demo', config=self.config) simple_rpc = rpc.SimpleAction(msg=msg, agent='demo', action='mounts', config=self.config) result = simple_rpc.call(timeout=15) assert len(result) == 1 res_msg = result[0] assert res_msg[':senderagent'] == 'demo' assert res_msg[':requestid'] == msg[':requestid']
def msg_with_data(config, filter_): """Creates :py:class:`pymco.message.Message` instance with some data.""" # Importing here since py-cov will ignore code imported on conftest files # imports from pymco import message with mock.patch('time.time') as time: with mock.patch('hashlib.sha1') as sha1: time.return_value = ctxt.MSG['msgtime'] sha1.return_value.hexdigest.return_value = ctxt.MSG['requestid'] body = { ':action': 'runonce', ':data': { ':noop': True, ':process_results': True }, ':ssl_msgtime': 1421878604, ':ssl_ttl': 60, } return message.Message(body=body, agent='puppet', filter_=filter_, config=config)
def msg_no_filter(config): '''Creates a new :py:class:`pymco.message.Message` instance.''' return message.Message(body=ctxt.MSG['body'], agent=ctxt.MSG['agent'], config=config)
# coding: utf-8 import logging from pymco import config from pymco import rpc from pymco import message logging.basicConfig() config = config.Config.from_configfile('client.cfg') msg = message.Message(body='ping', agent='discovery', config=config) action = rpc.SimpleAction(config=config, msg=msg, agent='discovery') print action.call()
def msg(config): return message.Message(body=test_ctxt.MSG['body'], agent=test_ctxt.MSG['agent'], config=config)