Permalink
Browse files

Derping

  • Loading branch information...
1 parent acee539 commit a9f0979fcdb8871cc3189713a62b49c2f13b126d @guilhermef guilhermef committed Oct 29, 2012
Showing with 83 additions and 0 deletions.
  1. +3 −0 Makefile
  2. 0 fabplugins/__init__.py
  3. +22 −0 fabplugins/healthcheck.py
  4. +4 −0 requirements.txt
  5. +26 −0 setup.py
  6. 0 tests/__init__.py
  7. +28 −0 tests/healthcheck_unit.py
View
@@ -0,0 +1,3 @@
+
+test:
+ @nosetests tests/*_unit.py
View
No changes.
View
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+from __future__ import with_statement
+import sys
+import time
+
+from fabric.api import run, settings
+
+
+def do_healthcheck(host, uri='healthcheck', body='WORKING'):
+ sleeping_time = 1
+
+ with settings(warn_only=True):
+ print 'Waiting for server (%s)' % host
+ while not run('curl %s/%s' % (host, uri)) == body:
+ print '. (sleeping %d)' % sleeping_time
+ time.sleep(sleeping_time)
+ sleeping_time = sleeping_time * 2
+ if sleeping_time >= 64:
+ print 'Timeout trying to healthcheck'
+ sys.exit(-1)
+ return True
View
@@ -0,0 +1,4 @@
+pyvows
+mock
+fabric
+nose
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+from setuptools import setup
+
+version = '1.0.0'
+
+setup(
+ name='fabplugins',
+ version=version,
+ description="Fabric plugins",
+ long_description="Fabric plugins",
+ keywords='fabplugins',
+ author='Time Home',
+ author_email='timehome@corp.globo.com',
+ url='',
+ license='Proprietary',
+ classifiers=[],
+ packages=['fabplugins'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ "fabric"
+ ]
+)
View
No changes.
View
@@ -0,0 +1,28 @@
+from fabplugins import healthcheck
+
+from mock import patch
+import unittest
+
+
+class TestHealthcheck(unittest.TestCase):
+
+ def test_without_parameters(self):
+ with patch.object(healthcheck, 'run') as mocked_run:
+ mocked_run.return_value = 'WORKING'
+ healthcheck.do_healthcheck('http://test.com')
+
+ mocked_run.assert_called_once_with('curl http://test.com/healthcheck')
+
+ def test_with_custom_uri(self):
+ with patch.object(healthcheck, 'run') as mocked_run:
+ mocked_run.return_value = 'WORKING'
+ healthcheck.do_healthcheck('http://test.com', uri='derpcheck')
+
+ mocked_run.assert_called_once_with('curl http://test.com/derpcheck')
+
+ def test_with_custom_body(self):
+ with patch.object(healthcheck, 'run') as mocked_run:
+ mocked_run.return_value = 'DERPING'
+ healthcheck.do_healthcheck('http://test.com', body='DERPING')
+
+ mocked_run.assert_called_once_with('curl http://test.com/healthcheck')

0 comments on commit a9f0979

Please sign in to comment.