Merge lp:~anybox/aeroo/fix-upgrade into lp:~anybox/aeroo/7.0-anybox

Proposed by Georges Racinet
Status: Merged
Merged at revision: 37
Proposed branch: lp:~anybox/aeroo/fix-upgrade
Merge into: lp:~anybox/aeroo/7.0-anybox
Diff against target: 196 lines (+91/-13)
6 files modified
report_aeroo/report_xml.py (+11/-6)
report_aeroo_ooo/DocumentConverter.py (+6/-6)
report_aeroo_ooo/check_deps.py (+8/-0)
report_aeroo_ooo/report.py (+28/-1)
report_aeroo_ooo/tests/__init__.py (+4/-0)
report_aeroo_ooo/tests/test_service.py (+34/-0)
To merge this branch: bzr merge lp:~anybox/aeroo/fix-upgrade
Reviewer Review Type Date Requested Status
Christophe Combelles read only, no try Approve
Review via email: mp+214389@code.launchpad.net

This proposal supersedes a proposal from 2014-04-05.

Description of the change

To test, take any customer project using an earlier version of aeroo (no restart_ooo_cmd column in oo_config table), and perform an upgrade with the upgrade script provided by the recipe.

A quicker test is to check if the server starts *without -u report_aeroo_ooo*

Note that I am also tempted by fixing the bare excepts once the fix itself is more mature.

I'm asking ccomb, but any comments are welcome, and especially further tests by the Anybox team on customer projects.

To post a comment you must log in.
Revision history for this message
Christophe Combelles (ccomb) wrote :

+1 to replace the bare exception and add uncatched exceptions as they appear

review: Needs Fixing (read only, no try)
lp:~anybox/aeroo/fix-upgrade updated
38. By Georges Racinet <email address hidden>

Removed some bare excepts

This did not change the behaviour for me. But exception treatment is so
messy in aeroo that I could not see the warning in the except: block

I could see parts of the module that systematically wrap and reraise everything
as Exception

Revision history for this message
Georges Racinet (gracinet) wrote :

@ccomb: removed the two bare excepts I highlited earlier. Are you satisfied ?
I'll work on the other aspects of exception handling in other branches, it's a different topic in my eyes.

Revision history for this message
Christophe Combelles (ccomb) :
review: Approve (read only, no try)
lp:~anybox/aeroo/fix-upgrade updated
39. By Pierre Verkest

use exception message

40. By Pierre Verkest

[FIX]use Message instead message from uno exception

41. By Georges Racinet

[FIX] (temp) graceful instantiation of OOo service depended on bare except

