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: ...@@ -340,7 +340,7 @@ class EmulabServer:
self.instances["osid"] = osid(self); self.instances["osid"] = osid(self);
self.instances["node"] = node(self); self.instances["node"] = node(self);
self.instances["elabinelab"] = elabinelab(self); self.instances["elabinelab"] = elabinelab(self);
self.instances["subboss"] = subboss(self); self.instances["subboss"] = subboss(self);
self.instances["blob"] = blob(self); self.instances["blob"] = blob(self);
self.instances["dataset"] = dataset(self); self.instances["dataset"] = dataset(self);
return return
...@@ -4431,8 +4431,10 @@ class subboss: ...@@ -4431,8 +4431,10 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where " res = DBQueryFatal("select load_address,frisbee_pid "
"imageid=%s and subboss_id=%s", (str(argdict["imageid"]), argdict["subboss_id"])) " from subboss_images "
"where imageid=%s and subboss_id=%s",
(str(argdict["imageid"]), argdict["subboss_id"]))
if len(res) == 0: if len(res) == 0:
unlock_tables() unlock_tables()
...@@ -4443,7 +4445,8 @@ class subboss: ...@@ -4443,7 +4445,8 @@ class subboss:
result["address"] = res[0][0] result["address"] = res[0][0]
result["frisbee_pid"] = res[0][1] 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: ...@@ -4481,30 +4484,39 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where " res = DBQueryFatal("select load_address,frisbee_pid "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"], " from subboss_images"
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0: if len(res) == 0:
# This pair doesn't exist in the table yet. Better insert it # 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"])) (argdict["subboss_id"], argdict["imageid"]))
elif res[0][0] != "": elif res[0][0] != "":
# Subboss is already running a frisbeed for this image, so just update the # Subboss is already running a frisbeed for this image,
# busy flag # so just update the busy flag
subboss_image_set_busy(argdict["subboss_id"], argdict["imageid"]) subboss_image_set_busy(argdict["subboss_id"],
argdict["imageid"])
unlock_tables() 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: elif res[0][1] != 0:
unlock_tables() 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 " res = DBQueryFatal("update subboss_images "
"subboss_id=%s and imageid=%s", (mcast_address, " set load_address = %s, load_busy = 1 "
argdict["subboss_id"], argdict["imageid"])) "where subboss_id=%s and imageid=%s",
(mcast_address,
argdict["subboss_id"], argdict["imageid"]))
unlock_tables() 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 # Reset a subboss image entry; called when frisbeed is no longer needed
...@@ -4534,16 +4546,18 @@ class subboss: ...@@ -4534,16 +4546,18 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where " res = DBQueryFatal("select load_address,frisbee_pid "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"], " from subboss_images "
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0: if len(res) == 0:
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image") return EmulabResponse(RESPONSE_ERROR, output="No such image")
res = DBQueryFatal("update subboss_images set load_address = '', frisbee_pid = 0, load_busy = 0 " res = DBQueryFatal("update subboss_images "
"where subboss_id=%s and imageid=%s", (argdict["subboss_id"], " set load_address='',frisbee_pid=0, load_busy=0 "
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS) return EmulabResponse(RESPONSE_SUCCESS)
...@@ -4562,7 +4576,8 @@ class subboss: ...@@ -4562,7 +4576,8 @@ class subboss:
except NoLoginsError, e: except NoLoginsError, e:
return EmulabResponse(RESPONSE_REFUSED, output=str(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): if (argerror):
return argerror return argerror
...@@ -4576,19 +4591,23 @@ class subboss: ...@@ -4576,19 +4591,23 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
res = DBQueryFatal("select load_address,frisbee_pid from subboss_images where " res = DBQueryFatal("select load_address,frisbee_pid "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"], " from subboss_images "
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0: if len(res) == 0:
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image") return EmulabResponse(RESPONSE_ERROR, output="No such image")
elif res[0][0] == "": elif res[0][0] == "":
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No address for image") 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"], res = DBQueryFatal("update subboss_images "
str(argdict["imageid"]))) " set frisbee_pid=%s "
"where subboss_id=%s and imageid=%s",
(argdict["frisbee_pid"], argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS) return EmulabResponse(RESPONSE_SUCCESS)
...@@ -4607,7 +4626,8 @@ class subboss: ...@@ -4607,7 +4626,8 @@ class subboss:
except NoLoginsError, e: except NoLoginsError, e:
return EmulabResponse(RESPONSE_REFUSED, output=str(e)) return EmulabResponse(RESPONSE_REFUSED, output=str(e))
argerror = CheckRequiredArgs(argdict, ("subboss_id", "imageid", "sync")) argerror = CheckRequiredArgs(argdict,
("subboss_id", "imageid", "sync"))
if (argerror): if (argerror):
return argerror return argerror
...@@ -4621,23 +4641,28 @@ class subboss: ...@@ -4621,23 +4641,28 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
res = DBQueryFatal("select sync from subboss_images where " res = DBQueryFatal("select sync from subboss_images "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"], "where subboss_id=%s and imageid=%s",
str(argdict["imageid"]))) (argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0: if len(res) == 0:
# This pair doesn't exist in the table yet. Better insert it # This pair doesn't exist in the table yet. Better insert it
res = DBQueryFatal("insert into subboss_images values (%s,%s,'',0,0,%d)", res = DBQueryFatal("insert into subboss_images "
(argdict["subboss_id"], str(argdict["imageid"]), argdict["sync"])) " values (%s,%s,'',0,0,%d)",
(argdict["subboss_id"],
str(argdict["imageid"]), argdict["sync"]))
else: else:
res = DBQueryFatal("update subboss_images set sync=%s where subboss_id=%s and " res = DBQueryFatal("update subboss_images "
"imageid=%s", (argdict["sync"], argdict["subboss_id"], " set sync=%s "
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["sync"], argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_SUCCESS) 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): def image_requested(self, version, argdict):
if version != self.VERSION: if version != self.VERSION:
...@@ -4665,23 +4690,29 @@ class subboss: ...@@ -4665,23 +4690,29 @@ class subboss:
lock_subboss_image_table() lock_subboss_image_table()
busy = 0 busy = 0
res = DBQueryFatal("select load_address,frisbee_pid,load_busy from subboss_images where " res = DBQueryFatal("select load_address,frisbee_pid,load_busy "
"subboss_id=%s and imageid=%s", (argdict["subboss_id"], " from subboss_images "
str(argdict["imageid"]))) "where subboss_id=%s and imageid=%s",
(argdict["subboss_id"], str(argdict["imageid"])))
if len(res) == 0: if len(res) == 0:
unlock_tables() unlock_tables()
return EmulabResponse(RESPONSE_ERROR, output="No such image") return EmulabResponse(RESPONSE_ERROR, output="No such image")
elif res[0][0] == "": elif res[0][0] == "":
unlock_tables() 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: elif res[0][1] == 0:
unlock_tables() 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: if res[0][2] > 0:
busy = 1 busy = 1
res = DBQueryFatal("update subboss_images set load_busy = 0 where subboss_id=%s and " res = DBQueryFatal("update subboss_images "
"imageid=%s", (argdict["subboss_id"], str(argdict["imageid"]))) " set load_busy=0 "
"where subboss_id=%s and imageid=%s",
(argdict["subboss_id"],
str(argdict["imageid"])))
unlock_tables() unlock_tables()
...@@ -4722,7 +4753,9 @@ class subboss: ...@@ -4722,7 +4753,9 @@ class subboss:
# has permission to load the image in libosload so we don't need to # 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 # check again in frisbeelauncher. Only a subboss can make this request
# anyway. # anyway.
(exitval, output) = runcommand(TBDIR + "/sbin/subboss_wrapper frisbeelauncher " + argstr) (exitval, output) = runcommand(TBDIR +
"/sbin/subboss_wrapper frisbeelauncher " +
argstr)
if exitval: if exitval:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output) return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
...@@ -4730,7 +4763,8 @@ class subboss: ...@@ -4730,7 +4763,8 @@ class subboss:
# #
# Success. Must get the loadinfo out of the DB so we can pass it back. # 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"]),)) (str(argdict["imageid"]),))
# Hmm, something went wrong? # 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