Add opt args to health function

This commit is contained in:
nolash 2021-04-19 14:33:50 +02:00
parent a0153bfa19
commit f785527156
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 14 additions and 5 deletions

View File

@ -14,7 +14,7 @@ if default_namespace == None:
default_namespace = socket.gethostname() 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: if namespace == None:
import socket import socket
@ -29,7 +29,7 @@ def load(check_strs, namespace=default_namespace, rundir='/run'):
checks.append(module) checks.append(module)
for check in checks: for check in checks:
r = check.health() r = check.health(args, kwargs)
if r == False: if r == False:
raise RuntimeError('liveness check {} failed'.format(str(check))) raise RuntimeError('liveness check {} failed'.format(str(check)))
logg.info('liveness check passed: {}'.format(str(check))) logg.info('liveness check passed: {}'.format(str(check)))

View File

@ -1,7 +1,7 @@
from setuptools import setup from setuptools import setup
setup( setup(
name='liveness', name='liveness',
version='0.0.1a4', version='0.0.1a5',
packages=['liveness'], packages=['liveness'],
include_package_data=True, include_package_data=True,
) )

View File

@ -1,2 +1,2 @@
def health(): def health(*args, **kwargs):
return False return False

View File

@ -1,2 +1,2 @@
def health(): def health(*args, **kwargs):
return True return True

View File

@ -114,5 +114,14 @@ class TestImports(unittest.TestCase):
os.stat(error_path) 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__': if __name__ == '__main__':
unittest.main() unittest.main()