From patchwork Mon Nov 28 22:16:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 5324 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 221A923E04 for ; Mon, 28 Nov 2011 22:16:42 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id E0DD0A1840B for ; Mon, 28 Nov 2011 22:16:41 +0000 (UTC) Received: by laah2 with SMTP id h2so991106laa.11 for ; Mon, 28 Nov 2011 14:16:41 -0800 (PST) Received: by 10.152.105.226 with SMTP id gp2mr29465924lab.28.1322518601500; Mon, 28 Nov 2011 14:16:41 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs10624lal; Mon, 28 Nov 2011 14:16:40 -0800 (PST) Received: by 10.180.77.42 with SMTP id p10mr47340351wiw.66.1322518583446; Mon, 28 Nov 2011 14:16:23 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id fx1si12454585wbb.76.2011.11.28.14.16.17 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Nov 2011 14:16:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RV9Un-0003Zn-LM for ; Mon, 28 Nov 2011 22:16:17 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 9A4F7E0100 for ; Mon, 28 Nov 2011 22:16:17 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-dispatcher X-Launchpad-Branch: ~linaro-validation/lava-dispatcher/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 168 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [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> Date: Mon, 28 Nov 2011 22:16:17 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14381"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: edeafa3c6972baed761f453a757c00f1973a3bbc 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 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 === 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 . +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)