Skip to content

Commit

Permalink
Merge pull request #40 from totem/develop
Browse files Browse the repository at this point in the history
0.3.11 Release
  • Loading branch information
sukrit007 committed Dec 8, 2015
2 parents 6f8922c + 841349c commit 13311db
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deployer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from celery.signals import setup_logging


__version__ = '0.3.10'
__version__ = '0.3.11'
__author__ = 'sukrit'

deployer.logger.init_logging()
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def _check_node(self, node, path, attempts, timeout):
# Clear the current exception so that celery does not raise original
# exception
reason = exc.reason if hasattr(exc, 'reason') else repr(exc)
kwargs = {}
kwargs = {'attempts': attempts}
if hasattr(exc, 'read'):
kwargs.update(response={'raw': exc.read()}, status=exc.code)

Expand Down
12 changes: 8 additions & 4 deletions deployer/tasks/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,23 @@ class NodeCheckFailed(Exception):
Exception corresponding to failed deployment check for a given node.
"""

def __init__(self, url, reason, status=None, response=None):
def __init__(self, url, reason, status=None, response=None, attempts=None):
self.url = url
self.message = 'Deployment check failed for url: {0} due to: {1}'\
.format(url, reason)
self.message = 'Deployment check failed for url: {0} due to: {1} ' \
'after {2} attempt(s).'.format(url, reason, attempts)
self.status = status
self.response = response
super(NodeCheckFailed, self).__init__(url, reason, status, response)
self.attempts = attempts
super(NodeCheckFailed, self).__init__(url, reason, status, response,
attempts)

def to_dict(self):
return {
'message': self.message,
'code': 'NODE_CHECK_FAILED',
'details': {
'url': self.url,
'attempts': self.attempts,
'status': self.status,
'response': self.response
}
Expand All @@ -201,4 +204,5 @@ def __eq__(self, other):
return self.status == other.status and \
self.message == other.message and \
self.response == other.response and \
self.attempts == other.attempts and \
self.url == other.url
4 changes: 2 additions & 2 deletions tests/unit/tasks/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def retry(*args, **kwargs):
# Then: NodeCheckFailed exception is raised
eq_(cm.exception, NodeCheckFailed(
'http://localhost:8080/mock', 'MockError', status=500,
response={'raw': 'MockResponse'}))
response={'raw': 'MockResponse'}, attempts=5))


@patch('urllib2.urlopen')
Expand All @@ -771,7 +771,7 @@ def retry(*args, **kwargs):
# Then: NodeCheckFailed exception is raised
eq_(cm.exception, NodeCheckFailed(
'http://localhost:8080/mock', 'BadStatusLine("\'\'",)', status=None,
response=None))
response=None, attempts=5))


@patch('deployer.tasks.deployment._check_node')
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/tasks/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,29 @@ def test_dict_repr_for_node_check_failed():

# When: I call to_dict for NodeCheckFailed exception
result = NodeCheckFailed('http://localhost:8080', 'MockReason',
status=500, response={'raw': 'Mock'}).to_dict()
status=500, response={'raw': 'Mock'},
attempts=2).to_dict()

# Then: Expected result is returned
dict_compare(result, {
'message': 'Deployment check failed for url: http://localhost:8080 '
'due to: MockReason',
'due to: MockReason after 2 attempt(s).',
'code': 'NODE_CHECK_FAILED',
'details': {
'url': 'http://localhost:8080',
'status': 500,
'response': {'raw': 'Mock'}
'response': {'raw': 'Mock'},
'attempts': 2
}
})


def test_str_repr_for_node_check_failed():

# When: I call str representation for NodeCheckFailed exception
result = str(NodeCheckFailed('http://localhost:8080', 'MockReason'))
result = str(NodeCheckFailed('http://localhost:8080', 'MockReason',
attempts=2))

# Then: Expected result is returned
eq_(result, 'Deployment check failed for url: http://localhost:8080 due '
'to: MockReason')
'to: MockReason after 2 attempt(s).')

0 comments on commit 13311db

Please sign in to comment.