def test_MonitorInit(self): m = Monitor( config_options={ "depend": "a, b", "urgent": 0, "tolerance": 2, "remote_alert": 1, "recover_command": "true", "recovered_command": "true", }) self.assertEqual(m.name, "unnamed", "Monitor did not set name") self.assertEqual(m.urgent, 0, "Monitor did not set urgent") self.assertEqual(m._tolerance, 2, "Monitor did not set tolerance") self.assertTrue(m.remote_alerting, "Monitor did not set remote_alerting") self.assertEqual(m._recover_command, "true", "Monitor did not set recover_command") self.assertEqual(m._recovered_command, "true", "Monitor did not set recovered_command") with self.assertRaises(ValueError): m.minimum_gap = -1 with self.assertRaises(TypeError): m.minimum_gap = "zero" with self.assertRaises(TypeError): m.notify = "true" m.notify = False self.assertEqual(m.notify, False, "monitor did not unset notify") m.notify = True self.assertEqual(m.notify, True, "monitor did not set notify") with self.assertRaises(TypeError): m.urgent = "true" m.urgent = True self.assertEqual(m.urgent, True, "monitor did not set urgent") m.urgent = 0 self.assertEqual(m.urgent, False, "monitor did not unset urgent with an int") m.urgent = 1 self.assertEqual(m.urgent, True, "monitor did not set urgent with an int") with self.assertRaises(TypeError): m.dependencies = "no at a list" m.dependencies = ["a", "b"] self.assertEqual( m.dependencies, ["a", "b"], "monitor did not set or return dependencies correctly", ) self.assertEqual( m.remaining_dependencies, ["a", "b"], "monitor did not set remaining dependencies", ) m.dependency_succeeded("a") self.assertEqual( m.remaining_dependencies, ["b"], "monitor did not remove dependencies from list", ) m.dependency_succeeded("a") # should be safe to remove again
def test_MonitorDependencies(self): m = Monitor() m.dependencies = ["a", "b", "c"] m.dependency_succeeded("b") self.assertEqual( m.remaining_dependencies, ["a", "c"], "monitor did not remove succeded dependency", ) m.reset_dependencies() self.assertEqual( m.remaining_dependencies, ["a", "b", "c"], "monitor did not reset dependencies", )