Move getWatchdogId to a constant in slapgrid.

parent 3727b3d4
......@@ -49,7 +49,9 @@ from slapos.grid.svcbackend import getSupervisorRPC
from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError,
PathDoesNotExistError)
from slapos.grid.networkcache import download_network_cached, upload_network_cached
from slapos.grid.watchdog import getWatchdogID
WATCHDOG_MARK = '-on-watch'
REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750
......@@ -526,7 +528,7 @@ class Partition(object):
# Same method to add to service and run
self.addServiceToGroup(partition_id, runner_list, self.run_path)
self.addServiceToGroup(partition_id, service_list, self.service_path,
extension=getWatchdogID())
extension=WATCHDOG_MARK)
updateFile(self.supervisord_partition_configuration_path,
self.partition_supervisor_configuration)
self.updateSupervisor()
......
......@@ -32,11 +32,10 @@ import os.path
import sys
import slapos.slap.slap
import slapos.grid.slapgrid
from slapos.grid.slapgrid import COMPUTER_PARTITION_TIMESTAMP_FILENAME, \
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
def getWatchdogID():
return "-on-watch"
from slapos.grid.SlapObject import WATCHDOG_MARK
def parseArgumentTuple():
......@@ -110,7 +109,7 @@ class Watchdog(object):
def handle_event(self, headers, payload):
if headers['eventname'] in self.process_state_events:
payload_dict = dict([x.split(':') for x in payload.split()])
if getWatchdogID() in payload_dict['processname'] and \
if WATCHDOG_MARK in payload_dict['processname'] and \
not self.has_bang_already_been_called(payload_dict['groupname']):
self.handle_process_state_change_event(headers, payload_dict)
......@@ -128,11 +127,11 @@ class Watchdog(object):
)
partition_timestamp_file_path = os.path.join(
partition_home_path,
slapos.grid.slapgrid.COMPUTER_PARTITION_TIMESTAMP_FILENAME
COMPUTER_PARTITION_TIMESTAMP_FILENAME
)
slapos_last_bang_timestamp_file_path = os.path.join(
partition_home_path,
slapos.grid.slapgrid.COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
)
if not os.path.exists(slapos_last_bang_timestamp_file_path):
......@@ -168,11 +167,11 @@ class Watchdog(object):
)
partition_timestamp_file_path = os.path.join(
partition_home_path,
slapos.grid.slapgrid.COMPUTER_PARTITION_TIMESTAMP_FILENAME
COMPUTER_PARTITION_TIMESTAMP_FILENAME
)
slapos_last_bang_timestamp_file_path = os.path.join(
partition_home_path,
slapos.grid.slapgrid.COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
COMPUTER_PARTITION_LATEST_BANG_TIMESTAMP_FILENAME
)
if os.path.exists(partition_timestamp_file_path):
timestamp = open(partition_timestamp_file_path, 'r').read()
......
......@@ -48,8 +48,9 @@ import slapos.grid.utils
from slapos.grid import slapgrid
from slapos.cli_legacy.slapgrid import parseArgumentTupleAndReturnSlapgridObject
from slapos.grid.utils import md5digest
from slapos.grid.watchdog import Watchdog, getWatchdogID
from slapos.grid.watchdog import Watchdog
from slapos.grid import SlapObject
from slapos.grid.SlapObject import WATCHDOG_MARK
dummylogger = logging.getLogger()
......@@ -866,7 +867,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['softwareInstanceBang'])
self.assertEqual(instance.header_list[0]['key'], instance.key)
......@@ -890,7 +891,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
computer.sequence = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, [])
......@@ -943,7 +944,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['softwareInstanceBang'])
self.assertEqual(instance.header_list[0]['key'], instance.key)
......@@ -977,7 +978,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['softwareInstanceBang'])
self.assertEqual(instance.header_list[0]['key'], instance.key)
......@@ -1066,7 +1067,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['softwareInstanceBang'])
self.assertEqual(instance.header_list[0]['key'], instance.key)
......@@ -1080,7 +1081,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, [])
......@@ -1096,7 +1097,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['softwareInstanceBang'])
self.assertEqual(instance.header_list[0]['key'], instance.key)
......@@ -1110,7 +1111,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
instance.header_list = []
headers = {'eventname': event}
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + getWatchdogID(), instance.name)
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, [])
......
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