diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 379: Make configuration keys with blank value and a default return the default

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

Commit Message

Antonio Terceiro Sept. 12, 2012, 6:28 p.m. UTC
Merge authors:
  Antonio Terceiro (terceiro)
Related merge proposals:
  https://code.launchpad.net/~terceiro/lava-dispatcher/fix-1032467/+merge/123833
  proposed by: Antonio Terceiro (terceiro)
  review: Approve - Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 379 [merge]
fixes bug: https://launchpad.net/bugs/1032467
committer: Antonio Terceiro <antonio.terceiro@linaro.org>
branch nick: lava-dispatcher
timestamp: Wed 2012-09-12 15:21:49 -0300
message:
  Make configuration keys with blank value and a default return the default
modified:
  lava_dispatcher/config.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_dispatcher/config.py'
--- lava_dispatcher/config.py	2012-08-08 22:30:52 +0000
+++ lava_dispatcher/config.py	2012-09-11 21:00:08 +0000
@@ -80,7 +80,10 @@ 
         self.config_dir = config_dir
     def get(self, key, default=_sentinel):
         try:
-            return self.cp.get("DEFAULT", key)
+            val = self.cp.get("DEFAULT", key)
+            if default is not _sentinel and val == '':
+                val = default
+            return val
         except NoOptionError:
             if default is not _sentinel:
                 return default

=== modified file 'lava_dispatcher/tests/test_config.py'
--- lava_dispatcher/tests/test_config.py	2011-11-28 20:27:03 +0000
+++ lava_dispatcher/tests/test_config.py	2012-09-12 18:09:46 +0000
@@ -22,11 +22,29 @@ 
 
 from lava_dispatcher.config import get_config, get_device_config
 from lava_dispatcher.utils import string_to_list
+from lava_dispatcher.client.base import LavaClient
 
 test_config_dir = os.path.join(os.path.dirname(__file__), 'test-config')
 print test_config_dir
 
+tmp_dir = os.getenv("TMPDIR") or '/tmp'
+tmp_config_dir = os.path.join(tmp_dir, 'lava-dispatcher-config')
+
+def create_config(name, data):
+    filename = os.path.join(tmp_config_dir, name)
+    os.mkdir(os.path.dirname(filename))
+    with open(filename, 'w') as f:
+        for key in data.keys():
+            f.write("%s = %s\n" % (key, data[key]))
+
 class TestConfigData(TestCase):
+
+    def setUp(self):
+        os.mkdir(tmp_config_dir)
+
+    def tearDown(self):
+        os.system('rm -rf %s' % tmp_config_dir)
+
     def test_beagle01_uboot_cmds(self):
         beagle01_config = get_device_config("beaglexm01", test_config_dir)
         expected = [
@@ -48,3 +66,8 @@ 
         lava_server_ip = server_config.get("LAVA_SERVER_IP")
         self.assertEqual(expected, lava_server_ip)
 
+    def test_default_value_for_tester_hostname(self):
+        create_config('devices/qemu01.conf', { 'device_type': 'qemu' })
+        config = get_device_config("qemu01", tmp_config_dir)
+        client = LavaClient(None, config)
+        self.assertEqual('linaro', client.tester_hostname)