Commit 3109de52 authored by Peter Chronz's avatar Peter Chronz
Browse files

Fix issues with ioscheduler device and slave autoupdate

parent 576daafa
......@@ -36,3 +36,13 @@ class ConnectionParameters(object):
self.port,
virtual_host=self.vhost)
return pika_params
def to_args(self):
args = ['--port', self.port,
'-v', self.vhost]
if self.username is not None:
args += ['-u', self.username]
if self.password is not None:
args += ['-p', self.password]
args = [str(arg) for arg in args]
return args
......@@ -2,10 +2,10 @@
import logging
def configure_logger(logger):
logger.setLevel(logging.DEBUG)
def configure_logger(logger, level=logging.INFO):
logger.setLevel(level)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setLevel(level)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
......@@ -103,7 +103,7 @@ class SlaveAgent(object):
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'}
......@@ -119,11 +119,17 @@ class SlaveAgent(object):
origin.pull()
def _restart(self):
port = self.port
if port is None:
port = 5672
config_path = self.config_path
os.execl('startslave.py', self.host, port, config_path, self.name)
args = self._create_args()
info_message = 'Restarting slave agent with followings args: {}'.format(args)
logger.info(info_message)
print(args)
os.execl('startslave.py', 'startslave.py', *args)
def _create_args(self):
mandatory_args = [self.connection_params.host, self.config_path, self.name]
optional_args = self.connection_params.to_args()
args = optional_args + mandatory_args
return args
def consume(self):
self._channel.start_consuming()
......
......@@ -71,4 +71,37 @@ class ConnectionParametersTest(unittest.TestCase):
password = credentials.password
self.assertEqual(username, 'guest')
self.assertEqual(password, 'guest')
def test_to_args(self):
connection_params = ConnectionParameters(
username=self.username,
password=self.password,
host=self.host,
port=self.port,
vhost=self.vhost)
args = connection_params.to_args()
expected_args = ['--port', str(self.port),
'-u', self.username, '-p', self.password,
'-v', self.vhost]
self.assertSetEqual(set(args), set(expected_args))
def test_to_args_with_default_settings(self):
connection_params = ConnectionParameters(
username=None,
password=None,
host=self.host,
port=self.port)
args = connection_params.to_args()
expected_args = ['--port', str(self.port),
'-v', '/']
self.assertEqual(args, expected_args)
def test_all_args_are_strings(self):
connection_params = ConnectionParameters(
username=self.username,
password=self.password,
host=self.host,
port=self.port,
vhost=self.vhost)
connection_args = connection_params.to_args()
self.assertTrue(all(type(arg) == str for arg in connection_args))
......@@ -5,14 +5,14 @@ import mock
import datetime
import time
import pika
from actuator.master.controller import Controller
from actuator.plugins import ioscheduler
from actuator.core.connection import ConnectionParameters
class ControllerTest(unittest.TestCase):
test_device = 'sda'
@mock.patch('pika.BlockingConnection')
def test_context_manager(self, connection_type_mock):
self._connection_type_mock = connection_type_mock
......@@ -100,7 +100,7 @@ class ControllerTest(unittest.TestCase):
self._test_config_response(response)
def _choose_new_config(self):
current_config = ioscheduler.IOScheduler().get_state()
current_config = ioscheduler.IOScheduler().get_state(device=self.test_device)
config_space = ['noop', 'deadline', 'cfp']
remaining_options = set(config_space) - set([current_config])
new_config = remaining_options.pop()
......
......@@ -109,7 +109,7 @@ class SlaveAgentTest(unittest.TestCase):
def test_handle_message_with_ioscheduler_get_state(self,
connection_type_mock):
plugin = ioscheduler.IOScheduler()
self._test_handle_message_with_plugin_get_state(plugin)
self._test_handle_message_with_plugin_get_state(plugin, device='sda')
def _test_handle_message_with_plugin_get_state(self, plugin, **kwargs):
body = {'method': 'get_state', 'args': [plugin.name], 'kwargs': kwargs}
......
......@@ -8,7 +8,7 @@ from actuator.core import log
logger = logging.getLogger('')
log.configure_logger(logger)
log.configure_logger(logger, level=logging.ERROR)
class ActuatorTest(unittest.TestCase):
......
......@@ -23,7 +23,7 @@ class GetStateTest(ActuatorTest):
def _get_ioscheduler_state(self):
plugin = ioscheduler.IOScheduler()
expected_state = plugin.get_state(device='sda')
plugin_state = self._get_plugin_state(plugin.name, expected_state)
plugin_state = self._get_plugin_state(plugin.name, expected_state, device='sda')
self.assertEquals(plugin_state, expected_state)
def _get_taskset_state(self):
......
......@@ -27,6 +27,8 @@ def parse_args():
if __name__ == '__main__':
log.configure_logger(logger)
args = parse_args()
info_message = 'Starting slave agents with parameters {}'.format(args)
logger.info(info_message)
host = args.host
port = args.port
settings_path = args.settings_path
......
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