[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/ Allow the storage name to be ommitted from the storage configuration

Jim Fulton jim at zope.com
Sun Nov 16 12:11:41 EST 2008


Log message for revision 93012:
  Allow the storage name to be ommitted from the storage configuration
  when there is just one storage.
  

Changed:
  U   ZODB/trunk/src/ZEO/runzeo.py
  U   ZODB/trunk/src/ZEO/schema.xml
  A   ZODB/trunk/src/ZEO/tests/zdoptions.test

-=-
Modified: ZODB/trunk/src/ZEO/runzeo.py
===================================================================
--- ZODB/trunk/src/ZEO/runzeo.py	2008-11-16 15:51:24 UTC (rev 93011)
+++ ZODB/trunk/src/ZEO/runzeo.py	2008-11-16 17:11:41 UTC (rev 93012)
@@ -124,6 +124,20 @@
         self.add("storages", "storages",
                  required="no storages specified; use -f or -C")
 
+    def realize(self, *a, **k):
+        ZDOptions.realize(self, *a, **k)
+        nunnamed = [s for s in self.storages if s.name is None]
+        if nunnamed:
+            if len(nunnamed) > 1:
+                return self.usage("No more than one storage may be unnamed.")
+            if [s for s in self.storages if s.name == '1']:
+                return self.usage(
+                    "Can't have an unnamed storage and a storage named 1.")
+            for s in self.storages:
+                if s.name is None:
+                    s.name = '1'
+                    break
+                
 
 class ZEOServer:
 

Modified: ZODB/trunk/src/ZEO/schema.xml
===================================================================
--- ZODB/trunk/src/ZEO/schema.xml	2008-11-16 15:51:24 UTC (rev 93011)
+++ ZODB/trunk/src/ZEO/schema.xml	2008-11-16 17:11:41 UTC (rev 93012)
@@ -24,7 +24,7 @@
 
   <section type="runner" name="*" required="no" attribute="runner" />
 
-  <multisection name="+" type="ZODB.storage"
+  <multisection name="*" type="ZODB.storage"
                 attribute="storages"
                 required="yes">
     <description>

Added: ZODB/trunk/src/ZEO/tests/zdoptions.test
===================================================================
--- ZODB/trunk/src/ZEO/tests/zdoptions.test	                        (rev 0)
+++ ZODB/trunk/src/ZEO/tests/zdoptions.test	2008-11-16 17:11:41 UTC (rev 93012)
@@ -0,0 +1,132 @@
+Minimal test of Server Options Handling
+=======================================
+
+This is initially motivated by a desire to remove the requirement of
+specifying a storage name when there is only one storage.
+
+Storage Names
+-------------
+
+It is an error not to specify any storages:
+
+    >>> import StringIO, sys, ZEO.runzeo
+    >>> stderr = sys.stderr
+
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... """)
+    
+    >>> sys.stderr = StringIO.StringIO() 
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    Traceback (most recent call last):
+    ...
+    SystemExit: 2
+
+    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+    Error: not enough values for section type 'zodb.storage';
+     0 found, 1 required
+    ...
+
+
+But we can specify a storage without a name:
+
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... <mappingstorage>
+    ... </mappingstorage>
+    ... """)
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    >>> [storage.name for storage in options.storages]
+    ['1']
+
+We can't have multiple unnamed storages:
+
+    >>> sys.stderr = StringIO.StringIO() 
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... <mappingstorage>
+    ... </mappingstorage>
+    ... <mappingstorage>
+    ... </mappingstorage>
+    ... """)
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    Traceback (most recent call last):
+    ...
+    SystemExit: 2
+
+    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+    Error: No more than one storage may be unnamed.
+    ...
+
+Or an unnamed storage and one named '1':
+
+    >>> sys.stderr = StringIO.StringIO() 
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... <mappingstorage>
+    ... </mappingstorage>
+    ... <mappingstorage 1>
+    ... </mappingstorage>
+    ... """)
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    Traceback (most recent call last):
+    ...
+    SystemExit: 2
+
+    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+    Error: Can't have an unnamed storage and a storage named 1.
+    ...
+
+But we can have multiple storages:
+
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... <mappingstorage x>
+    ... </mappingstorage>
+    ... <mappingstorage y>
+    ... </mappingstorage>
+    ... """)
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    >>> [storage.name for storage in options.storages]
+    ['x', 'y']
+
+As long as the names are unique:
+
+    >>> sys.stderr = StringIO.StringIO() 
+    >>> open('config', 'w').write("""
+    ... <zeo>
+    ...     address 8100
+    ... </zeo>
+    ... <mappingstorage 1>
+    ... </mappingstorage>
+    ... <mappingstorage 1>
+    ... </mappingstorage>
+    ... """)
+    >>> options = ZEO.runzeo.ZEOOptions()
+    >>> options.realize('-C config'.split())
+    Traceback (most recent call last):
+    ...
+    SystemExit: 2
+
+    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+    Error: section names must not be re-used within the same container:'1'
+    ...
+
+.. Cleanup =====================================================
+
+    >>> sys.stderr = stderr


Property changes on: ZODB/trunk/src/ZEO/tests/zdoptions.test
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the Zodb-checkins mailing list