From 4f70e94d4e72ffd88ceb1c211940d31b1baf5579 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 2 May 2011 16:42:57 +0000
Subject: [PATCH] Use dictionary for exposed zeo configuration wih storage name
 as key.

Allow to simply pass Zeo configuration string during Zope installation in
order to decouple Zope/Zeo configuration logic.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45776 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5/src/slapos/recipe/erp5/__init__.py   | 23 +++++++++----------
 .../erp5/template/zope-zeo-snippet.conf.in    |  8 +++++++
 .../slapos/recipe/erp5/template/zope.conf.in  |  9 +-------
 3 files changed, 20 insertions(+), 20 deletions(-)
 create mode 100644 slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope-zeo-snippet.conf.in

diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
index 37cda1c0ad..45950e7209 100644
--- a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
+++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
@@ -502,7 +502,7 @@ class Recipe(BaseSlapRecipe):
   def installZeo(self, ip):
     zodb_dir = os.path.join(self.data_root_directory, 'zodb')
     self._createDirectory(zodb_dir)
-    zeo_configuration_list = []
+    zeo_configuration_dict = {}
     zeo_number = 0
     for zeo_server in sorted(self._zeo_storage_dict.iterkeys()):
       zeo_number += 1
@@ -524,12 +524,11 @@ class Recipe(BaseSlapRecipe):
         storage_definition_list.append("""<filestorage %(storage_name)s>
   path %(path)s
 </filestorage>"""% dict(storage_name=storage_name, path=path))
-        zeo_configuration_list.append(dict(
+        zeo_configuration_dict[storage_name] = dict(
           ip=ip,
           port=config['zeo_port'],
-          path=path,
-          storage_name=storage_name,
-          ))
+          path=path
+          )
       config['zeo_filestorage_snippet'] = '\n'.join(storage_definition_list)
       zeo_conf_path = self.createConfigurationFile('zeo-%s.conf' % zeo_number,
         self.substituteTemplate(self.getTemplateFilename('zeo.conf.in'), config))
@@ -539,18 +538,18 @@ class Recipe(BaseSlapRecipe):
           self.options['runzeo_binary'].strip(), '-C', zeo_conf_path]
         )[0]
       self.path_list.append(wrapper)
-    return zeo_configuration_list
+    return zeo_configuration_dict
 
-  def installZope(self, ip, port, name, zeo_address=None, zeo_storagename=None,
-      zodb_root_path=None, with_timerservice=False):
+  def installZope(self, ip, port, name, zodb_root_path=None,
+      with_timerservice=False, zodb_configuration_string=None):
     # Create zope configuration file
     zope_config = dict(
         products=self.options['products'],
     )
-    if zeo_address is not None and zeo_storagename is not None:
-      zope_config.update(zeo_address=zeo_address, zeo_storagename=zeo_storagename)
-    elif zodb_root_path is not None:
+    if zodb_configuration_string is None:
       zope_config.update(zodb_root_path=zodb_root_path)
+    else:
+      zope_config.update(zodb_configuration_string=zodb_configuration_string)
     zope_config['instance'] = self.erp5_directory
     zope_config['event_log'] = os.path.join(self.log_directory,
         '%s-event.log' % name)
@@ -577,7 +576,7 @@ class Recipe(BaseSlapRecipe):
     zope_config['path'] = ':'.join([self.bin_directory] +
         os.environ['PATH'].split(':'))
 
-    if zeo_address is None:
+    if zodb_configuration_string is None:
       zope_wrapper_template_location = self.getTemplateFilename(
           'zope.conf.simple.in')
       with_timerservice = True
diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope-zeo-snippet.conf.in b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope-zeo-snippet.conf.in
new file mode 100644
index 0000000000..71ff156795
--- /dev/null
+++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope-zeo-snippet.conf.in
@@ -0,0 +1,8 @@
+<zodb_db %(storage_name)s>
+  mount-point %(mount_point)s
+  <zeoclient>
+    server %(address)s
+    storage %(storage_name)s
+    name %(storage_name)s
+  </zeoclient>
+</zodb_db>
diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope.conf.in b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope.conf.in
index 89370b7b4e..45e9d83465 100644
--- a/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope.conf.in
+++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zope.conf.in
@@ -43,14 +43,7 @@ lock-filename %(lock-filename)s
 </http-server>
 
 # ZODB configuration
-<zodb_db main>
-  mount-point /
-  <zeoclient>
-    server %(zeo_address)s
-    storage %(zeo_storagename)s
-    name %(zeo_storagename)s
-  </zeoclient>
-</zodb_db>
+%(zodb_configuration_string)s
 <zoperunner>
     program $INSTANCE/bin/runzope
 </zoperunner>
-- 
2.30.9