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",
......
...@@ -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 el in self_partition.__dict__[key].__dict__: for k, v in vars(value).items():
report += (' ' + el +': ' + fout.write(' %s: %s%s' % (k, v, nl))
str(self_partition.__dict__[key].__dict__[el]) + ' ') fout.write(message)
report += message
open('%(watchdog_banged)s','w').write(report) slapos.slap.ComputerPartition.bang = bang
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