def setUp(self): self.expected_service = Service(name=TEST_SERVICE_NAME, ip="127.0.0.1", check_methods=TEST_METHOD) self.expected_services = [self.expected_service, self.expected_service] self.expected_node = Node(group=TEST_GROUP, ip="127.0.0.1", services=self.expected_services) self.expected_nodes = [self.expected_node] node_sampler = NodeSampler() node_sampler_server = NodeSamplerServer(8000, node_sampler) def start_server(): node_sampler_server.start() server_thread = Thread(target=start_server) server_thread.setDaemon(True) server_thread.start() node_sampler.register_checker(TEST_METHOD, MockedMethodChecker)
def setUp(self): self.node_sampler = NodeSampler()
class NodeSamplerTest(TestCase): """ The test cases to test class NodeSampler """ def setUp(self): self.node_sampler = NodeSampler() def test_systemd_checker(self): self.node_sampler.register_checker("systemd", SystemdChecker) self.service = Service(name=TEST_SERVICE_NAME, check_methods="systemd", ip=TEST_IP) self.fake_services = [self.service] results = self.node_sampler.sample(services=self.fake_services) self.assertEquals(len(results), len(self.fake_services)) def test_pacemaker_checker(self): self.node_sampler.register_checker("pacemaker", PacemakerChecker) self.service = Service(name=TEST_SERVICE_NAME, check_methods="pacemaker", ip=TEST_IP) self.fake_services = [self.service] with self.assertRaises(NotImplementedError): self.node_sampler.sample(services=self.fake_services) def test_initd_checker(self): self.node_sampler.register_checker("init.d", InitdChecker) self.service = Service(name=TEST_SERVICE_NAME, check_methods="init.d", ip=TEST_IP) self.fake_services = [self.service] with self.assertRaises(NotImplementedError): self.node_sampler.sample(services=self.fake_services) def test_unknown_checker(self): self.service = Service(name=TEST_SERVICE_NAME, check_methods="unknown_checker", ip=TEST_IP) self.fake_services = [self.service] with self.assertRaises(Exception): self.node_sampler.sample(services=self.fake_services)