Skip to content

Commit 8e5778d

Browse files
committed
Fixed #406 -- return error detail if sudo fails in knife bootstrap.
1 parent 34990b5 commit 8e5778d

6 files changed

Lines changed: 43 additions & 7 deletions

File tree

api/exceptions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Deis exception classes.
3+
"""
4+
5+
from __future__ import unicode_literals
6+
7+
from rest_framework.exceptions import APIException
8+
from rest_framework import status
9+
10+
11+
class BuildNodeError(APIException):
12+
"""Indicates a problem in building or bootstrapping a node."""
13+
14+
status_code = status.HTTP_401_UNAUTHORIZED
15+
16+
def __init__(self, detail=None):
17+
self.detail = detail

api/tasks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from deis import settings
88
from provider import import_provider_module
9+
from .exceptions import BuildNodeError
910

1011
# import user-defined config management module
1112
CM = importlib.import_module(settings.CM_MODULE)
@@ -32,7 +33,10 @@ def build_node(node):
3233
node.fqdn = fqdn
3334
node.metadata = metadata
3435
node.save()
35-
CM.bootstrap_node(node.flat())
36+
try:
37+
CM.bootstrap_node(node.flat())
38+
except RuntimeError as err:
39+
raise BuildNodeError(str(err))
3640

3741

3842
@task

client/deis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,9 @@ def main():
20112011
cmd, help_flag = parse_args(cmd)
20122012
# print help if it was asked for
20132013
if help_flag:
2014-
if cmd != 'help':
2015-
if cmd in dir(cli):
2016-
print(trim(getattr(cli, cmd).__doc__))
2017-
return
2014+
if cmd != 'help' and cmd in dir(cli):
2015+
print(trim(getattr(cli, cmd).__doc__))
2016+
return
20182017
docopt(__doc__, argv=['--help'])
20192018
# unless cmd needs to use sys.argv directly
20202019
if hasattr(cli, cmd):
@@ -2036,6 +2035,8 @@ def main():
20362035
print('{} {}'.format(resp.status_code, resp.reason))
20372036
try:
20382037
msg = resp.json()
2038+
if 'detail' in msg:
2039+
msg = "Detail:\n{}".format(msg['detail'])
20392040
except:
20402041
msg = resp.text
20412042
print(msg)

cm/chef.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def bootstrap_node(node):
111111
output = f.read()
112112
print(output)
113113
# raise an exception if bootstrap failed
114-
if rc != 0:
115-
raise RuntimeError('Node Bootstrap Error')
114+
if rc != 0 or 'incorrect password' in output:
115+
raise RuntimeError('Node Bootstrap Error:\n' + output)
116116
# remove temp files from filesystem
117117
finally:
118118
os.remove(pk_path)

docs/server/api.exceptions.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:description: Python API Reference for the Deis api.exceptions module
2+
:keywords: deis, api.exceptions, python, api
3+
4+
==============
5+
api.exceptions
6+
==============
7+
8+
.. contents::
9+
:local:
10+
.. currentmodule:: api.exceptions
11+
12+
.. automodule:: api.exceptions
13+
:members:

docs/server/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Server Reference
1515
rest
1616

1717
api.admin
18+
api.exceptions
1819
api.fields
1920
api.models
2021
api.routers

0 commit comments

Comments
 (0)