=== modified file 'lava/dispatcher/commands.py'
@@ -1,21 +1,20 @@
+import argparse
import logging
import os
import sys
from json_schema_validator.errors import ValidationError
from lava.tool.command import Command
+from lava.tool.errors import CommandError
-from lava_dispatcher.config import get_config
+from lava_dispatcher.config import get_config, get_device_config
from lava_dispatcher.job import LavaTestJob, validate_job_data
-class dispatch(Command):
- """
- Run test scenarios on virtual and physical hardware
- """
-
+class DispatcherCommand(Command):
@classmethod
- def register_arguments(self, parser):
+ def register_arguments(cls, parser):
+ super(DispatcherCommand, cls).register_arguments(parser)
# When we're working inside a virtual environment use venv-relative
# configuration directory. This works well with lava-deployment-tool
# and the directory layout it currently provides but will need to be
@@ -25,17 +24,26 @@
os.environ["VIRTUAL_ENV"], "etc", "lava-dispatcher")
else:
default_config_dir = None
-
+ parser.add_argument(
+ "--config-dir",
+ default=default_config_dir,
+ help="Configuration directory override (currently %(default)s")
+
+
+class dispatch(DispatcherCommand):
+ """
+ Run test scenarios on virtual and physical hardware
+ """
+
+ @classmethod
+ def register_arguments(cls, parser):
+ super(dispatch, cls).register_arguments(parser)
parser.add_argument(
"--oob-fd",
default=None,
type=int,
help="Used internally by LAVA scheduler.")
parser.add_argument(
- "--config-dir",
- default=default_config_dir,
- help="Configuration directory override (currently %(default)s")
- parser.add_argument(
"--validate", action='store_true',
help="Just validate the job file, do not execute any steps.")
parser.add_argument(
@@ -43,7 +51,7 @@
help=("Set the scheduler job identifier. "
"This alters process name for easier debugging"))
parser.add_argument(
- "job-file",
+ "job_file",
metavar="JOB",
help="Test scenario file")
@@ -75,7 +83,7 @@
getproctitle(), self.args.job_id))
# Load the scenario file
- with open(args[0]) as stream:
+ with open(self.args.job_file) as stream:
jobdata = stream.read()
job = LavaTestJob(jobdata, oob_file, config)
@@ -87,3 +95,35 @@
print e
else:
job.run()
+
+
+
+class DeviceCommand(DispatcherCommand):
+
+ @classmethod
+ def register_arguments(cls, parser):
+ super(DeviceCommand, cls).register_arguments(parser)
+ parser.add_argument('device')
+
+ @property
+ def device_config(self):
+ try:
+ return get_device_config(self.args.device, self.args.config_dir)
+ except Exception:
+ raise CommandError("no such device: %s" % self.args.device)
+
+class connect(DeviceCommand):
+
+ def invoke(self):
+ os.execlp(
+ 'sh', 'sh', '-c', self.device_config.get('connection_command'))
+
+class power_cycle(DeviceCommand):
+
+ def invoke(self):
+ command = self.device_config.get('hard_reset_command', '')
+ if not command:
+ raise CommandError(
+ "%s does not have a power cycle command configured" %
+ self.args.device)
+ os.system(command)
=== modified file 'setup.py'
@@ -14,6 +14,8 @@
entry_points="""
[lava.commands]
dispatch = lava.dispatcher.commands:dispatch
+ connect = lava.dispatcher.commands:connect
+ power-cycle = lava.dispatcher.commands:power_cycle
""",
packages=find_packages(),
package_data= {