diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 168: add a --config-dir option that you can point at a directory containing the lava-dispatcher.conf f...

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

Commit Message

Michael-Doyle Hudson Nov. 28, 2011, 10:16 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-dispatcher/add-config-dir-option/+merge/83684
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 168 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Tue 2011-11-29 09:57:23 +1300
message:
  add a --config-dir option that you can point at a directory containing the lava-dispatcher.conf file and devices directory and so on
added:
  lava_dispatcher/tests/test-config/
  lava_dispatcher/tests/test-config/devices/
  lava_dispatcher/tests/test-config/devices/beaglexm01.conf
  lava_dispatcher/tests/test-config/lava-dispatcher.conf
modified:
  lava-dispatch
  lava_dispatcher/config.py
  lava_dispatcher/context.py
  lava_dispatcher/job.py
  lava_dispatcher/tests/test_config.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-dispatch'
--- lava-dispatch	2011-11-14 04:45:54 +0000
+++ lava-dispatch	2011-11-28 20:13:34 +0000
@@ -33,6 +33,8 @@ 
 parser.add_option(
     "--oob-fd", default=None, type=int, help="Write OOB data to this fd.")
 parser.add_option(
+    "--config-dir", default=None, help="XXX")
+parser.add_option(
     "--validate", action='store_true',
     help="Just validate the job file, do not execute any steps.")
 
@@ -57,11 +59,11 @@ 
 DATEFMT= '%Y-%m-%d %I:%M:%S %p'
 logging.basicConfig(format=FORMAT,datefmt=DATEFMT)
 
-config = get_config("lava-dispatcher")
+config = get_config("lava-dispatcher", options.config_dir)
 logging_level = config.get("LOGGING_LEVEL")
 logging.root.setLevel(int(logging_level))
 
-job = LavaTestJob(jobdata, oob_file)
+job = LavaTestJob(jobdata, oob_file, config)
 
 #FIXME Return status
 if options.validate:

=== modified file 'lava_dispatcher/config.py'
--- lava_dispatcher/config.py	2011-09-12 22:31:47 +0000
+++ lava_dispatcher/config.py	2011-11-28 20:12:01 +0000
@@ -28,10 +28,16 @@ 
     os.path.dirname(__file__), 'default-config')
 
 
-def load_config_paths(name):
-    for directory in [os.path.expanduser("~/.config"),
-                      "/etc/xdg", default_config_path]:
-        path = os.path.join(directory, name)
+def load_config_paths(name, config_dir):
+    if config_dir is None:
+        paths = [
+            os.path.join(path, name) for path in [
+                os.path.expanduser("~/.config"),
+                "/etc/xdg",
+                default_config_path]]
+    else:
+        paths = [config_dir, os.path.join(default_config_path, name)]
+    for path in paths:
         if os.path.isdir(path):
             yield path
 
@@ -44,7 +50,7 @@ 
     cp.readfp(s)
 
 
-def _get_config(name, cp=None):
+def _get_config(name, config_dir, cp=None):
     """Read a config file named name + '.conf'.
 
     This checks and loads files from the source tree, site wide location and
@@ -52,7 +58,7 @@ 
     settings which override source settings.
     """
     config_files = []
-    for directory in load_config_paths('lava-dispatcher'):
+    for directory in load_config_paths('lava-dispatcher', config_dir):
         path = os.path.join(directory, '%s.conf' % name)
         if os.path.exists(path):
             config_files.append(path)
@@ -68,23 +74,25 @@ 
 
 
 class ConfigWrapper(object):
-    def __init__(self, cp):
+    def __init__(self, cp, config_dir):
         self.cp = cp
+        self.config_dir = config_dir
     def get(self, key):
         return self.cp.get("DEFAULT", key)
     def getint(self, key):
         return self.cp.getint("DEFAULT", key)
 
 
-def get_config(name):
-    return ConfigWrapper(_get_config(name))
-
-
-def get_device_config(name):
-    device_config = _get_config("devices/%s" % name)
-    cp = _get_config("device-defaults")
+def get_config(name, config_dir):
+    return ConfigWrapper(_get_config(name, config_dir), config_dir)
+
+
+def get_device_config(name, config_dir):
+    device_config = _get_config("devices/%s" % name, config_dir)
+    cp = _get_config("device-defaults", config_dir)
     _get_config(
-        "device-types/%s" % device_config.get('DEFAULT', 'device_type'), cp)
-    _get_config("devices/%s" % name, cp)
+        "device-types/%s" % device_config.get('DEFAULT', 'device_type'),
+        config_dir, cp=cp)
+    _get_config("devices/%s" % name, config_dir, cp=cp)
     cp.set("DEFAULT", "hostname", name)
