Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Fixed #406 -- return error detail if sudo fails in knife bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Dec 26, 2013
1 parent 34990b5 commit 8e5778d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
17 changes: 17 additions & 0 deletions api/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Deis exception classes.
"""

from __future__ import unicode_literals

from rest_framework.exceptions import APIException
from rest_framework import status


class BuildNodeError(APIException):
"""Indicates a problem in building or bootstrapping a node."""

status_code = status.HTTP_401_UNAUTHORIZED

def __init__(self, detail=None):
self.detail = detail
6 changes: 5 additions & 1 deletion api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from deis import settings
from provider import import_provider_module
from .exceptions import BuildNodeError

# import user-defined config management module
CM = importlib.import_module(settings.CM_MODULE)
Expand All @@ -32,7 +33,10 @@ def build_node(node):
node.fqdn = fqdn
node.metadata = metadata
node.save()
CM.bootstrap_node(node.flat())
try:
CM.bootstrap_node(node.flat())
except RuntimeError as err:
raise BuildNodeError(str(err))


@task
Expand Down
9 changes: 5 additions & 4 deletions client/deis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,10 +2011,9 @@ def main():
cmd, help_flag = parse_args(cmd)
# print help if it was asked for
if help_flag:
if cmd != 'help':
if cmd in dir(cli):
print(trim(getattr(cli, cmd).__doc__))
return
if cmd != 'help' and cmd in dir(cli):
print(trim(getattr(cli, cmd).__doc__))
return
docopt(__doc__, argv=['--help'])
# unless cmd needs to use sys.argv directly
if hasattr(cli, cmd):
Expand All @@ -2036,6 +2035,8 @@ def main():
print('{} {}'.format(resp.status_code, resp.reason))
try:
msg = resp.json()
if 'detail' in msg:
msg = "Detail:\n{}".format(msg['detail'])
except:
msg = resp.text
print(msg)
Expand Down
4 changes: 2 additions & 2 deletions cm/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def bootstrap_node(node):
output = f.read()
print(output)
# raise an exception if bootstrap failed
if rc != 0:
raise RuntimeError('Node Bootstrap Error')
if rc != 0 or 'incorrect password' in output:
raise RuntimeError('Node Bootstrap Error:\n' + output)
# remove temp files from filesystem
finally:
os.remove(pk_path)
Expand Down
13 changes: 13 additions & 0 deletions docs/server/api.exceptions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:description: Python API Reference for the Deis api.exceptions module
:keywords: deis, api.exceptions, python, api

==============
api.exceptions
==============

.. contents::
:local:
.. currentmodule:: api.exceptions

.. automodule:: api.exceptions
:members:
1 change: 1 addition & 0 deletions docs/server/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Server Reference
rest

api.admin
api.exceptions
api.fields
api.models
api.routers
Expand Down

0 comments on commit 8e5778d

Please sign in to comment.