79
80
Run requested tests and posts results to the 'adt_results' queue
80
81
for later checking.
82
logger.info('Got: {}'.format(body))
83
83
body['worker'] = self.worker_name
84
logger.info('Received message request: {}'.format(body), extra=body)
85
86
# Run requested tests safely.
86
87
tarball_path = None
97
98
'nova', 'extra_args').split()
98
99
adt_kwargs['nova_flavor'] = get_default_testbed_flavor()
99
100
arguments = _make_adt_argument_list(adt_kwargs)
102
'Running adt-run with: {}'.format(
103
' '.join(arguments)), extra=body)
101
104
body['exit_code'] = run_adt(arguments)
106
'Exit code: {}'.format(body['exit_code']), extra=body)
102
107
_create_run_metadata_file(result_dir, body)
103
108
tarball_path = _create_tarball_from_directory(
110
115
upload_tarball_to_swift_container(tarball_path, container_name)
111
116
except Exception as e:
112
117
# Unexpected failures ...
113
logger.error(e, exc_info=True)
114
118
body['exit_code'] = '100'
119
logger.error(e, exc_info=True, extra=body)
117
# TODO: send error logging to result-checker in the message
118
queue = self.connection.SimpleQueue('adt.results.{}'.format(API_VERSION))
121
logger.info('Posting results: {}'.format(body), extra=body)
122
# TODO: send error logging to result-checker in the message.
123
queue = self.connection.SimpleQueue(
124
'adt.results.{}'.format(API_VERSION))
121
127
if tarball_path and os.path.exists(tarball_path):
122
128
os.remove(tarball_path)
130
logger.info('Done!', extra=body)
127
133
def _create_run_metadata_file(directory, request):
175
181
Returns the exit code from adt-run.
177
# TODO: We probably want something more clever here:
179
subprocess.check_call(['adt-run'] + arguments)
180
except subprocess.CalledProcessError as e:
182
# TODO: filter log content to avoid leaking cloud credentials.
183
cmd_line = ['adt-run'] + arguments
184
proc = subprocess.Popen(
185
cmd_line, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
187
return proc.returncode
187
190
def _make_adt_argument_list(request_configuration):
250
253
return tarball_path
256
def configure_logging(config):
257
root_logger = logging.getLogger()
258
root_logger.setLevel(logging.INFO)
260
# Silence requests logging, which is created by nova, keystone and swift.
261
requests_logger = logging.getLogger('requests')
262
requests_logger.setLevel(logging.ERROR)
264
# If there is no ./logs directory, fallback to stderr.
265
log_path = os.path.abspath(os.path.join(__file__, '../../logs/app.log'))
266
log_dir = os.path.dirname(log_path)
267
if os.path.exists(log_dir):
268
handler = logging.FileHandler(log_path)
270
print("'logs' directory '{}' does not exist, using stderr "
271
"for app log.".format(log_dir))
272
handler = logging.StreamHandler()
274
handler.setFormatter(
276
'%(asctime)s %(name)s %(levelname)s: %(message)s'
279
root_logger.addHandler(handler)
281
if 'logstash' in config:
282
root_logger.addHandler(
283
logstash.LogstashHandler(
284
config['logstash']['host'],
285
int(config['logstash']['port']),
286
int(config['logstash']['version'])
254
setup_logging(loglevel='DEBUG', loggers=[''])
256
292
parser = argparse.ArgumentParser(
257
293
description='ADT cloud worker ...')
258
294
parser.add_argument('-c', '--conf', default='adt-service.conf',