put a big comment in check_deps indicating how a proper fix of this terrible
entanglement should look

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'report_aeroo/report_xml.py'
2--- report_aeroo/report_xml.py 2013-12-03 14:15:00 +0000
3+++ report_aeroo/report_xml.py 2014-04-25 09:16:09 +0000
4@@ -225,23 +225,28 @@
5 super(report_xml, self).register_all(cr)
6 ########### Run OpenOffice service ###########
7 try:
8- from report_aeroo_ooo.report import OpenOffice_service
9- except Exception, e:
10- OpenOffice_service = False
11+ from report_aeroo_ooo.report import OpenOffice_service, DocumentConversionException
12+ except (ImportError, orm.except_orm):
13+ # TODO GR temporary catching the improper except_orm,
14+ # see comment in aeroo_ooo.check_deps
15+ OpenOffice_service = None
16
17 if OpenOffice_service:
18 cr.execute("SELECT id, state FROM ir_module_module WHERE name='report_aeroo_ooo'")
19 helper_module = cr.dictfetchone()
20- helper_installed = helper_module and helper_module['state']=='installed'
21+ helper_installed = helper_module and helper_module['state'] == 'installed'
22
23 if OpenOffice_service and helper_installed:
24+ # GR internal API discrepancy, see docstring of OpenOffice_service.__init__()
25 cr.execute("SELECT host, port FROM oo_config")
26 host, port = cr.fetchone()
27 try:
28 OpenOffice_service(cr, host, port)
29 self._logger.info("OpenOffice.org connection successfully established")
30- except Exception, e:
31- self._logger.warning(str(e))
32+ except DocumentConversionException:
33+ self._logger.warning("OpenOffice conversion failed (host=%r, port=%r)", host, port,
34+ exc_info=True)
35+
36 ##############################################
37
38 cr.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'aeroo' and active = true ORDER BY id") # change for OpenERP 6.0
39
40=== modified file 'report_aeroo_ooo/DocumentConverter.py'
41--- report_aeroo_ooo/DocumentConverter.py 2014-03-05 15:11:00 +0000
42+++ report_aeroo_ooo/DocumentConverter.py 2014-04-25 09:16:09 +0000
43@@ -96,19 +96,19 @@
44 try:
45 self._context = self._resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
46 except IllegalArgumentException, exception:
47- raise DocumentConversionException("The url is invalid (%s)" % exception)
48+ raise DocumentConversionException("The url is invalid (%s)" % exception.Message)
49 except NoConnectException, exception:
50 if self._restart_ooo():
51 # We try again once
52 try:
53 self._context = self._resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
54 except NoConnectException, exception:
55- raise DocumentConversionException("Failed to connect to OpenOffice.org on host %s, port %s. %s" % (host, port, exception))
56+ raise DocumentConversionException("Failed to connect to OpenOffice.org on host %s, port %s. %s" % (host, port, exception.Message))
57
58 else:
59- raise DocumentConversionException("Failed to connect to OpenOffice.org on host %s, port %s. %s" % (host, port, exception))
60+ raise DocumentConversionException("Failed to connect to OpenOffice.org on host %s, port %s. %s" % (host, port, exception.Message))
61 except ConnectionSetupException, exception:
62- raise DocumentConversionException("Not possible to accept on a local resource (%s)" % exception)
63+ raise DocumentConversionException("Not possible to accept on a local resource (%s)" % exception.Message)
64
65 def putDocument(self, data):
66 try:
67@@ -162,7 +162,7 @@
68 try:
69 found.insertDocumentFromURL('private:stream', self._toProperties(InputStream = subStream, FilterName = "writer8"))
70 except Exception, ex:
71- print (_("Error inserting file %s on the OpenOffice document: %s") % (subreport, ex))
72+ print (_("Error inserting file %s on the OpenOffice document: %s") % (subreport, ex.Message))
73 #found = self.document.findNext(found, search)
74
75 os.unlink(subreport)
76@@ -174,7 +174,7 @@
77 try:
78 self.document.Text.getEnd().insertDocumentFromURL('private:stream', self._toProperties(InputStream = subStream, FilterName = "writer8"))
79 except Exception, ex:
80- print (_("Error inserting file %s on the OpenOffice document: %s") % (docs, ex))
81+ print (_("Error inserting file %s on the OpenOffice document: %s") % (docs, ex.Message))
82
83 def convertByPath(self, inputFile, outputFile):
84 inputUrl = self._toFileUrl(inputFile)
85
86=== modified file 'report_aeroo_ooo/check_deps.py'
87--- report_aeroo_ooo/check_deps.py 2014-03-05 13:52:34 +0000
88+++ report_aeroo_ooo/check_deps.py 2014-04-25 09:16:09 +0000
89@@ -47,6 +47,14 @@
90 error = True
91 import_errors.append(str(e))
92 if error:
93+ # TODO GR: this is ridiculous. Missing dependencies that make conversions unusable are
94+ # definitely not user errors. Either we want aeroo reports to stay functional in pure ODF
95+ # mode, or not (note that this is imported in all cases at startup).
96+ # the dependency checking should definitely not rely on such. It worked because caller code
97+ # (report_aeroo.report_xml) used to catch everything
98+ # (fixing this could be in another branch, I can't chase all
99+ # consequencies right now). Probably we should replace all this cruft with OpenERP's native
100+ # way of checking dependencies (through manifest file).
101 raise orm.except_orm(_('Warning!')+' '+_('Unmet python dependencies!'), '\n'.join(import_errors))
102
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
104
105=== modified file 'report_aeroo_ooo/report.py'
106--- report_aeroo_ooo/report.py 2014-03-31 13:08:07 +0000
107+++ report_aeroo_ooo/report.py 2014-04-25 09:16:09 +0000
108@@ -33,11 +33,38 @@
109 from openerp.osv import orm, fields
110 from openerp import netsvc
111 from .DocumentConverter import DocumentConverter
112+from .DocumentConverter import DocumentConversionException # noqa (just forwarding)
113+
114
115 class OpenOffice_service (DocumentConverter, netsvc.Service):
116
117 def __init__(self, cr, host, port):
118- cr.execute("SELECT host, port, ooo_restart_cmd FROM oo_config")
119+ """Init the service, reading properties from database.
120+
121+ Care is taken not to break if the ``ooo_restart_cmd``` column does
122+ not exist in config table.
123+
124+ This is useful for transitional situations
125+ (upgrade/migrate scripts that need to load the database for inspection
126+ before launching the upgrade itself.
127+
128+ If the column is missing, the restart command is set to ``False``, the
129+ OpenERP standard missing marker. This is equivalent to the situation
130+ once the upgrade is complete.
131+
132+ .. note:: parameters ``host`` and ``port`` are discarded by the current
133+ implementation, being replaced by values read from the config table.
134+
135+ The standard instantiation caller, :mod:`openerp.addons.report_aeroo.report_xml`,
136+ performs the same lookup for these parameters, and passes them. This
137+ is an internal API discrepancy, probably introduced precisely with the
138+ ``ooo_restard_cmd`` parameter, and that we may want to take care of in a second
139+ move.
140+ """
141+ cr.execute("SELECT id FROM ir_model_fields "
142+ "WHERE name='ooo_restart_cmd' AND model='oo.config'")
143+ restart_col = 'ooo_restart_cmd' if cr.fetchone() else 'FALSE AS ooo_restart_cmd'
144+ cr.execute("SELECT host, port, " + restart_col + " FROM oo_config")
145 host, port, ooo_restart_cmd = cr.fetchone()
146 DocumentConverter.__init__(self, host, port, ooo_restart_cmd)
147 netsvc.Service.__init__(self, 'openoffice')
148
149=== added directory 'report_aeroo_ooo/tests'
150=== added file 'report_aeroo_ooo/tests/__init__.py'
151--- report_aeroo_ooo/tests/__init__.py 1970-01-01 00:00:00 +0000
152+++ report_aeroo_ooo/tests/__init__.py 2014-04-25 09:16:09 +0000
153@@ -0,0 +1,4 @@
154+from . import test_service
155+
156+fast_suite = [test_service,
157+ ]
158
159=== added file 'report_aeroo_ooo/tests/test_service.py'
160--- report_aeroo_ooo/tests/test_service.py 1970-01-01 00:00:00 +0000
161+++ report_aeroo_ooo/tests/test_service.py 2014-04-25 09:16:09 +0000
162@@ -0,0 +1,34 @@
163+from contextlib import contextmanager
164+from openerp.tests.common import TransactionCase
165+from ..report import OpenOffice_service
166+from ..DocumentConverter import DocumentConverter
167+
168+
169+def mock_doc_converter_init(self, host='localhost', port=8100, ooo_restart_cmd=None):
170+ self._host = host
171+ self._port = port
172+ self._ooo_restart_cmd = ooo_restart_cmd
173+
174+
175+@contextmanager
176+def mock_doc_converter():
177+ saved_init = DocumentConverter.__init__
178+ DocumentConverter.__init__ = mock_doc_converter_init
179+ yield
180+ DocumentConverter.__init__ = saved_init
181+
182+
183+class TestOooService(TransactionCase):
184+
185+ def test_bare_instantiation(self):
186+ with mock_doc_converter():
187+ OpenOffice_service(self.cr, 'the_host', 8101)
188+ # no assertion because of internal API discrepancy
189+
190+ def test_instantiation_missing_column(self):
191+ self.cr.execute("ALTER TABLE oo_config DROP COLUMN ooo_restart_cmd")
192+ self.cr.execute("DELETE FROM ir_model_fields "
193+ "WHERE model='oo.config' AND name='ooo_restart_cmd'")
194+ with mock_doc_converter():
195+ service = OpenOffice_service(self.cr, 'the_host', 8101)
196+ self.assertFalse(service._ooo_restart_cmd)

Subscribers

People subscribed via source and target branches