Commit 89b3e112 authored by Marco Mariani's avatar Marco Mariani

tests: simpler watchdog template

parent 95440d94
...@@ -57,6 +57,7 @@ REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750 ...@@ -57,6 +57,7 @@ REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750
PROGRAM_PARTITION_TEMPLATE = pkg_resources.resource_stream(__name__, PROGRAM_PARTITION_TEMPLATE = pkg_resources.resource_stream(__name__,
'templates/program_partition_supervisord.conf.in').read() 'templates/program_partition_supervisord.conf.in').read()
class Software(object): class Software(object):
"""This class is responsible for installing a software release""" """This class is responsible for installing a software release"""
......
...@@ -29,12 +29,15 @@ ...@@ -29,12 +29,15 @@
import argparse import argparse
import os.path import os.path
import slapos.slap.slap
import sys import sys
import slapos.slap.slap
def getWatchdogID(): def getWatchdogID():
return "-on-watch" return "-on-watch"
def parseArgumentTuple(): def parseArgumentTuple():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--master-url", parser.add_argument("--master-url",
...@@ -93,9 +96,9 @@ class Watchdog(object): ...@@ -93,9 +96,9 @@ class Watchdog(object):
self.write_stdout('READY\n') self.write_stdout('READY\n')
line = self.stdin.readline() # read header line from stdin line = self.stdin.readline() # read header line from stdin
headers = dict([x.split(':') for x in line.split()]) headers = dict([x.split(':') for x in line.split()])
data = sys.stdin.read(int(headers['len'])) # read the event payload data = sys.stdin.read(int(headers['len'])) # read the event payload
self.handle_event(headers, data) self.handle_event(headers, data)
self.write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED self.write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED
def handle_event(self, headers, payload): def handle_event(self, headers, payload):
if headers['eventname'] in self.process_state_events: if headers['eventname'] in self.process_state_events:
......
...@@ -52,29 +52,23 @@ from slapos.grid import SlapObject ...@@ -52,29 +52,23 @@ from slapos.grid import SlapObject
dummylogger = logging.getLogger() dummylogger = logging.getLogger()
WATCHDOG_TEMPLATE = """#!%(python_path)s -S WATCHDOG_TEMPLATE = """#!{python_path} -S
import sys import sys
sys.path=%(sys_path)s sys.path={sys_path}
import slapos.slap.slap import slapos.slap
import slapos.grid.watchdog import slapos.grid.watchdog
def setBang(): def bang(self_partition, message):
def getBang(): nl = chr(10)
def bang(self_partition,message): with open('{watchdog_banged}', 'w') as fout:
report = "" for key, value in vars(self_partition).items():
for key in self_partition.__dict__: fout.write('%s: %s%s' % (key, value, nl))
report += (key + ': ' + str(self_partition.__dict__[key]) + ' ') if key == '_connection_helper':
if key == '_connection_helper': for k, v in vars(value).items():
for el in self_partition.__dict__[key].__dict__: fout.write(' %s: %s%s' % (k, v, nl))
report += (' ' + el +': ' + fout.write(message)
str(self_partition.__dict__[key].__dict__[el]) + ' ')
report += message slapos.slap.ComputerPartition.bang = bang
open('%(watchdog_banged)s','w').write(report)
return bang
slapos.slap.ComputerPartition.bang = getBang()
setBang()
slapos.grid.watchdog.main() slapos.grid.watchdog.main()
""" """
...@@ -769,11 +763,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase): ...@@ -769,11 +763,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
# Prepare watchdog # Prepare watchdog
self.watchdog_banged = os.path.join(self._tempdir, 'watchdog_banged') self.watchdog_banged = os.path.join(self._tempdir, 'watchdog_banged')
watchdog_path = os.path.join(self._tempdir, 'watchdog') watchdog_path = os.path.join(self._tempdir, 'watchdog')
open(watchdog_path, 'w').write(WATCHDOG_TEMPLATE % { open(watchdog_path, 'w').write(WATCHDOG_TEMPLATE.format(
'python_path': sys.executable, python_path=sys.executable,
'sys_path': sys.path, sys_path=sys.path,
'watchdog_banged': self.watchdog_banged watchdog_banged=self.watchdog_banged
}) ))
os.chmod(watchdog_path, 0o755) os.chmod(watchdog_path, 0o755)
self.grid.watchdog_path = watchdog_path self.grid.watchdog_path = watchdog_path
slapos.grid.slapgrid.WATCHDOG_PATH = watchdog_path slapos.grid.slapgrid.WATCHDOG_PATH = watchdog_path
......
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