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
=== modified file 'anybox/recipe/openerp/base.py'
--- anybox/recipe/openerp/base.py 2014-02-10 12:13:18 +0000
+++ anybox/recipe/openerp/base.py 2014-02-10 12:13:18 +0000
@@ -35,6 +35,21 @@
35 rfc822.mktime_tz(rfc822.parsedate_tz(h))35 rfc822.mktime_tz(rfc822.parsedate_tz(h))
3636
3737
38def _relative_path(common, path):
39 """Copied from easy_install"""
40 r = []
41 while 1:
42 dirname, basename = os.path.split(path)
43 r.append(basename)
44 if dirname == common:
45 break
46 if dirname == path:
47 raise AssertionError("dirname of %s is the same" % dirname)
48 path = dirname
49 r.reverse()
50 return os.path.join(*r)
51
52
38class MainSoftware(object):53class MainSoftware(object):
39 """Placeholder to represent the main software instead of an addon location.54 """Placeholder to represent the main software instead of an addon location.
4055
@@ -124,6 +139,12 @@
124 self.vcs_clear_locks = clear_locks == 'true'139 self.vcs_clear_locks = clear_locks == 'true'
125 clear_retry = options.get('vcs-clear-retry', '').lower()140 clear_retry = options.get('vcs-clear-retry', '').lower()
126 self.clear_retry = clear_retry == 'true'141 self.clear_retry = clear_retry == 'true'
142 self.jailroot_buildout_dir = options.get('jailroot-buildout-dir')
143 self.python_scripts_executable = options.get(
144 'python-scripts-executable')
145
146 if self.jailroot_buildout_dir:
147 options['relative-paths'] = 'true'
127148
128 # same as in zc.recipe.eggs149 # same as in zc.recipe.eggs
129 relative_paths = options.get(150 relative_paths = options.get(
@@ -521,6 +542,18 @@
521 self.sources[local_path] = ((source[0], (source[1][0], revision))542 self.sources[local_path] = ((source[0], (source[1][0], revision))
522 + source[2:])543 + source[2:])
523544
545 def rewrite_addons_path(self, addons_path):
546 """
547 Rewrite the addons path if we are preparing a buildout
548 for a jail root
549 """
550 if self.jailroot_buildout_dir:
551 relative_addons_path = _relative_path(
552 self._relative_paths, addons_path)
553 return os.path.join(
554 self.jailroot_buildout_dir, relative_addons_path)
555 return addons_path
556
524 def retrieve_addons(self):557 def retrieve_addons(self):
525 """Peform all lookup and downloads specified in :attr:`sources`.558 """Peform all lookup and downloads specified in :attr:`sources`.
526559
@@ -1166,6 +1199,11 @@
1166 assert os.path.isdir(path), (1199 assert os.path.isdir(path), (
1167 "Not a directory: %r (aborting)" % path)1200 "Not a directory: %r (aborting)" % path)
11681201
1202 addons_paths = list(self.addons_paths)
1203 self.addons_paths = [
1204 self.rewrite_addons_path(addons_path)
1205 for addons_path in addons_paths
1206 ]
1169 self.options['options.addons_path'] = ','.join(self.addons_paths)1207 self.options['options.addons_path'] = ','.join(self.addons_paths)
1170 if self.major_version <= (6, 0):1208 if self.major_version <= (6, 0):
1171 self._60_fix_root_path()1209 self._60_fix_root_path()
11721210
=== modified file 'anybox/recipe/openerp/server.py'
--- anybox/recipe/openerp/server.py 2014-02-10 12:13:18 +0000
+++ anybox/recipe/openerp/server.py 2014-02-10 12:13:18 +0000
@@ -7,28 +7,13 @@
7import subprocess7import subprocess
8import zc.buildout8import zc.buildout
9from anybox.recipe.openerp import devtools9from anybox.recipe.openerp import devtools
10from anybox.recipe.openerp.base import BaseRecipe10from anybox.recipe.openerp.base import BaseRecipe, _relative_path
1111
12logger = logging.getLogger(__name__)12logger = logging.getLogger(__name__)
1313
14SERVER_COMMA_LIST_OPTIONS = ('log_handler', )14SERVER_COMMA_LIST_OPTIONS = ('log_handler', )
1515
1616
17def _relative_path(common, path):
18 """Copied from easy_install"""
19 r = []
20 while 1:
21 dirname, basename = os.path.split(path)
22 r.append(basename)
23 if dirname == common:
24 break
25 if dirname == path:
26 raise AssertionError("dirname of %s is the same" % dirname)
27 path = dirname
28 r.reverse()
29 return os.path.join(*r)
30
31
32class ServerRecipe(BaseRecipe):17class ServerRecipe(BaseRecipe):
33 """Recipe for server install and config18 """Recipe for server install and config
34 """19 """
@@ -69,6 +54,17 @@
69 "https://launchpad.net/openerp-command."),54 "https://launchpad.net/openerp-command."),
70 })55 })
7156
57 if self.python_scripts_executable:
58 # Monkeypatch the script headers to replace the python
59 # executable by the one configured by the user
60 new_header = '#!%s' % self.python_scripts_executable
61 zc.buildout.easy_install.script_template = (
62 zc.buildout.easy_install.script_template.replace(
63 zc.buildout.easy_install.script_header, new_header))
64 zc.buildout.easy_install.py_script_template = (
65 zc.buildout.easy_install.py_script_template.replace(
66 zc.buildout.easy_install.script_header, new_header))
67
72 def apply_version_dependent_decisions(self):68 def apply_version_dependent_decisions(self):
73 """Store some booleans depending on detected version.69 """Store some booleans depending on detected version.
7470
@@ -358,9 +354,10 @@
358 script_source_path = self.make_absolute(script[0])354 script_source_path = self.make_absolute(script[0])
359 desc.update(355 desc.update(
360 entry='openerp_upgrader',356 entry='openerp_upgrader',
361 arguments='%r, %r, %r, %r' % (357 arguments='%s, %r, %s, %r' % (
362 script_source_path, script[1],358 self._relativitize(script_source_path), script[1],
363 self.config_path, self.buildout_dir),359 self._relativitize(self.config_path),
360 self.jailroot_buildout_dir or self.buildout_dir),
364 )361 )
365362
366 if not os.path.exists(script_source_path):363 if not os.path.exists(script_source_path):
@@ -480,7 +477,7 @@
480 "from anybox.recipe.openerp.runtime.session import Session",477 "from anybox.recipe.openerp.runtime.session import Session",
481 "session = Session(%s, %r)" % (478 "session = Session(%s, %r)" % (
482 self._relativitize(self.config_path),479 self._relativitize(self.config_path),
483 self.buildout_dir),480 self.jailroot_buildout_dir or self.buildout_dir),
484 "if len(sys.argv) <= 1:",481 "if len(sys.argv) <= 1:",
485 " print('To start the OpenERP working session, just do:')",482 " print('To start the OpenERP working session, just do:')",
486 " print(' session.open(db=DATABASE_NAME)')",483 " print(' session.open(db=DATABASE_NAME)')",
@@ -520,8 +517,9 @@
520 common_init = os.linesep.join((517 common_init = os.linesep.join((
521 "",518 "",
522 "from anybox.recipe.openerp.runtime.session import Session",519 "from anybox.recipe.openerp.runtime.session import Session",
523 "session = Session(%r, %r)" % (self.config_path,520 "session = Session(%s, %r)" % (
524 self.buildout_dir),521 self._relativitize(self.config_path),
522 self.jailroot_buildout_dir or self.buildout_dir),
525 ))523 ))
526524
527 for script_name, desc in self.openerp_scripts.items():525 for script_name, desc in self.openerp_scripts.items():
528526
=== modified file 'doc/configuration.rst'
--- doc/configuration.rst 2014-02-10 12:13:18 +0000
+++ doc/configuration.rst 2014-02-10 12:13:18 +0000
@@ -320,6 +320,39 @@
320320
321Note that tarball downloads get re-extracted afresh in any case.321Note that tarball downloads get re-extracted afresh in any case.
322322
323:: _relocation_options:
324
325Options for buildout relocation and jail root
326~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327
328.. _relative-paths:
329
330relative-paths
331--------------
332
333If set to true, this option will set up a movable buildout. Paths in scripts
334will be made relative to the buildout directory so that it can be relocated
335on the file system.
336
337.. _jailroot-buildout-dir:
338
339jailroot-buildout-dir
340---------------------
341
342If you will be moving this buildout to a jail root, specify the location of
343the buildout in the jail root. The addons-paths in the OpenERP configuration
344file will be adapted to this path. This option implies :ref:`relative-paths`.
345
346.. _python-scripts-executable:
347
348python-scripts-executable
349-------------------------
350
351Specify an alternative Python executable to be used in the she-bang of
352generated scripts. For use in a jail root, ``/usr/bin/env python`` should
353be a sane value, or you could hardcode the path to the Python executable
354in your jail root.
355
323.. _openerp_options:356.. _openerp_options:
324357
325OpenERP options358OpenERP options

Subscribers

People subscribed via source and target branches

to all changes: