Commit 54114ed5 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos: Watchdog use jio api for software instance bang

parent d7cf0323
......@@ -187,12 +187,32 @@ class Watchdog(object):
def handle_process_state_change_event(self, headers, payload_dict):
partition_id = payload_dict['groupname']
self.initialize_connection(partition_id)
partition = slapos.slap.ComputerPartition(
computer_id=self.computer_id,
connection_helper=self.slap._connection_helper,
partition_id=partition_id)
partition.bang("%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id))
if self.slap.jio_api_connector:
instance_list = self.slap.jio_api_connector.allDocs({
"portal_type": "Software Instance",
"compute_node_id": self.computer_id,
"compute_partition_id": partition_id,
}).get("result_list", [])
if len(instance_list) != 1:
raise ValueError("No instance found for %s %s %s" % (
self.computer_id,
partition_id,
instance_list,
))
self.slap.jio_api_connector.put({
"portal_type": "Software Instance",
"reported_state": "bang",
"status_message": "%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id),
"reference": instance_list[0]["reference"]
})
else:
partition = slapos.slap.ComputerPartition(
computer_id=self.computer_id,
connection_helper=self.slap._connection_helper,
partition_id=partition_id)
partition.bang("%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id))
self.create_partition_bang_timestamp_file(payload_dict['groupname'])
......
......@@ -441,16 +441,28 @@ class ComputerForTest(object):
})
if content["portal_type"] == "Software Instance":
if "compute_node_id" in content:
return json.dumps({
"result_list": [{
"software_release_uri": x.software.name if x.software else None,
"reference": x.name,
"title": x.name,
"portal_type": "Software Instance",
"compute_partition_id": x.name,
"state": x.requested_state
} for x in self.instance_list]
})
if "compute_partition_id" in content:
return json.dumps({
"result_list": [{
"software_release_uri": x.software.name if x.software else None,
"reference": x.name,
"title": x.name,
"portal_type": "Software Instance",
"compute_partition_id": x.name,
"state": x.requested_state
} for x in self.instance_list if x.name == content["compute_partition_id"]]
})
else:
return json.dumps({
"result_list": [{
"software_release_uri": x.software.name if x.software else None,
"reference": x.name,
"title": x.name,
"portal_type": "Software Instance",
"compute_partition_id": x.name,
"state": x.requested_state
} for x in self.instance_list]
})
elif "root_instance_title" in content:
return json.dumps({
"result_list": [{
......@@ -494,6 +506,8 @@ class ComputerForTest(object):
if content["reported_state"] == "error":
instance.error = True
instance.error_log = content["status_message"]
elif content["reported_state"] == "bang":
instance.error_log = content["status_message"]
else:
requested_instance.state = content["reported_state"]
return json.dumps({
......@@ -579,13 +593,11 @@ class ComputerForTest(object):
"message": "No document found with parameters: %s" % reference,
"name": "NotFound",
})
if req.method == 'POST' and 'computer_partition_id' in qs:
instance = self.instance_list[int(qs['computer_partition_id'][0])]
instance.sequence.append(url.path)
instance.header_list.append(req.headers)
if url.path == '/softwareInstanceBang':
return {'status_code': 200}
if req.method == 'GET':
if url.path == "/getHateoasUrl":
return ""
elif url.path == "/getJIOAPIUrl":
return "https://127.0.0.1/api/"
raise ValueError("Unexcepted call to API. URL:%s Content:%s" % (url.path, req.body))
......@@ -1235,7 +1247,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
def test_unwanted_events_will_not_bang(self):
"""
......@@ -1311,7 +1323,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
with open(os.path.join(
partition,
......@@ -1346,7 +1358,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
with open(os.path.join(
partition,
......@@ -1381,7 +1393,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
# Second bang
event = watchdog.process_state_events[0]
......@@ -1435,7 +1447,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
with open(os.path.join(
partition,
......@@ -1466,7 +1478,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
payload = 'processname:%s groupname:%s from_state:RUNNING' % (
'daemon' + WATCHDOG_MARK, instance.name)
watchdog.handle_event(headers, payload)
self.assertEqual(instance.sequence, ['/softwareInstanceBang'])
self.assertEqual(instance.sequence[0][1]["reported_state"], 'bang')
with open(os.path.join(
partition,
......
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