Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

fix watchdog None exception error #1625

Merged
merged 1 commit into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/watchdog/src/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def parse_pod_item(pai_pod_gauge, pai_container_gauge, pod):
else:
phase = "unknown"

host_ip = None
host_ip = "unscheduled" # can not specify None here, None will cause None exception
if status.get("hostIP") is not None:
host_ip = status["hostIP"]

Expand Down
22 changes: 21 additions & 1 deletion src/watchdog/test/test_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import logging
import logging.config

import prometheus_client

sys.path.append(os.path.abspath("../src/"))

import watchdog
Expand Down Expand Up @@ -80,13 +82,31 @@ def test_process_nodes_status(self):
def test_process_pods_with_no_condition(self):
obj = json.loads(self.get_data_test_input("data/no_condtion_pod.json"))

pod_gauge = watchdog.gen_pai_node_gauge()
pod_gauge = watchdog.gen_pai_pod_gauge()
container_gauge = watchdog.gen_pai_container_gauge()

watchdog.process_pods_status(pod_gauge, container_gauge, obj)

self.assertTrue(len(pod_gauge.samples) > 0)
self.assertEquals(0, len(container_gauge.samples))

def test_process_pod_with_no_host_ip(self):
obj = json.loads(self.get_data_test_input("data/no_condtion_pod.json"))

class CustomCollector(object):
def collect(self):
pod_gauge = watchdog.gen_pai_pod_gauge()
container_gauge = watchdog.gen_pai_container_gauge()

watchdog.process_pods_status(pod_gauge, container_gauge, obj)

yield pod_gauge
yield container_gauge

registry = CustomCollector()

# expect no exception
prometheus_client.write_to_textfile("/tmp/test_watchdog.prom", registry)

if __name__ == '__main__':
unittest.main()