Merge lp:~openerp-community/openobject-server/stefan-therp_lp879872-6.1 into lp:openobject-server

Proposed by Stefan Rijnhart (Opener)
Status: Work in progress
Proposed branch: lp:~openerp-community/openobject-server/stefan-therp_lp879872-6.1
Merge into: lp:openobject-server
Diff against target: 50 lines (+9/-10)
2 files modified
openerp/service/web_services.py (+8/-8)
openerp/tools/misc.py (+1/-2)
To merge this branch: bzr merge lp:~openerp-community/openobject-server/stefan-therp_lp879872-6.1
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Needs Information
Review via email: mp+80125@code.launchpad.net

Description of the change

This branch slightly modifies the code around the pg_restore command, so that any error condition is properly signalled.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi Stefan,

The documentation[1] mentions a warning about the use of Popen.wait() in conjunction with the subprocess writing large amount of data to the pipes, and suggests Popen.communicate() as an alternative. We seem to be fully reading the pipes before wait() is called, so I imagine it might be safe, but wouldn't Popen.communicate() be a better match for our use case?

Also, have you by happenstance tested this code on Windows, to make sure the return codes are identical and reliable on all platforms?

Thanks!

[1] http://docs.python.org/library/subprocess.html#subprocess.Popen.wait

review: Needs Information
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

(Setting the branch to Work In Progress to indicate we expect some more investigation before merging it. Thanks!)

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Not sure who changed the status of this proposal to 'Needs review' yesterday evening. As far as I'm concerned it is still 'Work in progress' for lack of a status indicating 'Any community member, feel free to work on it'

Revision history for this message
Antony Lesuisse (OpenERP) (al-openerp) wrote :

It was me. Sorry, set it back to 'Needs review' once you think it's ready. Please make sure you dont forget to reap your dead children.

Unmerged revisions

3774. By Stefan Rijnhart (Opener)

[FIX] adapted other call to exec_pg_command_pipe() to modified return value

3773. By Stefan Rijnhart (Opener)

[FIX] check proper return value of pg_restore

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/service/web_services.py'
--- openerp/service/web_services.py 2011-10-13 10:47:50 +0000
+++ openerp/service/web_services.py 2011-10-22 12:02:24 +0000
@@ -213,10 +213,10 @@
213 cmd.append('--port=' + str(tools.config['db_port']))213 cmd.append('--port=' + str(tools.config['db_port']))
214 cmd.append(db_name)214 cmd.append(db_name)
215215
216 stdin, stdout = tools.exec_pg_command_pipe(*tuple(cmd))216 pop = tools.exec_pg_command_pipe(*tuple(cmd))
217 stdin.close()217 pop.stdin.close()
218 data = stdout.read()218 data = pop.stdout.read()
219 res = stdout.close()219 res = pop.wait()
220 if res:220 if res:
221 logger.notifyChannel("web-services", netsvc.LOG_ERROR,221 logger.notifyChannel("web-services", netsvc.LOG_ERROR,
222 'DUMP DB: %s failed\n%s' % (db_name, data))222 'DUMP DB: %s failed\n%s' % (db_name, data))
@@ -257,11 +257,11 @@
257 args2=list(args2)257 args2=list(args2)
258 args2.append(' ' + tmpfile)258 args2.append(' ' + tmpfile)
259 args2=tuple(args2)259 args2=tuple(args2)
260 stdin, stdout = tools.exec_pg_command_pipe(*args2)260 pop = tools.exec_pg_command_pipe(*args2)
261 if not os.name == "nt":261 if not os.name == "nt":
262 stdin.write(base64.decodestring(data))262 pop.stdin.write(base64.decodestring(data))
263 stdin.close()263 pop.stdin.close()
264 res = stdout.close()264 res = pop.wait()
265 if res:265 if res:
266 raise Exception, "Couldn't restore database"266 raise Exception, "Couldn't restore database"
267 logger.notifyChannel("web-services", netsvc.LOG_INFO,267 logger.notifyChannel("web-services", netsvc.LOG_INFO,
268268
=== modified file 'openerp/tools/misc.py'
--- openerp/tools/misc.py 2011-09-22 09:54:43 +0000
+++ openerp/tools/misc.py 2011-10-22 12:02:24 +0000
@@ -103,10 +103,9 @@
103 raise Exception('Couldn\'t find %s' % name)103 raise Exception('Couldn\'t find %s' % name)
104 # on win32, passing close_fds=True is not compatible104 # on win32, passing close_fds=True is not compatible
105 # with redirecting std[in/err/out]105 # with redirecting std[in/err/out]
106 pop = subprocess.Popen((prog,) + args, bufsize= -1,106 return subprocess.Popen((prog,) + args, bufsize= -1,
107 stdin=subprocess.PIPE, stdout=subprocess.PIPE,107 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
108 close_fds=(os.name=="posix"))108 close_fds=(os.name=="posix"))
109 return (pop.stdin, pop.stdout)
110109
111def exec_command_pipe(name, *args):110def exec_command_pipe(name, *args):
112 prog = find_in_path(name)111 prog = find_in_path(name)