diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 309: add "lava connect" and "lava power-cycle" commands

Message ID 20120601020017.23363.74358.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson June 1, 2012, 2 a.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 309 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Fri 2012-06-01 13:56:05 +1200
message:
  add "lava connect" and "lava power-cycle" commands
modified:
  lava/dispatcher/commands.py
  setup.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava/dispatcher/commands.py'
--- lava/dispatcher/commands.py	2012-03-19 13:29:52 +0000
+++ lava/dispatcher/commands.py	2012-06-01 01:49:28 +0000
@@ -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'
--- setup.py	2012-05-08 22:06:32 +0000
+++ setup.py	2012-06-01 01:49:28 +0000
@@ -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= {