Commit 42ff6b7a authored by Peter Chronz's avatar Peter Chronz
Browse files

Implement dynamic message handline in slave agent

parent 1ed5fe7f
......@@ -7,6 +7,7 @@ import pika
import git
from actuator.slave.core import MessageDispatcher
from actuator.core.exceptions import ActuatorException
logger = logging.getLogger(__name__)
......@@ -78,17 +79,32 @@ class SlaveAgent(object):
def _handle_agent_message(self, method):
response = None
if method == 'ping':
response = {'type': 'agent_discovery_response', 'name': self.name}
if method == 'list_active_plugins':
active_plugins = self.settings['plugins'].keys()
response = {'type': 'list_active_plugins_response', 'plugins': active_plugins}
if method == 'get_version':
sha = git.Repo('.').head.object.hexsha
response = {'type': 'get_version_response', 'sha': sha}
if method == 'autoupdate':
self._autoupdate()
response = {'type': 'autoupdate_response'}
allowed_methods = ['ping', 'list_active_plugins', 'get_version', 'autoupdate']
handler_method_name = 'handle_{}'.format(method)
handler_method = getattr(self, handler_method_name)
response = handler_method()
if method not in allowed_methods:
error_message = u'Method {} is not allowed'.format(method)
raise ActuatorException(error_message)
return response
def handle_ping(self):
response = {'type': 'agent_discovery_response', 'name': self.name}
return response
def handle_list_active_plugins(self):
active_plugins = self.settings['plugins'].keys()
response = {'type': 'list_active_plugins_response', 'plugins': active_plugins}
return response
def handle_get_version(self):
sha = git.Repo('.').head.object.hexsha
response = {'type': 'get_version_response', 'sha': sha}
return response
def handle_autoupdate(self):
self._autoupdate()
response = {'type': 'autoupdate_response'}
return response
def _autoupdate(self):
......
......@@ -71,7 +71,7 @@ class SlaveAgentTest(unittest.TestCase):
ch = mock.MagicMock()
method = mock.MagicMock()
props = mock.MagicMock()
body = {'method': 'foo', 'args': [], 'kwargs': {}}
body = {'method': 'ping', 'args': [], 'kwargs': {}}
body_json = json.dumps(body)
slave._on_request(ch, method, props, body_json)
ch.basic_publish.assert_called()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment