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
1=== modified file 'openerp/service/web_services.py'
2--- openerp/service/web_services.py 2011-10-13 10:47:50 +0000
3+++ openerp/service/web_services.py 2011-10-22 12:02:24 +0000
4@@ -213,10 +213,10 @@
5 cmd.append('--port=' + str(tools.config['db_port']))
6 cmd.append(db_name)
7
8- stdin, stdout = tools.exec_pg_command_pipe(*tuple(cmd))
9- stdin.close()
10- data = stdout.read()
11- res = stdout.close()
12+ pop = tools.exec_pg_command_pipe(*tuple(cmd))
13+ pop.stdin.close()
14+ data = pop.stdout.read()
15+ res = pop.wait()
16 if res:
17 logger.notifyChannel("web-services", netsvc.LOG_ERROR,
18 'DUMP DB: %s failed\n%s' % (db_name, data))
19@@ -257,11 +257,11 @@
20 args2=list(args2)
21 args2.append(' ' + tmpfile)
22 args2=tuple(args2)
23- stdin, stdout = tools.exec_pg_command_pipe(*args2)
24+ pop = tools.exec_pg_command_pipe(*args2)
25 if not os.name == "nt":
26- stdin.write(base64.decodestring(data))
27- stdin.close()
28- res = stdout.close()
29+ pop.stdin.write(base64.decodestring(data))
30+ pop.stdin.close()
31+ res = pop.wait()
32 if res:
33 raise Exception, "Couldn't restore database"
34 logger.notifyChannel("web-services", netsvc.LOG_INFO,
35
36=== modified file 'openerp/tools/misc.py'
37--- openerp/tools/misc.py 2011-09-22 09:54:43 +0000
38+++ openerp/tools/misc.py 2011-10-22 12:02:24 +0000
39@@ -103,10 +103,9 @@
40 raise Exception('Couldn\'t find %s' % name)
41 # on win32, passing close_fds=True is not compatible
42 # with redirecting std[in/err/out]
43- pop = subprocess.Popen((prog,) + args, bufsize= -1,
44+ return subprocess.Popen((prog,) + args, bufsize= -1,
45 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
46 close_fds=(os.name=="posix"))
47- return (pop.stdin, pop.stdout)
48
49 def exec_command_pipe(name, *args):
50 prog = find_in_path(name)