From bfa290680c3bc445246d85cca9b54cf12f67a248 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 13 Mar 2015 17:23:13 +0300 Subject: [PATCH] Make polling interval configurable Also cleanup in agent code and in config template Change-Id: I5ad6867336421bbb0e2e8d97de865bf42d2ef774 --- etc/shaker.conf | 25 ++----------------------- shaker/agent/agent.py | 40 ++++++++++++++-------------------------- shaker/engine/config.py | 13 ++++++------- 3 files changed, 22 insertions(+), 56 deletions(-) diff --git a/etc/shaker.conf b/etc/shaker.conf index e1ba3f7..7033648 100644 --- a/etc/shaker.conf +++ b/etc/shaker.conf @@ -91,9 +91,8 @@ # env[SHAKER_SERVER_ENDPOINT]. (string value) #server_endpoint = -# -# From shaker.engine.config -# +# How frequently the agent polls server, in seconds (integer value) +#polling_interval = 10 # Authentication URL, defaults to env[OS_AUTH_URL]. (string value) #os_auth_url = @@ -123,10 +122,6 @@ # value) #flavor_name = shaker-flavor -# -# From shaker.engine.config -# - # Scenario file name, defaults to env[SHAKER_SCENARIO]. (string value) #scenario = @@ -134,10 +129,6 @@ # value) #output = -# -# From shaker.engine.config -# - # Report template in Jinja format (string value) #report_template = shaker/resources/report_template.jinja2 @@ -145,23 +136,11 @@ # report is printed to stdout. (string value) #report = -# -# From shaker.engine.config -# - # File to read test results from, defaults to env[SHAKER_INPUT]. (string value) #input = -# -# From shaker.engine.config -# - # Agent unique id, defaults to env[SHAKER_AGENT_ID]. (string value) #agent_id = -# -# From shaker.engine.config -# - # Heat template for the image builder. (string value) #image_builder_template = shaker/resources/image_builder_template.yaml diff --git a/shaker/agent/agent.py b/shaker/agent/agent.py index ec1bf6c..dbc5107 100644 --- a/shaker/agent/agent.py +++ b/shaker/agent/agent.py @@ -19,9 +19,11 @@ import time from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging +import sys import zmq from shaker.engine import config +from shaker.engine import utils LOG = logging.getLogger(__name__) @@ -54,29 +56,12 @@ def send_reply(socket, agent_id, result): def main(): - # init conf and logging - conf = cfg.CONF - conf.register_cli_opts(config.COMMON_OPTS) - conf.register_cli_opts(config.AGENT_OPTS) - conf.register_opts(config.COMMON_OPTS) - conf.register_opts(config.AGENT_OPTS) - logging.register_options(conf) - logging.set_defaults() - - try: - conf(project='shaker') - except cfg.RequiredOptError as e: - print('Error: %s' % e) - conf.print_usage() - exit(1) - - logging.setup(conf, 'shaker') - LOG.info('Logging enabled') + utils.init_config_and_logging(config.COMMON_OPTS + config.AGENT_OPTS) endpoint = cfg.CONF.server_endpoint - + polling_interval = cfg.CONF.polling_interval agent_id = cfg.CONF.agent_id - LOG.info('My instance id is: %s', agent_id) + LOG.info('My id is: %s', agent_id) context = zmq.Context() LOG.info('Connecting to server: %s', endpoint) @@ -98,20 +83,23 @@ def main(): # do something useful command_stdout, command_stderr = processutils.execute( - *shlex.split(command)) + *shlex.split(command), check_exit_code=False) send_reply(socket, agent_id, { 'stdout': command_stdout, 'stderr': command_stderr, }) + elif task['operation'] == 'configure': + if 'polling_interval' in task: + polling_interval = task.get('polling_interval') - time.sleep(10) + time.sleep(polling_interval) except BaseException as e: - if not isinstance(e, KeyboardInterrupt): + if isinstance(e, KeyboardInterrupt): + LOG.info('The process is interrupted') + sys.exit(3) + else: LOG.exception(e) - finally: - LOG.info('Shutting down') - if __name__ == "__main__": main() diff --git a/shaker/engine/config.py b/shaker/engine/config.py index 919ffb6..8b7597b 100644 --- a/shaker/engine/config.py +++ b/shaker/engine/config.py @@ -25,6 +25,9 @@ COMMON_OPTS = [ required=True, help='Address for server connections (host:port), ' 'defaults to env[SHAKER_SERVER_ENDPOINT].'), + cfg.IntOpt('polling-interval', + default=10, + help='How frequently the agent polls server, in seconds') ] OPENSTACK_OPTS = [ @@ -119,10 +122,6 @@ IMAGE_BUILDER_OPTS = [ def list_opts(): - yield (None, copy.deepcopy(COMMON_OPTS)) - yield (None, copy.deepcopy(OPENSTACK_OPTS)) - yield (None, copy.deepcopy(SERVER_OPTS)) - yield (None, copy.deepcopy(REPORT_OPTS)) - yield (None, copy.deepcopy(INPUT_OPTS)) - yield (None, copy.deepcopy(AGENT_OPTS)) - yield (None, copy.deepcopy(IMAGE_BUILDER_OPTS)) + all_opts = (COMMON_OPTS + OPENSTACK_OPTS + SERVER_OPTS + REPORT_OPTS + + INPUT_OPTS + AGENT_OPTS + IMAGE_BUILDER_OPTS) + yield (None, copy.deepcopy(all_opts))