From f7855271561976543f61212b89bf05bc798199e8 Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 19 Apr 2021 14:33:50 +0200 Subject: [PATCH] Add opt args to health function --- apps/util/liveness/liveness/linux.py | 4 ++-- apps/util/liveness/setup.py | 2 +- apps/util/liveness/tests/imports/import_false.py | 2 +- apps/util/liveness/tests/imports/import_true.py | 2 +- apps/util/liveness/tests/test_imports.py | 9 +++++++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/util/liveness/liveness/linux.py b/apps/util/liveness/liveness/linux.py index 1ce1fb02..e9f1c4f6 100644 --- a/apps/util/liveness/liveness/linux.py +++ b/apps/util/liveness/liveness/linux.py @@ -14,7 +14,7 @@ if default_namespace == None: default_namespace = socket.gethostname() -def load(check_strs, namespace=default_namespace, rundir='/run'): +def load(check_strs, namespace=default_namespace, rundir='/run', *args, **kwargs): if namespace == None: import socket @@ -29,7 +29,7 @@ def load(check_strs, namespace=default_namespace, rundir='/run'): checks.append(module) for check in checks: - r = check.health() + r = check.health(args, kwargs) if r == False: raise RuntimeError('liveness check {} failed'.format(str(check))) logg.info('liveness check passed: {}'.format(str(check))) diff --git a/apps/util/liveness/setup.py b/apps/util/liveness/setup.py index 9862eaf2..0ec91aff 100644 --- a/apps/util/liveness/setup.py +++ b/apps/util/liveness/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup( name='liveness', - version='0.0.1a4', + version='0.0.1a5', packages=['liveness'], include_package_data=True, ) diff --git a/apps/util/liveness/tests/imports/import_false.py b/apps/util/liveness/tests/imports/import_false.py index cc5a26fb..311f2781 100644 --- a/apps/util/liveness/tests/imports/import_false.py +++ b/apps/util/liveness/tests/imports/import_false.py @@ -1,2 +1,2 @@ -def health(): +def health(*args, **kwargs): return False diff --git a/apps/util/liveness/tests/imports/import_true.py b/apps/util/liveness/tests/imports/import_true.py index c33f7db9..69c2e286 100644 --- a/apps/util/liveness/tests/imports/import_true.py +++ b/apps/util/liveness/tests/imports/import_true.py @@ -1,2 +1,2 @@ -def health(): +def health(*args, **kwargs): return True diff --git a/apps/util/liveness/tests/test_imports.py b/apps/util/liveness/tests/test_imports.py index 1505f28f..02e6be79 100644 --- a/apps/util/liveness/tests/test_imports.py +++ b/apps/util/liveness/tests/test_imports.py @@ -114,5 +114,14 @@ class TestImports(unittest.TestCase): os.stat(error_path) + def test_args(self): + checks = ['tests.imports.import_args'] + liveness.linux.load(checks, namespace=self.unit, rundir=self.run_dir, args=['foo'], kwargs={'bar': 42}) + f = open(self.pid_path, 'r') + r = f.read() + f.close() + self.assertEqual(str(os.getpid()), r) + + if __name__ == '__main__': unittest.main()