prservice: Added sanity check for prservice connection.

Fixed bug [YOCTO #2052]. Added sanity check for variables of PRSERV_HOST
and PRSERV_PORT, also for the connection availabity of prservice.

(From OE-Core rev: 7588a4f2e2728da0ff7a773b18527f3711b138f2)

Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Lianhao Lu 2012-03-07 15:36:45 +08:00 committed by Richard Purdie
parent 10d6c4e056
commit e189a7113c
3 changed files with 23 additions and 2 deletions

View File

@ -21,11 +21,13 @@ python prexport_handler () {
bb.fatal("prexport_handler: export failed!")
(metainfo, datainfo) = retval
if not datainfo:
bb.error("prexport_handler: No AUROPR values found for %s" % ver)
bb.warn("prexport_handler: No AUROPR values found for %s" % ver)
return
oe.prservice.prserv_export_tofile(e.data, None, datainfo, False)
elif isinstance(e, bb.event.ParseStarted):
import bb.utils
import oe.prservice
oe.prservice.prserv_check_avail(e.data)
#remove dumpfile
bb.utils.remove(e.data.getVar('PRSERV_DUMPFILE', True))
elif isinstance(e, bb.event.ParseCompleted):

View File

@ -12,6 +12,9 @@ python primport_handler () {
for (version, pkgarch, checksum, value) in imported:
bb.note("imported (%s,%s,%s,%d)" % (version, pkgarch, checksum, value))
elif isinstance(e, bb.event.ParseStarted):
import oe.prservice
oe.prservice.prserv_check_avail(e.data)
}
addhandler primport_handler

View File

@ -1,12 +1,15 @@
import bb
def prserv_make_conn(d):
def prserv_make_conn(d, check = False):
import prserv.serv
host = d.getVar("PRSERV_HOST",True)
port = d.getVar("PRSERV_PORT",True)
try:
conn = None
conn = prserv.serv.PRServerConnection(host,int(port))
if check:
if not conn.ping():
raise Exception('service not available')
d.setVar("__PRSERV_CONN",conn)
except Exception, exc:
bb.fatal("Connecting to PR service %s:%s failed: %s" % (host, port, str(exc)))
@ -111,3 +114,16 @@ def prserv_export_tofile(d, metainfo, datainfo, lockdown, nomax=False):
f.write("PRAUTO_%s_%s = \"%s\"\n" % (str(datainfo[idx[i]]['version']),str(datainfo[idx[i]]['pkgarch']),str(datainfo[idx[i]]['value'])))
f.close()
bb.utils.unlockfile(lf)
def prserv_check_avail(d):
host = d.getVar("PRSERV_HOST",True)
port = d.getVar("PRSERV_PORT",True)
try:
if not host:
raise TypeError
else:
port = int(port)
except TypeError:
bb.fatal("Undefined or incorrect values of PRSERV_HOST or PRSERV_PORT")
else:
prserv_make_conn(d, True)