Commit 49a46676 authored by Jim Fulton's avatar Jim Fulton

Allow the storage name to be ommitted from the storage configuration

when there is just one storage.
parent 1a4f1414
...@@ -124,6 +124,20 @@ class ZEOOptions(ZDOptions, ZEOOptionsMixin): ...@@ -124,6 +124,20 @@ class ZEOOptions(ZDOptions, ZEOOptionsMixin):
self.add("storages", "storages", self.add("storages", "storages",
required="no storages specified; use -f or -C") 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: class ZEOServer:
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<section type="runner" name="*" required="no" attribute="runner" /> <section type="runner" name="*" required="no" attribute="runner" />
<multisection name="+" type="ZODB.storage" <multisection name="*" type="ZODB.storage"
attribute="storages" attribute="storages"
required="yes"> required="yes">
<description> <description>
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment