aboutsummaryrefslogtreecommitdiffstats
path: root/gui/test
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-10-19 15:07:31 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-19 15:07:31 +0000
commitfaee281ab73e49629265fe66dcfdd456d79be2bc (patch)
tree06ee3bba835c903f9b56da0a03205cdd2b775e9c /gui/test
parent891109824b93f3dd7b7f553e3561c2cd17495bf6 (diff)
parent255a77da00dd047ee0c5ab1e849cf7e6ce75ecf6 (diff)
Merge "Adding sample trex example"
Diffstat (limited to 'gui/test')
0 files changed, 0 insertions, 0 deletions
{ color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import threading
import os
import logging

from oslo_serialization import jsonutils

from yardstick.common import constants as consts

LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)


class TaskThread(threading.Thread):

    def __init__(self, target, args, handler):
        super(TaskThread, self).__init__(target=target, args=args)
        self.target = target
        self.args = args
        self.handler = handler

    def run(self):
        if self.handler.__class__.__name__.lower().startswith('v2'):
            self.handler.update_attr(self.args.task_id, {'status': consts.TASK_NOT_DONE})
        else:
            update_data = {'task_id': self.args.task_id, 'status': consts.TASK_NOT_DONE}
            self.handler.insert(update_data)

        LOG.info('Starting run task')
        try:
            data = self.target(self.args)
        except Exception as e:
            LOG.exception('Task Failed')
            update_data = {'status': consts.TASK_FAILED, 'error': str(e)}
            self.handler.update_attr(self.args.task_id, update_data)
        else:
            LOG.info('Task Finished')
            LOG.debug('Result: %s', data)

            if self.handler.__class__.__name__.lower().startswith('v2'):
                new_data = {'status': consts.TASK_DONE, 'result': jsonutils.dumps(data['result'])}
                self.handler.update_attr(self.args.task_id, new_data)
                os.remove(self.args.inputfile[0])
            else:
                data['result'] = jsonutils.dumps(data.get('result', {}))
                self.handler.update_attr(self.args.task_id, data)