Fix supervisor watchdog tests

parent 80f164b3
...@@ -84,7 +84,7 @@ echo "touch launched ...@@ -84,7 +84,7 @@ echo "touch launched
if [ -f ./crashed ]; then if [ -f ./crashed ]; then
while :; do echo "Working\\nWorking\\n" ; sleep 0.1; done while :; do echo "Working\\nWorking\\n" ; sleep 0.1; done
else else
touch ./crashed; echo "Failing\\nFailing\\n"; sleep 1; return 111; touch ./crashed; echo "Failing\\nFailing\\n"; sleep 1; exit 111;
fi" >> etc/service/daemon && fi" >> etc/service/daemon &&
chmod 755 etc/service/daemon && chmod 755 etc/service/daemon &&
touch worked touch worked
...@@ -650,6 +650,19 @@ chmod 755 etc/run/wrapper ...@@ -650,6 +650,19 @@ chmod 755 etc/run/wrapper
class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase): class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
def setUp(self):
MasterMixin.setUp(self)
# Prepare watchdog
self.watchdog_banged = os.path.join(self._tempdir, 'watchdog_banged')
watchdog_path = os.path.join(self._tempdir, 'watchdog')
open(watchdog_path, 'w').write(
WATCHDOG_TEMPLATE % dict(python_path=sys.executable,
sys_path=sys.path,
watchdog_banged=self.watchdog_banged))
os.chmod(watchdog_path, 0755)
self.grid.watchdog_path = watchdog_path
slapos.grid.slapgrid.WATCHDOG_PATH = watchdog_path
def test_one_failing_daemon_in_service_will_bang_with_watchdog(self): def test_one_failing_daemon_in_service_will_bang_with_watchdog(self):
""" """
Check that a failing service watched by watchdog trigger bang Check that a failing service watched by watchdog trigger bang
...@@ -666,15 +679,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase): ...@@ -666,15 +679,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
partition = computer.instance_list[0] partition = computer.instance_list[0]
partition.requested_state = 'started' partition.requested_state = 'started'
partition.software.setBuildout(DAEMON_CONTENT) partition.software.setBuildout(DAEMON_CONTENT)
# Prepare watchdog
watchdog_path = os.path.join(self._tempdir, 'watchdog')
watchdog_banged = os.path.join(self._tempdir, 'watchdog_banged')
open(watchdog_path, 'w').write(
WATCHDOG_TEMPLATE % dict(python_path=sys.executable,
sys_path=sys.path,
watchdog_banged=watchdog_banged))
os.chmod(watchdog_path, 0755)
self.grid.watchdog_path = watchdog_path
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
...@@ -692,11 +697,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase): ...@@ -692,11 +697,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
tries = 25 tries = 25
while tries > 0: while tries > 0:
tries -= 1 tries -= 1
if os.path.exists(watchdog_banged): if os.path.exists(self.watchdog_banged):
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue(os.path.exists(watchdog_banged)) self.assertTrue(os.path.exists(self.watchdog_banged))
self.assertTrue('daemon' in open(watchdog_banged, 'r').read()) self.assertTrue('daemon' in open(self.watchdog_banged, 'r').read())
RUN_CONTENT = """#!/bin/sh RUN_CONTENT = """#!/bin/sh
mkdir -p etc/run && mkdir -p etc/run &&
...@@ -724,15 +729,7 @@ touch worked ...@@ -724,15 +729,7 @@ touch worked
partition = computer.instance_list[0] partition = computer.instance_list[0]
partition.requested_state = 'started' partition.requested_state = 'started'
partition.software.setBuildout(self.RUN_CONTENT) partition.software.setBuildout(self.RUN_CONTENT)
# Prepare watchdog
watchdog_path = os.path.join(self._tempdir,'watchdog')
watchdog_banged = os.path.join(self._tempdir,'watchdog_banged')
open(watchdog_path,'w').write(
WATCHDOG_TEMPLATE % dict(python_path=sys.executable,
sys_path=sys.path,
watchdog_banged=watchdog_banged))
os.chmod(watchdog_path,0755)
self.grid.watchdog_path = watchdog_path
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
...@@ -746,13 +743,13 @@ touch worked ...@@ -746,13 +743,13 @@ touch worked
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Failing' in open(daemon_log, 'r').read()) self.assertTrue('Failing' in open(daemon_log, 'r').read())
tries = 25 tries = 50
while tries > 0: while tries > 0:
tries -= 1 tries -= 1
if os.path.exists(watchdog_banged): if os.path.exists(self.watchdog_banged):
break break
time.sleep(0.1) time.sleep(0.1)
self.assertFalse(os.path.exists(watchdog_banged)) self.assertFalse(os.path.exists(self.watchdog_banged))
def test_watched_by_watchdog_bang(self): def test_watched_by_watchdog_bang(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment