This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from a5huynh/feature/vulcand-trust-headers
Vulcand Tests & Flag to trust headers
- Loading branch information
Showing
7 changed files
with
148 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.coverage | ||
htmlcov | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
language: python | ||
python: | ||
- "3.4" | ||
- "3.5" | ||
|
||
# install dependencies | ||
install: "pip install -r requirements.txt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Author: ahuynh | ||
# @Date: 2016-01-28 10:04:58 | ||
# @Last Modified by: ahuynh | ||
# @Last Modified time: 2016-02-11 17:25:54 | ||
import etcd | ||
|
||
|
||
class MockEtcd( object ): | ||
|
||
def __init__( self, raise_exception=False ): | ||
self._reset() | ||
self.raise_exception = raise_exception | ||
|
||
def _check_raise( self ): | ||
if self.raise_exception: | ||
raise etcd.EtcdException( 'Test Exception' ) | ||
|
||
def _reset( self ): | ||
self.deleted = set([]) | ||
self.written = {} | ||
|
||
def delete( self, key ): | ||
self._check_raise() | ||
self.deleted.add( key ) | ||
|
||
def write( self, key, value, ttl ): | ||
self._check_raise() | ||
self.written[ key ] = value |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Author: ahuynh | ||
# @Date: 2016-02-11 14:28:02 | ||
# @Last Modified by: ahuynh | ||
# @Last Modified time: 2016-02-26 16:15:00 | ||
import unittest | ||
|
||
from sidekick import announce_services, find_matching_container, parse_args | ||
from tests import MockEtcd | ||
from unittest.mock import patch | ||
|
||
|
||
class TestVulcandBackend( unittest.TestCase ): | ||
|
||
def setUp( self ): | ||
|
||
self.args = parse_args([ | ||
'--name', 'test', | ||
'--ip', 'localhost', | ||
'--check-ip', '0.0.0.0', | ||
'--vulcand', 'True' | ||
]) | ||
|
||
self.etcd_client = MockEtcd() | ||
self.container = { | ||
'Image': 'image:latest', | ||
'Ports': [{ | ||
'PrivatePort': 9200, | ||
'IP': '0.0.0.0', | ||
'Type': 'tcp', | ||
'PublicPort': 9200 | ||
}, { | ||
'PrivatePort': 9300, | ||
'IP': '0.0.0.0', | ||
'Type': 'tcp', | ||
'PublicPort': 9300 | ||
}], | ||
'Created': 1427906382, | ||
'Names': ['/test'], | ||
'Status': 'Up 2 days' | ||
} | ||
|
||
def test_vulcand_announce( self ): | ||
""" Test `announce_services` functionality """ | ||
services = find_matching_container( [ self.container ], self.args ) | ||
|
||
# Successful health check | ||
with patch( 'sidekick.check_health', return_value=True ): | ||
announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args ) | ||
self.assertEqual( len( self.etcd_client.written.keys() ), 4 ) | ||
|
||
# Unsuccessful health check | ||
self.etcd_client._reset() | ||
with patch( 'sidekick.check_health', return_value=False ): | ||
announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args ) | ||
self.assertEqual( len( self.etcd_client.deleted ), 4 ) | ||
|
||
# Correct etcd exception handling | ||
self.etcd_client = MockEtcd( raise_exception=True ) | ||
with patch( 'logging.error' ) as mock_method: | ||
announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args ) | ||
self.assertEquals( str(mock_method.call_args[0][0]), 'Test Exception' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters