diff --git a/deployer/__init__.py b/deployer/__init__.py index e996709..d9a81ac 100644 --- a/deployer/__init__.py +++ b/deployer/__init__.py @@ -3,7 +3,7 @@ from celery.signals import setup_logging -__version__ = '0.3.10' +__version__ = '0.3.11' __author__ = 'sukrit' deployer.logger.init_logging() diff --git a/deployer/tasks/deployment.py b/deployer/tasks/deployment.py index 7780a3a..4fcd5e4 100644 --- a/deployer/tasks/deployment.py +++ b/deployer/tasks/deployment.py @@ -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) diff --git a/deployer/tasks/exceptions.py b/deployer/tasks/exceptions.py index 279727d..ce491d7 100644 --- a/deployer/tasks/exceptions.py +++ b/deployer/tasks/exceptions.py @@ -175,13 +175,15 @@ 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 { @@ -189,6 +191,7 @@ def to_dict(self): 'code': 'NODE_CHECK_FAILED', 'details': { 'url': self.url, + 'attempts': self.attempts, 'status': self.status, 'response': self.response } @@ -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 diff --git a/tests/unit/tasks/test_deployment.py b/tests/unit/tasks/test_deployment.py index b6eac21..4a9e965 100644 --- a/tests/unit/tasks/test_deployment.py +++ b/tests/unit/tasks/test_deployment.py @@ -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') @@ -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') diff --git a/tests/unit/tasks/test_exceptions.py b/tests/unit/tasks/test_exceptions.py index e6df3c5..f456ca2 100644 --- a/tests/unit/tasks/test_exceptions.py +++ b/tests/unit/tasks/test_exceptions.py @@ -48,17 +48,19 @@ 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 } }) @@ -66,8 +68,9 @@ def test_dict_repr_for_node_check_failed(): 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).')