Merge lp:~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_explicit_jailroot_support into lp:~jbaudoux/anybox.recipe.openerp/20130908_relative_paths

Proposed by Stefan Rijnhart (Opener)
Status: Needs review
Proposed branch: lp:~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_explicit_jailroot_support
Merge into: lp:~jbaudoux/anybox.recipe.openerp/20130908_relative_paths
Prerequisite: lp:~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_resolve_conflict
Diff against target: 200 lines (+91/-22)
3 files modified
anybox/recipe/openerp/base.py (+38/-0)
anybox/recipe/openerp/server.py (+20/-22)
doc/configuration.rst (+33/-0)
To merge this branch: bzr merge lp:~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_explicit_jailroot_support
Reviewer Review Type Date Requested Status
Jacques-Etienne Baudoux test & code review Needs Fixing
Anybox Pending
Therp Pending
Review via email: mp+205099@code.launchpad.net

Description of the change

This branch allows the creation of a buildout that can be moved to a jail root and run OpenERP in that jail root without any modifications to any of the files in the buildout.

Please notice the target branch: this proposal is a continuation of the work by Jacques-Etienne Baudoux.

- Apply the use of _relativitize in recent changes in the target branch.
- Add explicit support for jail root in the buildout.cfg [openerp] section, which will update the addons-paths.
- Also allow specification of a portable python executable or the python executable in the jail root, to be put in the generated scripts' she-bangs.

For clarity, an update of the original branch by mr. Baudoux with the series branch of the project has been delegated to the prerequisite branch. I'll leave that branch in WIP state, as I don't believe it really needs a separate review.

To post a comment you must log in.
429. By Stefan Rijnhart (Opener)

[FIX] Terminology

430. By Stefan Rijnhart (Opener)

[FIX] Remove call to debugger

Revision history for this message
Jacques-Etienne Baudoux (jbaudoux) wrote :

Hello Stefan,

I tried your latest branch lp:~therp-nl/anybox.recipe.openerp/8.2-jbaudoux-relative_paths_explicit_jailroot_support to test the jailroot.
It's not clear for me what you expect in the new "jailroot-buildout-dir" option.

When instanciating Session, it's not clear to me what is expected as root path. Seems only used to find a VERSION.txt file that I can't find anyway.
| "session = Session(%s, %r)" % (
|| self._relativitize(self.config_path),
|| self.jailroot_buildout_dir or self.buildout_dir),

When deploying from /root into /root/jailroot, do you expect jailroot-buildout-dir to be '/' which is the root from inside the jail, or '/root/jailroot' which is the path of the jail.
In the later case, that path was already deducted in the method _relativitize in server.py without having to define a new variable.

At the moment, your changes do not work with my current setup. If you can clarify your approach, I'm willing to refactor your MP to make it work with my setup against latest 1.8 serie. I'd be happy to finalize this branch and get it merged.

review: Needs Fixing (test & code review)

Unmerged revisions

430. By Stefan Rijnhart (Opener)

[FIX] Remove call to debugger

429. By Stefan Rijnhart (Opener)

[FIX] Terminology

428. By Stefan Rijnhart (Opener)

[IMP] Comment

427. By Stefan Rijnhart (Opener)

[FIX] Typo

426. By Stefan Rijnhart (Opener)

[RFR] Terminology

425. By Stefan Rijnhart (Opener)

[RFR] Make _relative_path available in both base.py and server.py
[ADD] Adapt addons paths to explicit jail root location
[ADD] Option to specify target python executable

424. By Stefan Rijnhart (Opener)

