diff --git a/deployer/__init__.py b/deployer/__init__.py index 10abd1a..e996709 100644 --- a/deployer/__init__.py +++ b/deployer/__init__.py @@ -3,7 +3,7 @@ from celery.signals import setup_logging -__version__ = '0.3.9' +__version__ = '0.3.10' __author__ = 'sukrit' deployer.logger.init_logging() diff --git a/deployer/tasks/deployment.py b/deployer/tasks/deployment.py index 87a7d83..7780a3a 100644 --- a/deployer/tasks/deployment.py +++ b/deployer/tasks/deployment.py @@ -3,6 +3,7 @@ """ import copy import datetime +from httplib import HTTPException import json import socket import logging @@ -919,10 +920,10 @@ def _check_node(self, node, path, attempts, timeout): timeout_ms = to_milliseconds(timeout) try: urllib2.urlopen(check_url, None, timeout_ms/1000) - except IOError as exc: + except (IOError, HTTPException) as exc: # Clear the current exception so that celery does not raise original # exception - reason = exc.reason if hasattr(exc, 'reason') else str(exc) + reason = exc.reason if hasattr(exc, 'reason') else repr(exc) kwargs = {} if hasattr(exc, 'read'): kwargs.update(response={'raw': exc.read()}, status=exc.code) diff --git a/tests/unit/tasks/test_deployment.py b/tests/unit/tasks/test_deployment.py index 0a3da3c..b6eac21 100644 --- a/tests/unit/tasks/test_deployment.py +++ b/tests/unit/tasks/test_deployment.py @@ -1,4 +1,5 @@ import datetime +import httplib import urllib2 from freezegun import freeze_time @@ -746,6 +747,33 @@ def retry(*args, **kwargs): response={'raw': 'MockResponse'})) +@patch('urllib2.urlopen') +def test_check_node_for_unhealthy_node_returning_bad_status_line(m_urlopen): + """ + Should fail node check for unhealthy node. + """ + + # Given: Unhealthy node + m_urlopen.side_effect = httplib.BadStatusLine('') + + # And: Mock Implementation for retry + _check_node.retry = MagicMock() + + def retry(*args, **kwargs): + raise kwargs.get('exc') + + _check_node.retry.side_effect = retry + + # When: I call check node with a given path + with nose.tools.assert_raises(NodeCheckFailed) as cm: + _check_node('localhost:8080', 'mock', 5, '5s') + + # Then: NodeCheckFailed exception is raised + eq_(cm.exception, NodeCheckFailed( + 'http://localhost:8080/mock', 'BadStatusLine("\'\'",)', status=None, + response=None)) + + @patch('deployer.tasks.deployment._check_node') @patch('deployer.tasks.deployment.chord') def test_check_deployment(m_chord, m_check_node):