-    return ConfigWrapper(cp)
+    return ConfigWrapper(cp, config_dir)

=== modified file 'lava_dispatcher/context.py'
--- lava_dispatcher/context.py	2011-11-14 00:52:45 +0000
+++ lava_dispatcher/context.py	2011-11-28 20:12:01 +0000
@@ -22,14 +22,15 @@ 
 
 from lava_dispatcher.client import LavaClient
 from lava_dispatcher.config import get_device_config
-from lava_dispatcher.test_data import LavaTestData 
+from lava_dispatcher.test_data import LavaTestData
 
 
 class LavaContext(object):
     def __init__(self, target, image_type, dispatcher_config, oob_file, job_data):
         self.config = dispatcher_config
         self.job_data = job_data
-        device_config = get_device_config(target)
+        device_config = get_device_config(
+            target, dispatcher_config.config_dir)
         self._client = LavaClient(self, device_config)
         self.test_data = LavaTestData()
         self.oob_file = oob_file

=== modified file 'lava_dispatcher/job.py'
--- lava_dispatcher/job.py	2011-11-15 01:44:45 +0000
+++ lava_dispatcher/job.py	2011-11-28 20:13:34 +0000
@@ -71,13 +71,11 @@ 
     }
 
 class LavaTestJob(object):
-    def __init__(self, job_json, oob_file):
+    def __init__(self, job_json, oob_file, config):
         self.job_status = 'pass'
         self.load_job_data(job_json)
-        dispatcher_config = get_config("lava-dispatcher")
         self.context = LavaContext(
-            self.target, self.image_type, dispatcher_config, oob_file,
-            self.job_data)
+            self.target, self.image_type, config, oob_file, self.job_data)
 
     def load_job_data(self, job_json):
         self.job_data = json.loads(job_json)

=== added directory 'lava_dispatcher/tests/test-config'
=== added directory 'lava_dispatcher/tests/test-config/devices'
=== added file 'lava_dispatcher/tests/test-config/devices/beaglexm01.conf'
--- lava_dispatcher/tests/test-config/devices/beaglexm01.conf	1970-01-01 00:00:00 +0000
+++ lava_dispatcher/tests/test-config/devices/beaglexm01.conf	2011-11-28 20:27:03 +0000
@@ -0,0 +1,1 @@ 
+device_type = beagle-xm
\ No newline at end of file

=== added file 'lava_dispatcher/tests/test-config/lava-dispatcher.conf'
--- lava_dispatcher/tests/test-config/lava-dispatcher.conf	1970-01-01 00:00:00 +0000
+++ lava_dispatcher/tests/test-config/lava-dispatcher.conf	2011-11-28 20:27:03 +0000
@@ -0,0 +1,1 @@ 
+LAVA_SERVER_IP = 192.168.200.200
\ No newline at end of file

=== modified file 'lava_dispatcher/tests/test_config.py'
--- lava_dispatcher/tests/test_config.py	2011-09-08 23:35:05 +0000
+++ lava_dispatcher/tests/test_config.py	2011-11-28 20:27:03 +0000
@@ -17,14 +17,18 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, see <http://www.gnu.org/licenses>.
 
+import os
 from unittest import TestCase
 
 from lava_dispatcher.config import get_config, get_device_config
 from lava_dispatcher.utils import string_to_list
 
+test_config_dir = os.path.join(os.path.dirname(__file__), 'test-config')
+print test_config_dir
+
 class TestConfigData(TestCase):
     def test_beagle01_uboot_cmds(self):
-        beagle01_config = get_device_config("beaglexm01")
+        beagle01_config = get_device_config("beaglexm01", test_config_dir)
         expected = [
             "mmc init",
             "mmc part 0",
@@ -39,8 +43,8 @@ 
         self.assertEquals(expected, string_to_list(uboot_cmds))
 
     def test_server_ip(self):
-        server_config = get_config("lava-dispatcher")
-        expected = "192.168.1.10"
+        server_config = get_config("lava-dispatcher", test_config_dir)
+        expected = "192.168.200.200"
         lava_server_ip = server_config.get("LAVA_SERVER_IP")
         self.assertEqual(expected, lava_server_ip)