[MRG] Update with target branch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'anybox/recipe/openerp/base.py'
2--- anybox/recipe/openerp/base.py 2014-02-10 12:13:18 +0000
3+++ anybox/recipe/openerp/base.py 2014-02-10 12:13:18 +0000
4@@ -35,6 +35,21 @@
5 rfc822.mktime_tz(rfc822.parsedate_tz(h))
6
7
8+def _relative_path(common, path):
9+ """Copied from easy_install"""
10+ r = []
11+ while 1:
12+ dirname, basename = os.path.split(path)
13+ r.append(basename)
14+ if dirname == common:
15+ break
16+ if dirname == path:
17+ raise AssertionError("dirname of %s is the same" % dirname)
18+ path = dirname
19+ r.reverse()
20+ return os.path.join(*r)
21+
22+
23 class MainSoftware(object):
24 """Placeholder to represent the main software instead of an addon location.
25
26@@ -124,6 +139,12 @@
27 self.vcs_clear_locks = clear_locks == 'true'
28 clear_retry = options.get('vcs-clear-retry', '').lower()
29 self.clear_retry = clear_retry == 'true'
30+ self.jailroot_buildout_dir = options.get('jailroot-buildout-dir')
31+ self.python_scripts_executable = options.get(
32+ 'python-scripts-executable')
33+
34+ if self.jailroot_buildout_dir:
35+ options['relative-paths'] = 'true'
36
37 # same as in zc.recipe.eggs
38 relative_paths = options.get(
39@@ -521,6 +542,18 @@
40 self.sources[local_path] = ((source[0], (source[1][0], revision))
41 + source[2:])
42
43+ def rewrite_addons_path(self, addons_path):
44+ """
45+ Rewrite the addons path if we are preparing a buildout
46+ for a jail root
47+ """
48+ if self.jailroot_buildout_dir:
49+ relative_addons_path = _relative_path(
50+ self._relative_paths, addons_path)
51+ return os.path.join(
52+ self.jailroot_buildout_dir, relative_addons_path)
53+ return addons_path
54+
55 def retrieve_addons(self):
56 """Peform all lookup and downloads specified in :attr:`sources`.
57
58@@ -1166,6 +1199,11 @@
59 assert os.path.isdir(path), (
60 "Not a directory: %r (aborting)" % path)
61
62+ addons_paths = list(self.addons_paths)
63+ self.addons_paths = [
64+ self.rewrite_addons_path(addons_path)
65+ for addons_path in addons_paths
66+ ]
67 self.options['options.addons_path'] = ','.join(self.addons_paths)
68 if self.major_version <= (6, 0):
69 self._60_fix_root_path()
70
71=== modified file 'anybox/recipe/openerp/server.py'
72--- anybox/recipe/openerp/server.py 2014-02-10 12:13:18 +0000
73+++ anybox/recipe/openerp/server.py 2014-02-10 12:13:18 +0000
74@@ -7,28 +7,13 @@
75 import subprocess
76 import zc.buildout
77 from anybox.recipe.openerp import devtools
78-from anybox.recipe.openerp.base import BaseRecipe
79+from anybox.recipe.openerp.base import BaseRecipe, _relative_path
80
81 logger = logging.getLogger(__name__)
82
83 SERVER_COMMA_LIST_OPTIONS = ('log_handler', )
84
85
86-def _relative_path(common, path):
87- """Copied from easy_install"""
88- r = []
89- while 1:
90- dirname, basename = os.path.split(path)
91- r.append(basename)
92- if dirname == common:
93- break
94- if dirname == path:
95- raise AssertionError("dirname of %s is the same" % dirname)
96- path = dirname
97- r.reverse()
98- return os.path.join(*r)
99-
100-
101 class ServerRecipe(BaseRecipe):
102 """Recipe for server install and config
103 """
104@@ -69,6 +54,17 @@
105 "https://launchpad.net/openerp-command."),
106 })
107
108+ if self.python_scripts_executable:
109+ # Monkeypatch the script headers to replace the python
110+ # executable by the one configured by the user
111+ new_header = '#!%s' % self.python_scripts_executable
112+ zc.buildout.easy_install.script_template = (
113+ zc.buildout.easy_install.script_template.replace(
114+ zc.buildout.easy_install.script_header, new_header))
115+ zc.buildout.easy_install.py_script_template = (
116+ zc.buildout.easy_install.py_script_template.replace(
117+ zc.buildout.easy_install.script_header, new_header))
118+
119 def apply_version_dependent_decisions(self):
120 """Store some booleans depending on detected version.
121
122@@ -358,9 +354,10 @@
123 script_source_path = self.make_absolute(script[0])
124 desc.update(
125 entry='openerp_upgrader',
126- arguments='%r, %r, %r, %r' % (
127- script_source_path, script[1],
128- self.config_path, self.buildout_dir),
129+ arguments='%s, %r, %s, %r' % (
130+ self._relativitize(script_source_path), script[1],
131+ self._relativitize(self.config_path),
132+ self.jailroot_buildout_dir or self.buildout_dir),
133 )
134
135 if not os.path.exists(script_source_path):
136@@ -480,7 +477,7 @@
137 "from anybox.recipe.openerp.runtime.session import Session",
138 "session = Session(%s, %r)" % (
139 self._relativitize(self.config_path),
140- self.buildout_dir),
141+ self.jailroot_buildout_dir or self.buildout_dir),
142 "if len(sys.argv) <= 1:",
143 " print('To start the OpenERP working session, just do:')",
144 " print(' session.open(db=DATABASE_NAME)')",
145@@ -520,8 +517,9 @@
146 common_init = os.linesep.join((
147 "",
148 "from anybox.recipe.openerp.runtime.session import Session",
149- "session = Session(%r, %r)" % (self.config_path,
150- self.buildout_dir),
151+ "session = Session(%s, %r)" % (
152+ self._relativitize(self.config_path),
153+ self.jailroot_buildout_dir or self.buildout_dir),
154 ))
155
156 for script_name, desc in self.openerp_scripts.items():
157
158=== modified file 'doc/configuration.rst'
159--- doc/configuration.rst 2014-02-10 12:13:18 +0000
160+++ doc/configuration.rst 2014-02-10 12:13:18 +0000
161@@ -320,6 +320,39 @@
162
163 Note that tarball downloads get re-extracted afresh in any case.
164
165+:: _relocation_options:
166+
167+Options for buildout relocation and jail root
168+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169+
170+.. _relative-paths:
171+
172+relative-paths
173+--------------
174+
175+If set to true, this option will set up a movable buildout. Paths in scripts
176+will be made relative to the buildout directory so that it can be relocated
177+on the file system.
178+
179+.. _jailroot-buildout-dir:
180+
181+jailroot-buildout-dir
182+---------------------
183+
184+If you will be moving this buildout to a jail root, specify the location of
185+the buildout in the jail root. The addons-paths in the OpenERP configuration
186+file will be adapted to this path. This option implies :ref:`relative-paths`.
187+
188+.. _python-scripts-executable:
189+
190+python-scripts-executable
191+-------------------------
192+
193+Specify an alternative Python executable to be used in the she-bang of
194+generated scripts. For use in a jail root, ``/usr/bin/env python`` should
195+be a sane value, or you could hardcode the path to the Python executable
196+in your jail root.
197+
198 .. _openerp_options:
199
200 OpenERP options

Subscribers

People subscribed via source and target branches

to all changes: