Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2 signal issue on py34 #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ def get_version(version_tuple):

try:
from pypandoc import convert
read_md = lambda f: convert(f, 'rst')

def read_md(f):
return convert(f, 'rst')

except ImportError:
print(
"warning: pypandoc module not found, could not convert Markdown to RST"
)
read_md = lambda f: open(f, 'r').read()

def read_md(f):
return open(f, 'r').read() # noqa

README = os.path.join(os.path.dirname(__file__), 'README.md')
PACKAGES = find_packages('src')
Expand Down
7 changes: 6 additions & 1 deletion src/ianitor/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,19 @@ def signal_handler(signal_number, *_):
signal.signal(signum, signal_handler)
except RuntimeError:
# signals that cannot be catched will raise RuntimeException
# (SIGKILL) ...
pass
except OSError:
# ... or OSError (SIGSTOP)
pass

while sleep(args.heartbeat) or service.is_up():
service.keep_alive()

logger.info("process quit with errorcode %s %s" % (
service.process.poll(),
"(signal)" if service.process.poll() < 0 else ""
"(signal)" if service.process.poll() and service.process.poll() < 0
else ""
))

service.deregister()
6 changes: 3 additions & 3 deletions tests/test_args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def test_coordinates():
args_parser.coordinates(":123")


@patch('sys.argv', ["ianitor", "tailf", '--', 'tailf', 'something'])
@patch('sys.argv', ["ianitor", "tailf", '--', 'tail', '-f', 'something'])
def test_parse_args():
args, invocation = args_parser.parse_args()
assert invocation == ['tailf', 'something']
assert invocation == ['tail', '-f', 'something']

TEST_TTL = 100


@patch('sys.argv', ["ianitor", "tailf", '--ttl', str(TEST_TTL), '--', 'tailf', 'something']) # noqa
@patch('sys.argv', ["ianitor", "tailf", '--ttl', str(TEST_TTL), '--', 'tail', '-f', 'something']) # noqa
def test_default_heartbeat():
args, invocation = args_parser.parse_args()
assert args.heartbeat == TEST_TTL / 10.
33 changes: 33 additions & 0 deletions tests/test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014 by Clearcode <http://clearcode.cc>
# and associates (see AUTHORS.md).

# This file is part of ianitor.

# ianitor is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# ianitor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with ianitor. If not, see <http://www.gnu.org/licenses/>.
from mock import patch


from ianitor.service import Service
import ianitor.script


@patch('sys.argv', ["ianitor", "tail", "--", "tail", '-f', '/dev/null'])
def test_script_main():
"""Run ianitor.script.main and mock service is_up so it will quit
immediately"""

with patch.object(Service, "is_up", return_value=False) as is_up:
ianitor.script.main()
is_up.assert_any_call()
2 changes: 1 addition & 1 deletion tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def get_tailf_service(session):
return service.Service(
["tailf", "/dev/null"],
["tail", "-f", "/dev/null"],
session=session,
service_name="tailf",
# small ttl for faster testing
Expand Down