Skip to content

Commit

Permalink
Merge pull request #38 from totem/develop
Browse files Browse the repository at this point in the history
0.3.10 Release
  • Loading branch information
sukrit007 committed Dec 8, 2015
2 parents 352cb80 + 72bee8c commit 6f8922c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 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.9'
__version__ = '0.3.10'
__author__ = 'sukrit'

deployer.logger.init_logging()
Expand Down
5 changes: 3 additions & 2 deletions deployer/tasks/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import copy
import datetime
from httplib import HTTPException
import json
import socket
import logging
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/tasks/test_deployment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import httplib
import urllib2

from freezegun import freeze_time
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6f8922c

Please sign in to comment.