diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 475: add a new "devices" api to the dispatcher

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

Commit Message

Andy Doan Dec. 2, 2012, 4:46 a.m. UTC
------------------------------------------------------------
revno: 475
committer: Andy Doan <andy.doan@linaro.org>
branch nick: device-list
timestamp: Fri 2012-11-30 13:14:23 -0600
message:
  add a new "devices" api to the dispatcher
  
  This allows us to know every device configured locally for a given
  LAVA instance.
modified:
  lava/dispatcher/commands.py
  lava_dispatcher/config.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-09-26 02:55:25 +0000
+++ lava/dispatcher/commands.py	2012-11-30 19:14:23 +0000
@@ -1,4 +1,3 @@ 
-import argparse
 import logging
 import os
 import sys
@@ -7,7 +6,7 @@ 
 from lava.tool.command import Command
 from lava.tool.errors import CommandError
 
-from lava_dispatcher.config import get_config, get_device_config
+from lava_dispatcher.config import get_config, get_device_config, get_devices
 from lava_dispatcher.job import LavaTestJob, validate_job_data
 
 
@@ -30,6 +29,15 @@ 
             help="Configuration directory override (currently %(default)s")
 
 
+class devices(DispatcherCommand):
+    """
+    Lists all the configured devices in this LAVA instance.
+    """
+    def invoke(self):
+        for d in get_devices(self.args.config_dir):
+            print d.hostname
+
+
 class dispatch(DispatcherCommand):
     """
     Run test scenarios on virtual and physical hardware
@@ -68,8 +76,8 @@ 
         del logging.root.handlers[:]
         del logging.root.filters[:]
         FORMAT = '<LAVA_DISPATCHER>%(asctime)s %(levelname)s: %(message)s'
-        DATEFMT= '%Y-%m-%d %I:%M:%S %p'
-        logging.basicConfig(format=FORMAT,datefmt=DATEFMT)
+        DATEFMT = '%Y-%m-%d %I:%M:%S %p'
+        logging.basicConfig(format=FORMAT, datefmt=DATEFMT)
         config = get_config(self.args.config_dir)
         logging.root.setLevel(config.logging_level)
 
@@ -100,7 +108,6 @@ 
             job.run()
 
 
-
 class DeviceCommand(DispatcherCommand):
 
     @classmethod
@@ -115,12 +122,14 @@ 
         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.connection_command)
 
+
 class power_cycle(DeviceCommand):
 
     def invoke(self):

=== modified file 'lava_dispatcher/config.py'
--- lava_dispatcher/config.py	2012-11-30 19:13:30 +0000
+++ lava_dispatcher/config.py	2012-11-30 19:14:23 +0000
@@ -191,3 +191,12 @@ 
         logging.warning("Device config for %s is not valid:\n    %s", name, '\n    '.join(report))
 
     return DeviceConfig(real_device_config)
+
+
+def get_devices(config_dir):
+    devices = []
+    devices_dir = os.path.join(config_dir, 'devices')
+    for d in os.listdir(devices_dir):
+        d = os.path.splitext(d)[0]
+        devices.append(get_device_config(d, config_dir))
+    return devices

=== modified file 'setup.py'
--- setup.py	2012-11-21 00:57:15 +0000
+++ setup.py	2012-11-30 19:14:23 +0000
@@ -15,6 +15,7 @@ 
     [lava.commands]
     dispatch = lava.dispatcher.commands:dispatch
     connect = lava.dispatcher.commands:connect
+    devices = lava.dispatcher.commands:devices
     power-cycle = lava.dispatcher.commands:power_cycle
     [lava.signal_handlers]
     add-duration = lava_dispatcher.signals.duration:AddDuration