1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-02 03:12:34 +01:00

Fixed run command to the point of invoking the Executor

This commit is contained in:
Sergei Trofimov
2017-02-09 15:38:28 +00:00
parent dc6d9676f2
commit 3d8503b056
11 changed files with 310 additions and 352 deletions

View File

@@ -117,7 +117,7 @@ class CreateWorkloadSubcommand(CreateSubcommand):
'should place the APK file into the workload\'s directory at the ' +
'same level as the __init__.py.')
def execute(self, args): # pylint: disable=R0201
def execute(self, state, args): # pylint: disable=R0201
where = args.path or 'local'
check_name = not args.force

View File

@@ -39,7 +39,7 @@ class ListCommand(Command):
self.parser.add_argument('-p', '--platform', help='Only list results that are supported by '
'the specified platform')
def execute(self, args):
def execute(self, state, args):
filters = {}
if args.name:
filters['name'] = args.name

View File

@@ -78,7 +78,7 @@ class RecordCommand(Command):
args.suffix += "."
# pylint: disable=W0201
def execute(self, args):
def execute(self, state, args):
self.validate_args(args)
self.logger.info("Connecting to device...")

View File

@@ -20,11 +20,13 @@ import shutil
import wlauto
from wlauto import Command, settings
from wlauto.core.execution import Executor
from wlauto.utils.log import add_log_file
from wlauto.core.configuration import RunConfiguration
from wlauto.core import pluginloader
from wlauto.core.configuration.parsers import AgendaParser, ConfigParser, CommandLineArgsParser
from wlauto.core.configuration import RunConfiguration
from wlauto.core.configuration.parsers import AgendaParser, ConfigParser
from wlauto.core.execution import Executor
from wlauto.exceptions import NotFoundError, ConfigError
from wlauto.utils.log import add_log_file
from wlauto.utils.types import toggle_set
class RunCommand(Command):
@@ -32,103 +34,6 @@ class RunCommand(Command):
name = 'run'
description = 'Execute automated workloads on a remote device and process the resulting output.'
def initialize(self, context):
self.parser.add_argument('agenda', metavar='AGENDA',
help="""
Agenda for this workload automation run. This defines which
workloads will be executed, how many times, with which
tunables, etc. See example agendas in {} for an example of
how this file should be structured.
""".format(os.path.dirname(wlauto.__file__)))
self.parser.add_argument('-d', '--output-directory', metavar='DIR', default=None,
help="""
Specify a directory where the output will be generated. If
the directory already exists, the script will abort unless -f
option (see below) is used, in which case the contents of the
directory will be overwritten. If this option is not specified,
then {} will be used instead.
""".format("settings.default_output_directory")) # TODO: Fix this!
self.parser.add_argument('-f', '--force', action='store_true',
help="""
Overwrite output directory if it exists. By default, the script
will abort in this situation to prevent accidental data loss.
""")
self.parser.add_argument('-i', '--id', action='append', dest='only_run_ids', metavar='ID',
help="""
Specify a workload spec ID from an agenda to run. If this is
specified, only that particular spec will be run, and other
workloads in the agenda will be ignored. This option may be
used to specify multiple IDs.
""")
self.parser.add_argument('--disable', action='append', dest='instruments_to_disable',
metavar='INSTRUMENT', help="""
Specify an instrument to disable from the command line. This
equivalent to adding "~{metavar}" to the instrumentation list in
the agenda. This can be used to temporarily disable a troublesome
instrument for a particular run without introducing permanent
change to the config (which one might then forget to revert).
This option may be specified multiple times.
""")
def execute(self, args):
# STAGE 1: Gather configuratation
env = EnvironmentVars()
args = CommandLineArgs(args)
# STAGE 2.1a: Early WAConfiguration, required to find config files
if env.user_directory:
settings.set("user_directory", env.user_directory)
if env.plugin_paths:
settings.set("plugin_paths", env.plugin_paths)
# STAGE 1 continued
# TODO: Check for config.py and convert to yaml, if it fails, warn user.
configs = [ConfigFile(os.path.join(settings.user_directory, 'config.yaml'))]
for c in args.config:
configs.append(ConfigFile(c))
agenda = Agenda(args.agenda)
configs.append(Agenda.config)
# STAGE 2: Sending configuration to the correct place & merging in
# order of priority.
#
# Priorities (lowest to highest):
# - Enviroment Variables
# - config.yaml from `user_directory`
# - config files passed via command line
# (the first specified will be the first to be applied)
# - Agenda
# - Command line configuration e.g. disabled instrumentation.
# STAGE 2.1b: WAConfiguration
for config in configs:
for config_point in settings.configuration.keys():
if hasattr(config, config_point):
settings.set(config_point, config.getattr(config_point))
def _parse_config(self):
pass
def _serialize_raw_config(self, env, args, agenda, configs):
pod = {}
pod['environment_variables'] = env.to_pod()
pod['commandline_arguments'] = args.to_pod()
pod['agenda'] = agenda.to_pod()
pod['config_files'] = [c.to_pod() for c in configs]
return pod
def _serialize_final_config(self):
pass
class OldRunCommand(Command):
name = 'old_run'
description = 'Execute automated workloads on a remote device and process the resulting output.'
def initialize(self, context):
self.parser.add_argument('agenda', metavar='AGENDA',
help="""
@@ -158,6 +63,7 @@ class OldRunCommand(Command):
used to specify multiple IDs.
""")
self.parser.add_argument('--disable', action='append', dest='instruments_to_disable',
default=[],
metavar='INSTRUMENT', help="""
Specify an instrument to disable from the command line. This
equivalent to adding "~{metavar}" to the instrumentation list in
@@ -167,38 +73,32 @@ class OldRunCommand(Command):
This option may be specified multiple times.
""")
def execute(self, args): # NOQA
def execute(self, state, args):
output_directory = self.set_up_output_directory(args)
add_log_file(os.path.join(output_directory, "run.log"))
config = RunConfiguration(pluginloader)
disabled_instruments = toggle_set(["~{}".format(i)
for i in args.instruments_to_disable])
state.jobs_config.disable_instruments(disabled_instruments)
state.jobs_config.only_run_ids(args.only_run_ids)
parser = AgendaParser()
if os.path.isfile(args.agenda):
agenda = Agenda(args.agenda)
settings.agenda = args.agenda
shutil.copy(args.agenda, config.meta_directory)
parser.load_from_path(state, args.agenda)
else:
self.logger.debug('{} is not a file; assuming workload name.'.format(args.agenda))
agenda = Agenda()
agenda.add_workload_entry(args.agenda)
try:
pluginloader.get_workload(args.agenda)
agenda = {'workloads': [{'name': args.agenda}]}
parser.load(state, agenda, 'CMDLINE_ARGS')
except NotFoundError:
msg = 'Agenda file "{}" does not exist, and there no workload '\
'with that name.\nYou can get a list of available '\
'by running "wa list workloads".'
raise ConfigError(msg.format(args.agenda))
for filepath in settings.config_paths:
config.load_config(filepath)
if args.instruments_to_disable:
if 'instrumentation' not in agenda.config:
agenda.config['instrumentation'] = []
for itd in args.instruments_to_disable:
self.logger.debug('Updating agenda to disable {}'.format(itd))
agenda.config['instrumentation'].append('~{}'.format(itd))
basename = 'config_'
for file_number, path in enumerate(settings.config_paths, 1):
file_ext = os.path.splitext(path)[1]
shutil.copy(path, os.path.join(config.meta_directory,
basename + str(file_number) + file_ext))
executor = Executor(config)
executor.execute(agenda, selectors={'ids': args.only_run_ids})
executor = Executor()
# TODO: fix executor
# executor.execute(state, selectors={'ids': args.only_run_ids})
def set_up_output_directory(self, args):
if args.output_directory:

View File

@@ -40,7 +40,7 @@ class ShowCommand(Command):
help='''The name of the plugin for which information will
be shown.''')
def execute(self, args):
def execute(self, state, args):
# pylint: disable=unpacking-non-sequence
plugin = pluginloader.get_plugin_class(args.name)
out = StringIO()