Skip to content

Commit

Permalink
web status: add alert_msg
Browse files Browse the repository at this point in the history
implement a simple way for action ressources to report errors to users

if action resource returns a tuple, then it is URL, alert_msg, the message is displayed
in the next web page

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Nov 28, 2011
1 parent 43eb37b commit 6eea469
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
7 changes: 7 additions & 0 deletions master/buildbot/status/web/base.py
Expand Up @@ -213,6 +213,7 @@ def getContext(self, request):
welcomeurl = rootpath,
authz = self.getAuthz(request),
request = request,
alert_msg = request.args.get("alert_msg", [""])[0],
)


Expand All @@ -230,11 +231,17 @@ def performAction(self, request):
@param request: the web request
@returns: URL via Deferred
can also return (URL, alert_msg) to display simple
feedback to user in case of failure
"""

def render(self, request):
d = defer.maybeDeferred(lambda : self.performAction(request))
def redirect(url):
if isinstance(url, tuple):
url, alert_msg = url
if alert_msg:
url += "?alert_msg="+urllib.quote(alert_msg, safe='')
request.redirect(url)
request.write("see <a href='%s'>%s</a>" % (url,url))
try:
Expand Down
17 changes: 11 additions & 6 deletions master/buildbot/status/web/build.py
Expand Up @@ -58,19 +58,24 @@ def performAction(self, req):
comments = req.args.get("comments", ["<no reason specified>"])[0]
reason = ("The web-page 'rebuild' button was pressed by "
"'%s': %s\n" % (name, comments))
msg = ""
extraProperties = getAndCheckProperties(req)
if not bc or not b.isFinished() or extraProperties is None:
log.msg("could not rebuild: bc=%s, isFinished=%s"
% (bc, b.isFinished()))
# TODO: indicate an error
msg = "could not rebuild: "
if b.isFinished():
msg += "build still not finished "
if bc:
msg += "could not get builder control"
else:
d = bc.rebuildBuild(b, reason, extraProperties)
wfd = defer.waitForDeferred(d)
yield wfd
tup = wfd.getResult()
# check that (bsid, brids) were properly stored
if not isinstance(tup, (int, dict)):
log.err("while rebuilding a build")
if not (isinstance(tup, tuple) and
isinstance(tup[0], int) and
isinstance(tup[1], dict)):
msg = "rebuilding a build failed "+ str(tup)
# we're at
# http://localhost:8080/builders/NAME/builds/5/rebuild?[args]
# Where should we send them?
Expand All @@ -82,7 +87,7 @@ def performAction(self, req):
# evidence of their build starting (or to see the reason that it
# didn't start). This should be the Builder page.

url = path_to_builder(req, self.builder)
url = path_to_builder(req, self.builder), msg
yield url


Expand Down
6 changes: 6 additions & 0 deletions master/buildbot/status/web/templates/layout.html
Expand Up @@ -51,6 +51,12 @@

{%- block barecontent -%}
<hr/>

{% if alert_msg != "" %}
<div class="alert">
{{ alert_msg }}
</div>
{% endif %}

<div class="content">
{%- block content -%}
Expand Down

0 comments on commit 6eea469

Please sign in to comment.