From 98eefa9a0af4e889f1aca2b255d13a8d77bf3776 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Wed, 19 Oct 2011 15:40:58 +0200
Subject: [PATCH] Prepare tidstorage configuration.

In order to stabilise it zodb path has to be calculated early.
---
 slapos/recipe/generate_erp5_tidstorage.py | 9 ++++++++-
 slapos/recipe/zeo/__init__.py             | 7 +++----
 software/erp5/snippet-master.cfg          | 2 +-
 software/erp5/software.cfg                | 2 +-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/slapos/recipe/generate_erp5_tidstorage.py b/slapos/recipe/generate_erp5_tidstorage.py
index 4462b259c..ce38ef1b0 100644
--- a/slapos/recipe/generate_erp5_tidstorage.py
+++ b/slapos/recipe/generate_erp5_tidstorage.py
@@ -54,6 +54,7 @@ class Recipe(GenericSlapRecipe):
     part_list = []
     zope_dict = {}
     zope_connection_dict = {}
+    known_tid_storage_identifier_dict = {}
     snippet_zeo = open(self.options['snippet-zeo']).read()
     for zeo_id, zeo_configuration_list in json_data['zeo'].iteritems():
       storage_list = []
@@ -66,7 +67,13 @@ class Recipe(GenericSlapRecipe):
           'storage-name': zeo_slave['storage-name'],
           'server': '${zeo-instance-%(zeo-id)s:ip}:${zeo-instance-%(zeo-id)s:port}' % {'zeo-id': zeo_id}
         }
-        a('  storage-name=%(storage-name)s zodb-name=%(zodb-name)s' % zeo_slave)
+        zodb_path = os.path.join('${directory:zodb}', zeo_slave['storage-name'] + '.fs')
+        a('  storage-name=%(storage-name)s zodb-path=%(zodb-path)s' % {'zodb-path': zodb_path, 'storage-name': zeo_slave['storage-name']})
+        known_tid_storage_identifier_dict[
+          "((('%(ip)s', %(port)s),), '%(storage_name)s')" % dict(
+            ip='${zeo-instance-%(zeo-id)s:ip}',
+            port='${zeo-instance-%(zeo-id)s:port}',
+            storage_name=zeo_slave['storage-name'])] = (zodb_path, '${directory:zodb-backup}/%s/' % zeo_slave['storage-name'], zeo_slave['serialize-path'] % {'site-id': site_id})
       current_zeo_port += 1
       output += snippet_zeo % dict(
         zeo_id=zeo_id,
diff --git a/slapos/recipe/zeo/__init__.py b/slapos/recipe/zeo/__init__.py
index 11852cd1d..cdc0ac90d 100644
--- a/slapos/recipe/zeo/__init__.py
+++ b/slapos/recipe/zeo/__init__.py
@@ -65,11 +65,10 @@ class Recipe(GenericBaseRecipe):
       for q in storage_definition.split():
         if 'storage-name' in q:
           storage_name = q.split('=')[1].strip()
-        if 'zodb-name' in q:
-          zodb_name = q.split('=')[1].strip()
-      storage_path = os.path.join(zodb_directory_path, '%s.fs' % zodb_name)
+        if 'zodb-path' in q:
+          zodb_path = q.split('=')[1].strip()
       filestorage_snippet += self.substituteTemplate(
-          snippet_filename, dict(storage_name=storage_name, path=storage_path))
+          snippet_filename, dict(storage_name=storage_name, path=zodb_path))
 
     config = dict(
       zeo_ip=self.options['ip'],
diff --git a/software/erp5/snippet-master.cfg b/software/erp5/snippet-master.cfg
index 81f931ff0..e36df1cb0 100644
--- a/software/erp5/snippet-master.cfg
+++ b/software/erp5/snippet-master.cfg
@@ -74,7 +74,6 @@ create = true
 
 [zeo-instance-entry-common]
 recipe = slapos.cookbook:zeo
-zodb-path = $${directory:zodb}
 ip = $${slap-network-information:local-ipv4}
 binary-path = ${buildout:bin-directory}/runzeo
 
@@ -115,6 +114,7 @@ backup = $${rootdirectory:srv}/backup/
 [directory]
 recipe = slapos.cookbook:mkdirectory
 zodb = $${rootdirectory:srv}/zodb/
+zodb-backup = $${basedirectory:backup}/zodb
 instance = $${rootdirectory:srv}/erp5shared/
 instance-etc = $${:instance}/etc
 apache-conf = $${rootdirectory:etc}/apache
diff --git a/software/erp5/software.cfg b/software/erp5/software.cfg
index 44c5484b8..7a6d17e15 100644
--- a/software/erp5/software.cfg
+++ b/software/erp5/software.cfg
@@ -88,7 +88,7 @@ mode = 0644
 [template-snippet-master]
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/snippet-master.cfg
-md5sum = c14f7eecea2603f53f1dd6e640ee671b
+md5sum = 4061555651d15cd050f4e00736877a33
 output = ${buildout:directory}/template-snippet-master.cfg
 mode = 0644
 
-- 
2.30.9