From 36fe7f249e3313d02b5bb2faa59f993b48fac3b3 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Tue, 11 Nov 2008 03:50:12 -0500 Subject: [PATCH 01/16] Move CodeError and InvalidInput into invirt.common svn path=/trunk/packages/invirt-base/; revision=1612 --- debian/changelog | 6 ++++++ python/invirt/common.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/debian/changelog b/debian/changelog index 36dc0d6..7082585 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.9) unstable; urgency=low + + * Move useful Python exceptions into invirt.common + + -- Evan Broder Tue, 11 Nov 2008 00:32:19 -0500 + invirt-base (0.0.8) unstable; urgency=low * invirt-reload should force-reload, not just reload diff --git a/python/invirt/common.py b/python/invirt/common.py index 77770a6..69317fb 100644 --- a/python/invirt/common.py +++ b/python/invirt/common.py @@ -37,6 +37,26 @@ def lock_file(path, exclusive = True): flock(f, LOCK_UN) # +# Exceptions. +# + +class InvalidInput(Exception): + """Exception for user-provided input is invalid but maybe in good faith. + + This would include setting memory to negative (which might be a + typo) but not setting an invalid boot CD (which requires bypassing + the select box). + """ + def __init__(self, err_field, err_value, expl=None): + MyException.__init__(self, expl) + self.err_field = err_field + self.err_value = err_value + +class CodeError(Exception): + """Exception for internal errors or bad faith input.""" + pass + +# # Tests. # -- 1.7.9.5 From 4e706695a3bce2ff5cc2010a2a496d7b403bdd15 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Tue, 11 Nov 2008 03:50:13 -0500 Subject: [PATCH 02/16] Move the remctl code into invirt.remctl svn path=/trunk/packages/invirt-base/; revision=1613 --- debian/changelog | 3 ++- python/invirt/remctl.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 python/invirt/remctl.py diff --git a/debian/changelog b/debian/changelog index 7082585..314f13b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,9 @@ invirt-base (0.0.9) unstable; urgency=low * Move useful Python exceptions into invirt.common + * Move the remctl code out of the website and into invirt-base - -- Evan Broder Tue, 11 Nov 2008 00:32:19 -0500 + -- Evan Broder Tue, 11 Nov 2008 01:14:42 -0500 invirt-base (0.0.8) unstable; urgency=low diff --git a/python/invirt/remctl.py b/python/invirt/remctl.py new file mode 100644 index 0000000..8f93984 --- /dev/null +++ b/python/invirt/remctl.py @@ -0,0 +1,40 @@ +""" +Functions to perform remctls. +""" + +from invirt.common import CodeError +import subprocess + +def kinit(): + """Kinit with a given username and keytab""" + p = subprocess.Popen(['kinit', "-k", "-t", '/etc/invirt/keytab', + 'daemon/'+config.web.hostname], + stderr=subprocess.PIPE) + e = p.wait() + if e: + raise CodeError("Error %s in kinit: %s" % (e, p.stderr.read())) + +def checkKinit(): + """If we lack tickets, kinit.""" + p = subprocess.Popen(['klist', '-s']) + if p.wait(): + kinit() + +def remctl(*args, **kws): + """Perform a remctl and return the output. + + kinits if necessary, and outputs errors to stderr. + """ + checkKinit() + p = subprocess.Popen(['remctl', config.remote.hostname] + + list(args), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + v = p.wait() + if kws.get('err'): + return p.stdout.read(), p.stderr.read() + if v: + print >> sys.stderr, 'Error', v, 'on remctl', args, ':' + print >> sys.stderr, p.stderr.read() + raise CodeError('ERROR on remctl') + return p.stdout.read() -- 1.7.9.5 From 93012c9a4cc83922a3546c7b51fc524a4efda2b4 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Tue, 11 Nov 2008 04:32:17 -0500 Subject: [PATCH 03/16] Actually generalize the invirt.remctl module svn path=/trunk/packages/invirt-base/; revision=1614 --- python/invirt/remctl.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/python/invirt/remctl.py b/python/invirt/remctl.py index 8f93984..465d31c 100644 --- a/python/invirt/remctl.py +++ b/python/invirt/remctl.py @@ -4,29 +4,33 @@ Functions to perform remctls. from invirt.common import CodeError import subprocess +from socket import getfqdn -def kinit(): +def kinit(principal=None, keytab=None): """Kinit with a given username and keytab""" - p = subprocess.Popen(['kinit', "-k", "-t", '/etc/invirt/keytab', - 'daemon/'+config.web.hostname], + if principal is None: + principal = 'daemon/' + getfqdn() + if keytab is None: + keytab = '/etc/invirt/keytab' + p = subprocess.Popen(['kinit', "-k", "-t", keytab, principal], stderr=subprocess.PIPE) e = p.wait() if e: raise CodeError("Error %s in kinit: %s" % (e, p.stderr.read())) -def checkKinit(): +def checkKinit(principal=None, keytab=None): """If we lack tickets, kinit.""" p = subprocess.Popen(['klist', '-s']) if p.wait(): - kinit() + kinit(principal, keytab) -def remctl(*args, **kws): +def remctl(host, *args, **kws): """Perform a remctl and return the output. kinits if necessary, and outputs errors to stderr. """ - checkKinit() - p = subprocess.Popen(['remctl', config.remote.hostname] + checkKinit(kws.get('principal'), kws.get('keytab')) + p = subprocess.Popen(['remctl', host] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) -- 1.7.9.5 From 1345623118c2045fb66a972cd2a0ffbf1d65a277 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 12 Nov 2008 03:30:56 -0500 Subject: [PATCH 04/16] Fix a missing import in the invirt.remctl code svn path=/trunk/packages/invirt-base/; revision=1621 --- debian/changelog | 6 ++++++ python/invirt/remctl.py | 1 + 2 files changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 314f13b..d55b761 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.10) unstable; urgency=low + + * Fix a missing import in the remctl code + + -- Evan Broder Wed, 12 Nov 2008 03:30:41 -0500 + invirt-base (0.0.9) unstable; urgency=low * Move useful Python exceptions into invirt.common diff --git a/python/invirt/remctl.py b/python/invirt/remctl.py index 465d31c..d530d7a 100644 --- a/python/invirt/remctl.py +++ b/python/invirt/remctl.py @@ -4,6 +4,7 @@ Functions to perform remctls. from invirt.common import CodeError import subprocess +import sys from socket import getfqdn def kinit(principal=None, keytab=None): -- 1.7.9.5 From 58779732826ce6a4f91fdb8a55f0c7a480d1544e Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 12 Nov 2008 05:59:37 -0500 Subject: [PATCH 05/16] Fix another typo - this one in invirt.common svn path=/trunk/packages/invirt-base/; revision=1623 --- debian/changelog | 6 ++++++ python/invirt/common.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index d55b761..ea099f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.11) unstable; urgency=low + + * Fix a typo in the common Python exceptions + + -- Evan Broder Wed, 12 Nov 2008 05:59:05 -0500 + invirt-base (0.0.10) unstable; urgency=low * Fix a missing import in the remctl code diff --git a/python/invirt/common.py b/python/invirt/common.py index 69317fb..2cf860d 100644 --- a/python/invirt/common.py +++ b/python/invirt/common.py @@ -48,7 +48,7 @@ class InvalidInput(Exception): the select box). """ def __init__(self, err_field, err_value, expl=None): - MyException.__init__(self, expl) + Exception.__init__(self, expl) self.err_field = err_field self.err_value = err_value -- 1.7.9.5 From 6105a3c976a01cd176e31d93d42a662a005ad4ee Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 15 Nov 2008 10:16:42 -0500 Subject: [PATCH 06/16] Update apt sources list for prod svn path=/trunk/packages/invirt-base/; revision=1646 --- debian/changelog | 7 +++++++ files/etc/apt/sources.list.d/invirt.list | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index ea099f5..0964f34 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +invirt-base (0.0.12) unstable; urgency=low + + * Change the apt source list for production + * Punt hardy-backports, since the servers have it enabled on their side + + -- Evan Broder Sat, 15 Nov 2008 10:16:23 -0500 + invirt-base (0.0.11) unstable; urgency=low * Fix a typo in the common Python exceptions diff --git a/files/etc/apt/sources.list.d/invirt.list b/files/etc/apt/sources.list.d/invirt.list index 680a320..7a3dbb1 100644 --- a/files/etc/apt/sources.list.d/invirt.list +++ b/files/etc/apt/sources.list.d/invirt.list @@ -1,4 +1,2 @@ -deb http://xvm-2.mit.edu/invirt stable main -deb-src http://xvm-2.mit.edu/invirt stable main -deb http://mirrors.ccs.neu.edu/ubuntu/ hardy-backports main universe -deb-src http://mirrors.ccs.neu.edu/ubuntu/ hardy-backports main universe +deb http://xvm.mit.edu/invirt stable main +deb-src http://xvm.mit.edu/invirt stable main -- 1.7.9.5 From cb19c608412378d9e7f07845155a626933603bf7 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 20 Nov 2008 22:46:55 -0500 Subject: [PATCH 07/16] Add a dependency on apticron for all servers svn path=/trunk/packages/invirt-base/; revision=1727 --- debian/changelog | 6 ++++++ debian/control | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0964f34..b639c45 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.13) unstable; urgency=low + + * Add a dependency on apticron for all servers + + -- Evan Broder Thu, 20 Nov 2008 20:37:40 -0500 + invirt-base (0.0.12) unstable; urgency=low * Change the apt source list for production diff --git a/debian/control b/debian/control index 7c8376d..550a5ff 100644 --- a/debian/control +++ b/debian/control @@ -7,9 +7,9 @@ Standards-Version: 3.8.0 Package: invirt-base Architecture: all -Depends: ${python:Depends}, ${misc:Depends}, molly-guard, python-json - (>= 3.4-2), python-yaml (>= 3.05), python-mako (>= 0.2.2), - invirt-config, invirt-mail-config +Depends: ${python:Depends}, ${misc:Depends}, molly-guard, apticron, + python-json (>= 3.4-2), python-yaml (>= 3.05), python-mako (>= + 0.2.2), invirt-config, invirt-mail-config Provides: ${python:Provides} XB-Python-Version: ${python:Versions} Description: Base configuration required for all Invirt servers -- 1.7.9.5 From f7f61fe7ba6a3716d1f634ac57744975720b75f3 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 6 Dec 2008 15:02:24 -0500 Subject: [PATCH 08/16] Move the prod .k5login file to xvm-prodconfig svn path=/trunk/packages/invirt-base/; revision=1793 --- debian/changelog | 6 ++++++ files/root/.k5login | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 files/root/.k5login diff --git a/debian/changelog b/debian/changelog index b639c45..3223a9c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.14) unstable; urgency=low + + * Move the XVM production .k5login out of this package + + -- Evan Broder Sat, 06 Dec 2008 14:43:37 -0500 + invirt-base (0.0.13) unstable; urgency=low * Add a dependency on apticron for all servers diff --git a/files/root/.k5login b/files/root/.k5login deleted file mode 100644 index 5fe9091..0000000 --- a/files/root/.k5login +++ /dev/null @@ -1,6 +0,0 @@ -andersk/root@ATHENA.MIT.EDU -broder/root@ATHENA.MIT.EDU -ecprice/root@ATHENA.MIT.EDU -hartmans/root@ATHENA.MIT.EDU -price/root@ATHENA.MIT.EDU -quentin/root@ATHENA.MIT.EDU -- 1.7.9.5 From e66842c0badbb0cff67fd26f63c94f594b546c0b Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 7 Dec 2008 09:26:40 -0500 Subject: [PATCH 09/16] Stop depending on invirt-mail-config in invirt-base This was basically an attempt to stuff an XVM site-specific config into the namespace of invirt packages. If we don't expect other users of invirt to roll their own packages, we should depend on packages they can't provide. The dependency on xvm-mail-config will move into a set of xvm metapackages svn path=/trunk/packages/invirt-base/; revision=1803 --- debian/changelog | 7 +++++++ debian/control | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 3223a9c..f06235f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +invirt-base (0.0.15) unstable; urgency=low + + * Stop trying to stuff the XVM site-specific packages into the invirt + namespace + + -- Evan Broder Sun, 07 Dec 2008 09:08:40 -0500 + invirt-base (0.0.14) unstable; urgency=low * Move the XVM production .k5login out of this package diff --git a/debian/control b/debian/control index 550a5ff..3c12e66 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Package: invirt-base Architecture: all Depends: ${python:Depends}, ${misc:Depends}, molly-guard, apticron, python-json (>= 3.4-2), python-yaml (>= 3.05), python-mako (>= - 0.2.2), invirt-config, invirt-mail-config + 0.2.2), invirt-config Provides: ${python:Provides} XB-Python-Version: ${python:Versions} Description: Base configuration required for all Invirt servers -- 1.7.9.5 From 27400a74cc6ce5291b08017928320201f4929631 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 10 Dec 2008 23:21:24 -0500 Subject: [PATCH 10/16] config.{authn[0] => kerberos}.realm svn path=/trunk/packages/invirt-base/; revision=1836 --- debian/changelog | 6 ++++++ scripts/invirt-getconf | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index f06235f..69e596b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.16) unstable; urgency=low + + * Don't reference a config field that we no longer use + + -- Evan Broder Wed, 10 Dec 2008 23:04:58 -0500 + invirt-base (0.0.15) unstable; urgency=low * Stop trying to stuff the XVM site-specific packages into the invirt diff --git a/scripts/invirt-getconf b/scripts/invirt-getconf index 530efd6..86b36b7 100755 --- a/scripts/invirt-getconf +++ b/scripts/invirt-getconf @@ -13,7 +13,7 @@ the YAML configuration; e.g., they cannot contain dots.) Examples: invirt-getconf db.uri - invirt-getconf authn.0.type + invirt-getconf hosts.0.ip """ from invirt import config -- 1.7.9.5 From 4bac1b6bcebc6c1e7b51da52875316e2a4bdfcf1 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 26 Dec 2008 23:57:33 -0500 Subject: [PATCH 11/16] move apticron, molly-guard dependencies to xvm metapackages from invirt-base svn path=/trunk/packages/invirt-base/; revision=1910 --- debian/changelog | 7 +++++++ debian/control | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 69e596b..8c9d137 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +invirt-base (0.0.17) unstable; urgency=low + + * Remove apticron and molly-guard dependencies, + to go into the XVM metapackages + + -- Greg Price Fri, 26 Dec 2008 23:56:34 -0500 + invirt-base (0.0.16) unstable; urgency=low * Don't reference a config field that we no longer use diff --git a/debian/control b/debian/control index 3c12e66..e52327a 100644 --- a/debian/control +++ b/debian/control @@ -7,7 +7,7 @@ Standards-Version: 3.8.0 Package: invirt-base Architecture: all -Depends: ${python:Depends}, ${misc:Depends}, molly-guard, apticron, +Depends: ${python:Depends}, ${misc:Depends}, python-json (>= 3.4-2), python-yaml (>= 3.05), python-mako (>= 0.2.2), invirt-config Provides: ${python:Provides} -- 1.7.9.5 From 310c5346861980c50ac8cd5113198ff0eb04b390 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 28 Dec 2008 01:01:06 -0500 Subject: [PATCH 12/16] invirt.config.run_parts_list: fix unclear docstring svn path=/trunk/packages/invirt-base/; revision=1926 --- debian/changelog | 6 ++++++ python/invirt/config.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 8c9d137..ea065ed 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.18) unstable; urgency=low + + * run_parts_list: fix unclear docstring + + -- Greg Price Sun, 28 Dec 2008 01:00:07 -0500 + invirt-base (0.0.17) unstable; urgency=low * Remove apticron and molly-guard dependencies, diff --git a/python/invirt/config.py b/python/invirt/config.py index 86d9c8a..e4aad28 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -38,7 +38,8 @@ def run_parts_list(dirname): """Reimplements Debian's run-parts --list. One difference from run-parts's behavior: run-parts --list /foo/ - will give output like /foo//bar, because Python code tends to expect this. + will give output like /foo//bar, but run_parts_list('/foo/') gives + /foo/bar in deference to Python conventions. Matches documented behavior of run-parts in debianutils v2.28.2, dated 2007. """ -- 1.7.9.5 From 8bd0fc61a1fb3fa5f97dc03d432a60d5bfebf457 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 28 Dec 2008 02:56:18 -0500 Subject: [PATCH 13/16] config-init.sh: degrade to non-bash gracefully svn path=/trunk/packages/invirt-base/; revision=1928 --- debian/changelog | 1 + files/lib/init/config-init.sh | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index ea065ed..c187e35 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ invirt-base (0.0.18) unstable; urgency=low * run_parts_list: fix unclear docstring + * config-init.sh: degrade to non-bash gracefully -- Greg Price Sun, 28 Dec 2008 01:00:07 -0500 diff --git a/files/lib/init/config-init.sh b/files/lib/init/config-init.sh index 04ca1a0..d9d1f76 100644 --- a/files/lib/init/config-init.sh +++ b/files/lib/init/config-init.sh @@ -1,30 +1,41 @@ # For a package which only configures another, "parent" package. # -# Global variable PARENTPACKAGE names parent; may be array -# for zero or many parents. +# Global variable PARENTPACKAGE names parent; unset for no parent, +# array for (zero or one or) many parents. # # Global variable PACKAGE names this package, for log message. # -# Requires bash. +# If BASH_VERSION is null or unset, accepts only one parent in +# PARENTPACKAGE, or empty for zero. . /lib/init/vars.sh . /lib/lsb/init-functions . /lib/init/gen-files.sh +if [ $BASH_VERSION ]; then + handle_parents () { + for p in "${PARENTPACKAGE[@]}"; do + invoke-rc.d "$p" "$1" + done + } +else + handle_parents () { + if [ -n "$PARENTPACKAGE" ]; then + invoke-rc.d "$PARENTPACKAGE" "$1" + fi + } +fi + config_init () { case "$1" in start|reload|force-reload|restart) log_begin_msg "Reloading config for $PACKAGE" gen_files log_end_msg $? - for p in "${PARENTPACKAGE[@]}"; do - invoke-rc.d "$p" "$1" - done + handle_parents "$1" ;; stop) - for p in "${PARENTPACKAGE[@]}"; do - invoke-rc.d "$p" "$1" - done + handle_parents "$1" ;; *) log_success_msg "Usage: /etc/init.d/$PACKAGE {start|reload|force-reload|restart|stop}" -- 1.7.9.5 From 9b5b9aa21dd2b255d9d4464581b438f67348999e Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 28 Dec 2008 02:56:22 -0500 Subject: [PATCH 14/16] document config-init.sh better svn path=/trunk/packages/invirt-base/; revision=1929 --- debian/changelog | 4 ++-- files/lib/init/config-init.sh | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index c187e35..c433d61 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,9 @@ invirt-base (0.0.18) unstable; urgency=low * run_parts_list: fix unclear docstring - * config-init.sh: degrade to non-bash gracefully + * config-init.sh: degrade to non-bash gracefully, document better - -- Greg Price Sun, 28 Dec 2008 01:00:07 -0500 + -- Greg Price Sun, 28 Dec 2008 02:46:33 -0500 invirt-base (0.0.17) unstable; urgency=low diff --git a/files/lib/init/config-init.sh b/files/lib/init/config-init.sh index d9d1f76..33ea582 100644 --- a/files/lib/init/config-init.sh +++ b/files/lib/init/config-init.sh @@ -1,12 +1,18 @@ # For a package which only configures another, "parent" package. # -# Global variable PARENTPACKAGE names parent; unset for no parent, -# array for (zero or one or) many parents. +# Usage: +# PACKAGE=short-name +# GEN_FILES=(files to generate) +# PARENTPACKAGE=(parent-package another-parent-package) +# . /lib/init/config-init.sh +# config_init "$1" # -# Global variable PACKAGE names this package, for log message. +# PACKAGE - name to appear in log message +# GEN_FILES - files to be generated with gen-files.sh +# PARENTPACKAGE - packages to receive start, etc, commands passed through # -# If BASH_VERSION is null or unset, accepts only one parent in -# PARENTPACKAGE, or empty for zero. +# Global variables GEN_FILES, PARENTPACKAGE may be unset for zero +# values, or scalars for one. If run under sh, they cannot be arrays. . /lib/init/vars.sh . /lib/lsb/init-functions -- 1.7.9.5 From 8f5e6b9f6b945f302c821ce1abee8554ae300a0d Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 28 Dec 2008 19:19:55 -0500 Subject: [PATCH 15/16] invirt.config: fix an error on empty config files svn path=/trunk/packages/invirt-base/; revision=1933 --- debian/changelog | 3 ++- python/invirt/config.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index c433d61..fcba5fd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,9 @@ invirt-base (0.0.18) unstable; urgency=low * run_parts_list: fix unclear docstring * config-init.sh: degrade to non-bash gracefully, document better + * invirt.config: fix an error on empty config files - -- Greg Price Sun, 28 Dec 2008 02:46:33 -0500 + -- Greg Price Sun, 28 Dec 2008 19:16:03 -0500 invirt-base (0.0.17) unstable; urgency=low diff --git a/python/invirt/config.py b/python/invirt/config.py index e4aad28..8c5e7e2 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -20,6 +20,8 @@ lock_path = '/var/lib/invirt/cache.lock' def augment(d1, d2): """Splice dict-tree d2 into d1. Return d1. + d2 may be None for an empty dict-tree, because yaml.load produces that. + Example: >>> d = {'a': {'b': 1}, 'c': 2} >>> augment(d, {'a': {'d': 3}}) @@ -27,6 +29,8 @@ def augment(d1, d2): >>> d {'a': {'b', 1, 'd': 3}, 'c': 2} """ + if d2 is None: + return d1 for k in d2: if k in d1 and isinstance(d1[k], dict): augment(d1[k], d2[k]) -- 1.7.9.5 From 2017f5583611b400f821ad7996308d51a4bbe98b Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 28 Dec 2008 19:20:07 -0500 Subject: [PATCH 16/16] invirt.common: give clearer error message on missing config variable svn path=/trunk/packages/invirt-base/; revision=1934 --- debian/changelog | 3 ++- python/invirt/common.py | 31 +++++++++++++++++++++++++------ python/invirt/config.py | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index fcba5fd..4200a28 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,9 @@ invirt-base (0.0.18) unstable; urgency=low * run_parts_list: fix unclear docstring * config-init.sh: degrade to non-bash gracefully, document better * invirt.config: fix an error on empty config files + * invirt.common: give clearer error message on missing config variable - -- Greg Price Sun, 28 Dec 2008 19:16:03 -0500 + -- Greg Price Sun, 28 Dec 2008 19:18:51 -0500 invirt-base (0.0.17) unstable; urgency=low diff --git a/python/invirt/common.py b/python/invirt/common.py index 2cf860d..85f37d6 100644 --- a/python/invirt/common.py +++ b/python/invirt/common.py @@ -4,22 +4,41 @@ import unittest from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN import contextlib as clib +class InvirtConfigError(AttributeError): + pass + class struct(object): 'A simple namespace object.' - def __init__(self, d = {}, **kwargs): - 'd is the dictionary to update my __dict__ with.' + def __init__(self, d = {}, __prefix = None, **kwargs): + 'd is the dictionary or the items-iterable to update my __dict__ with.' self.__dict__.update(d) self.__dict__.update(kwargs) + self.__prefix = __prefix + def __getattr__(self, key): + # XX ideally these would point a frame higher on the stack. + prefix = self.__prefix + if prefix is not None: + raise InvirtConfigError('missing configuration variable %s%s' + % (prefix, key)) + else: + raise AttributeError("anonymous struct has no member '%s'" + % (key,)) -def dicts2struct(x): +def dicts2struct(x, prefix = None): """ Given a tree of lists/dicts, perform a deep traversal to transform all the dicts to structs. """ + if prefix is not None: + def newprefix(k): return prefix + str(k) + '.' + else: + def newprefix(k): return prefix if type(x) == dict: - return struct((k, dicts2struct(v)) for k,v in x.iteritems()) + return struct(((k, dicts2struct(v, newprefix(k))) + for k,v in x.iteritems()), + prefix) elif type(x) == list: - return [dicts2struct(v) for v in x] + return [dicts2struct(v, newprefix(i)) for i, v in enumerate(x)] else: return x @@ -67,7 +86,7 @@ class common_tests(unittest.TestCase): 'dict': { 'atom': 'atom', 'list': [1,2,3] }, 'list': [ 'atom', {'key': 'value'} ] } - structs = dicts2struct(dicts) + structs = dicts2struct(dicts, '') self.assertEqual(structs.atom, dicts['atom']) self.assertEqual(structs.dict.atom, dicts['dict']['atom']) self.assertEqual(structs.dict.list, dicts['dict']['list']) diff --git a/python/invirt/config.py b/python/invirt/config.py index 8c5e7e2..bcd2423 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -140,6 +140,6 @@ def load(force_refresh = False): return ns.cfg dicts = load() -structs = dicts2struct(dicts) +structs = dicts2struct(dicts, '') # vim:et:sw=4:ts=4 -- 1.7.9.5