Commit c562ed93 authored by Mike Hibler's avatar Mike Hibler

Reformat the old subboss class code.

For those of us with 80-column vision...
parent 81762ce2
......@@ -340,7 +340,7 @@ class EmulabServer:
self.instances["osid"] = osid(self);
self.instances["node"] = node(self);
self.instances["elabinelab"] = elabinelab(self);
self.instances["subboss"] = subboss(self);
self.instances["subboss"] = subboss(self);
self.instances["blob"] = blob(self);
self.instances["dataset"] = dataset(self);
return
......@@ -4431,8 +4431,10 @@ class subboss:
lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where "
"imageid=%s and subboss_id=%s", (str(argdict["imageid"]), argdict["subboss_id"]))
res = DBQueryFatal("select load_address,frisbee_pid "
" from subboss_images "
"where imageid=%s and subboss_id=%s",
(str(argdict["imageid"]), argdict["subboss_id"]))
if len(res) == 0:
unlock_tables()
......@@ -4443,7 +4445,8 @@ class subboss:
result["address"] = res[0][0]
result["frisbee_pid"] = res[0][1]
return EmulabResponse(RESPONSE_SUCCESS, value=result, output=str(result))
return EmulabResponse(RESPONSE_SUCCESS,
value=result, output=str(result))
#
......@@ -4481,30 +4484,39 @@ class subboss:
lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("select load_address,frisbee_pid "
" from subboss_images"
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0:
# This pair doesn't exist in the table yet. Better insert it
res = DBQueryFatal("insert into subboss_images values (%s,%s,'',0,1,0)",
res = DBQueryFatal("insert into subboss_images "
" values (%s,%s,'',0,1,0)",
(argdict["subboss_id"], argdict["imageid"]))
elif res[0][0] != "":
# Subboss is already running a frisbeed for this image, so just update the
# busy flag
subboss_image_set_busy(argdict["subboss_id"], argdict["imageid"])
# Subboss is already running a frisbeed for this image,
# so just update the busy flag
subboss_image_set_busy(argdict["subboss_id"],
argdict["imageid"])
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="Frisbee server already running")
return EmulabResponse(RESPONSE_ERROR,
output="Frisbee server already running")
elif res[0][1] != 0:
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="Bad DB state: frisbeed PID without load_address")
return EmulabResponse(RESPONSE_ERROR,
output="Bad DB state: "
"frisbeed PID without load_address")
res = DBQueryFatal("update subboss_images set load_address = %s, load_busy = 1 where "
"subboss_id=%s and imageid=%s", (mcast_address,
argdict["subboss_id"], argdict["imageid"]))
res = DBQueryFatal("update subboss_images "
" set load_address = %s, load_busy = 1 "
"where subboss_id=%s and imageid=%s",
(mcast_address,
argdict["subboss_id"], argdict["imageid"]))
unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS, value=mcast_address, output=mcast_address)
return EmulabResponse(RESPONSE_SUCCESS,
value=mcast_address, output=mcast_address)
#
# Reset a subboss image entry; called when frisbeed is no longer needed
......@@ -4534,16 +4546,18 @@ class subboss:
lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("select load_address,frisbee_pid "
" from subboss_images "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0:
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image")
res = DBQueryFatal("update subboss_images set load_address = '', frisbee_pid = 0, load_busy = 0 "
"where subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("update subboss_images "
" set load_address='',frisbee_pid=0, load_busy=0 "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS)
......@@ -4562,7 +4576,8 @@ class subboss:
except NoLoginsError, e:
return EmulabResponse(RESPONSE_REFUSED, output=str(e))
argerror = CheckRequiredArgs(argdict, ("subboss_id", "imageid", "frisbee_pid"))
argerror = CheckRequiredArgs(argdict,
("subboss_id", "imageid", "frisbee_pid"))
if (argerror):
return argerror
......@@ -4576,19 +4591,23 @@ class subboss:
lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("select load_address,frisbee_pid "
" from subboss_images "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0:
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image")
elif res[0][0] == "":
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No address for image")
res = DBQueryFatal("update subboss_images set frisbee_pid=%s where subboss_id=%s and "
"imageid=%s", (argdict["frisbee_pid"], argdict["subboss_id"],
str(argdict["imageid"])))
return EmulabResponse(RESPONSE_ERROR,
output="No address for image")
res = DBQueryFatal("update subboss_images "
" set frisbee_pid=%s "
"where subboss_id=%s and imageid=%s",
(argdict["frisbee_pid"], argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS)
......@@ -4607,7 +4626,8 @@ class subboss:
except NoLoginsError, e:
return EmulabResponse(RESPONSE_REFUSED, output=str(e))
argerror = CheckRequiredArgs(argdict, ("subboss_id", "imageid", "sync"))
argerror = CheckRequiredArgs(argdict,
("subboss_id", "imageid", "sync"))
if (argerror):
return argerror
......@@ -4621,23 +4641,28 @@ class subboss:
lock_subboss_image_table()
res = DBQueryFatal("select sync from subboss_images where "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("select sync from subboss_images "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0:
# This pair doesn't exist in the table yet. Better insert it
res = DBQueryFatal("insert into subboss_images values (%s,%s,'',0,0,%d)",
(argdict["subboss_id"], str(argdict["imageid"]), argdict["sync"]))
res = DBQueryFatal("insert into subboss_images "
" values (%s,%s,'',0,0,%d)",
(argdict["subboss_id"],
str(argdict["imageid"]), argdict["sync"]))
else:
res = DBQueryFatal("update subboss_images set sync=%s where subboss_id=%s and "
"imageid=%s", (argdict["sync"], argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("update subboss_images "
" set sync=%s "
"where subboss_id=%s and imageid=%s",
(argdict["sync"], argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS)
#
# See if subboss image 'busy' flag is set; indicates frisbeed should run again
# See if subboss image 'busy' flag is set;
# indicates frisbeed should run again
#
def image_requested(self, version, argdict):
if version != self.VERSION:
......@@ -4665,23 +4690,29 @@ class subboss:
lock_subboss_image_table()
busy = 0
res = DBQueryFatal("select load_address,frisbee_pid,load_busy from subboss_images where "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"],
str(argdict["imageid"])))
res = DBQueryFatal("select load_address,frisbee_pid,load_busy "
" from subboss_images "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0:
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image")
elif res[0][0] == "":
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No address for image")
return EmulabResponse(RESPONSE_ERROR,
output="No address for image")
elif res[0][1] == 0:
unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="PID not set for image")
return EmulabResponse(RESPONSE_ERROR,
output="PID not set for image")
if res[0][2] > 0:
busy = 1
res = DBQueryFatal("update subboss_images set load_busy = 0 where subboss_id=%s and "
"imageid=%s", (argdict["subboss_id"], str(argdict["imageid"])))
res = DBQueryFatal("update subboss_images "
" set load_busy=0 "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables()
......@@ -4722,7 +4753,9 @@ class subboss:
# has permission to load the image in libosload so we don't need to
# check again in frisbeelauncher. Only a subboss can make this request
# anyway.
(exitval, output) = runcommand(TBDIR + "/sbin/subboss_wrapper frisbeelauncher " + argstr)
(exitval, output) = runcommand(TBDIR +
"/sbin/subboss_wrapper frisbeelauncher " +
argstr)
if exitval:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
......@@ -4730,7 +4763,8 @@ class subboss:
#
# Success. Must get the loadinfo out of the DB so we can pass it back.
#
res = DBQueryFatal("select load_address from frisbee_blobs where imageid=%s",
res = DBQueryFatal("select load_address "
" from frisbee_blobs where imageid=%s",
(str(argdict["imageid"]),))
# Hmm, something went wrong?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment