[Checkins] SVN: zc.recipe.deployment/trunk/ add system-wide configuration for root directories

Fred Drake cvs-admin at zope.org
Fri Mar 8 21:51:43 UTC 2013


Log message for revision 130068:
  add system-wide configuration for root directories

Changed:
  U   zc.recipe.deployment/trunk/CHANGES.txt
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/tests.py

-=-
Modified: zc.recipe.deployment/trunk/CHANGES.txt
===================================================================
--- zc.recipe.deployment/trunk/CHANGES.txt	2013-03-08 03:31:54 UTC (rev 130067)
+++ zc.recipe.deployment/trunk/CHANGES.txt	2013-03-08 21:51:42 UTC (rev 130068)
@@ -15,10 +15,13 @@
 - Add ``cache-directory`` and ``lib-directory`` to the set of output
   directories.
 
-- Consistently refuse to clobber the *-directory outputs; join with
-  prefix if relative.
+- Add system-wide configuration, allowing locations of the "root"
+  directories to be specified for an entire machine.
 
+- Consistently refuse to clobber the *-directory inputs with unrelated
+  outputs; join input with prefix if relative.
 
+
 0.9.0 (2011-11-21)
 ==================
 

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2013-03-08 03:31:54 UTC (rev 130067)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2013-03-08 21:51:42 UTC (rev 130068)
@@ -16,6 +16,7 @@
 $Id: deployment.py 14934 2006-11-10 23:57:33Z jim $
 """
 
+import ConfigParser
 import grp
 import logging
 import os
@@ -41,6 +42,21 @@
         etc = os.path.join(
             prefix, options.get('etc-prefix') or options.get('etc') or 'etc')
 
+        cfg = os.path.join(etc, "zc.recipe.deployment.cfg")
+        cp = ConfigParser.RawConfigParser()
+        cp.optionxform = str
+        cp.read(cfg)
+        if cp.has_section("deployment"):
+            #import pdb; pdb.set_trace()
+            for key in cp.options("deployment"):
+                if key in ("log", "run", "var-prefix"):
+                    value = cp.get("deployment", key)
+                    if value and not options.get(key):
+                        options[key] = value
+                elif key:
+                    raise zc.buildout.UserError(
+                        "disallowed option %s in system configuration" % key)
+
         var = os.path.join(prefix, options.get('var-prefix') or 'var')
         if options.get('var-prefix'):
             log = os.path.join(var, "log")

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt	2013-03-08 03:31:54 UTC (rev 130067)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt	2013-03-08 21:51:42 UTC (rev 130068)
@@ -303,3 +303,133 @@
      'run': '/run/someplace',
      'run-directory': '/big-disk/run/myapp',
      'var-prefix': '/big-disk'}
+
+
+Overriding settings from the target system
+------------------------------------------
+
+A common requirement is to be able to locate large bodies of data in a
+different part of the filesystem hierarchy, usually to take advantage of
+disks with different behaviorial characteristics (capacity, performance).
+
+In these cases, the right locations for different kinds of files depends
+on the resources available on the deployment target rather than the
+software being deployed.  To support this, the deployment recipe can
+read a system-wide configuration file located at:
+
+    ${:etc-prerfix}/zc.recipe.deployment.cfg
+
+If the file doesn't exist, we get the behavriors described above.  If it
+does, the file can affect the roots of the data locations (the
+directories traditionally located in /var/).  The /etc/ directories
+cannot be affected.
+
+To avoid needing to write into the system directories for this
+demonstration, we're going to control the ``etc-prefix`` setting in all
+cases.
+
+    >>> import os.path
+
+    >>> config_path = os.path.join(
+    ...     sample_buildout, 'zc.recipe.deployment.cfg')
+
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... var-prefix = /mnt/fatdisk
+    ... ''')
+
+    >>> compute({"etc-prefix": sample_buildout})
+    {'cache-directory': '/mnt/fatdisk/cache/myapp',
+     'crontab-directory': 'PREFIX/cron.d',
+     'etc-directory': 'PREFIX/myapp',
+     'etc-prefix': 'PREFIX',
+     'lib-directory': '/mnt/fatdisk/lib/myapp',
+     'log-directory': '/mnt/fatdisk/log/myapp',
+     'logrotate-directory': 'PREFIX/logrotate.d',
+     'name': 'myapp',
+     'prefix': '/',
+     'rc-directory': 'PREFIX/init.d',
+     'run-directory': '/mnt/fatdisk/run/myapp',
+     'var-prefix': '/mnt/fatdisk'}
+
+    >>> compute({"etc": sample_buildout})
+    {'cache-directory': '/mnt/fatdisk/cache/myapp',
+     'crontab-directory': 'PREFIX/cron.d',
+     'etc': 'PREFIX',
+     'etc-directory': 'PREFIX/myapp',
+     'etc-prefix': 'PREFIX',
+     'lib-directory': '/mnt/fatdisk/lib/myapp',
+     'log-directory': '/mnt/fatdisk/log/myapp',
+     'logrotate-directory': 'PREFIX/logrotate.d',
+     'name': 'myapp',
+     'prefix': '/',
+     'rc-directory': 'PREFIX/init.d',
+     'run-directory': '/mnt/fatdisk/run/myapp',
+     'var-prefix': '/mnt/fatdisk'}
+
+The ``log`` and ``run`` settings can be used here, though that's less
+interesting than ``var-prefix``:
+
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... log = /mnt/fatdisk/logs
+    ... run = /mnt/scratch
+    ... ''')
+
+    >>> compute({"etc-prefix": sample_buildout})
+    {'cache-directory': '/var/cache/myapp',
+     'crontab-directory': 'PREFIX/cron.d',
+     'etc-directory': 'PREFIX/myapp',
+     'etc-prefix': 'PREFIX',
+     'lib-directory': '/var/lib/myapp',
+     'log': '/mnt/fatdisk/logs',
+     'log-directory': '/mnt/fatdisk/logs/myapp',
+     'logrotate-directory': 'PREFIX/logrotate.d',
+     'name': 'myapp',
+     'prefix': '/',
+     'rc-directory': 'PREFIX/init.d',
+     'run': '/mnt/scratch',
+     'run-directory': '/mnt/scratch/myapp',
+     'var-prefix': '/var'}
+
+
+Disallowed settings
+~~~~~~~~~~~~~~~~~~~
+
+Attempting to set the location of /etc from the configuration file is an
+error, since the /etc location has already been determined:
+
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... etc-prefix = /some/where
+    ... ''')
+
+    >>> compute({"etc": sample_buildout})
+    Traceback (most recent call last):
+    UserError: disallowed option etc-prefix in system configuration
+
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... etc = /some/where
+    ... ''')
+
+    >>> compute({"etc": sample_buildout})
+    Traceback (most recent call last):
+    UserError: disallowed option etc in system configuration
+
+Specific -directory settings cannot be included in the system
+configuration file:
+
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... log-directory = /some/fat/disk/for/logging
+    ... ''')
+
+    >>> compute({"etc": sample_buildout})
+    Traceback (most recent call last):
+    UserError: disallowed option log-directory in system configuration

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/tests.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/tests.py	2013-03-08 03:31:54 UTC (rev 130067)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/tests.py	2013-03-08 21:51:42 UTC (rev 130068)
@@ -59,8 +59,15 @@
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocFileSuite('paths.txt'),
         doctest.DocFileSuite(
+            'paths.txt',
+            setUp=zc.buildout.testing.buildoutSetUp,
+            tearDown=zc.buildout.testing.buildoutTearDown,
+            checker=renormalizing.RENormalizing([
+                (re.compile('/[^ ]*/sample-buildout'), 'PREFIX'),
+               ]),
+            ),
+        doctest.DocFileSuite(
             'README.txt',
             setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
             checker=renormalizing.RENormalizing([



More information about the checkins mailing list