def set_up_negtive(self): f = open(self._fake_path, 'w') conf = SednaConfigParser() conf_mock = conf.get_config_parser("./tests/fake_sedna.conf") conf_mock.add_section("groups") conf_mock.set("groups", "test_group_a", "192.168.0.1") conf_mock.set("groups", "test_group_b", "192.168.0.2") conf_mock.add_section("sampler") conf_mock.set("sampler", "port", " 8000") conf_mock.add_section("services") conf_mock.set("services", "test_group_a", "service_a,service_b") conf_mock.set("services", "test_group_b", "service_c,service_d") conf_mock.add_section("method") conf_mock.set("method", "service_a", "systemd") conf_mock.set("method", "service_b", "pacemaker") conf_mock.set("method", "service_c", "init.d") # conf_mock.set("method", "service_d", "unknown") conf_mock.write(f) f.close() fake_sedna_config_relative_path = "./tests/fake_sedna.conf" return fake_sedna_config_relative_path
def setUp(self): self.fake_config_file = FakeSednaConfigFile() fake_relative_path = self.fake_config_file.set_up_negtive() config = SednaConfigParser() self.fake_sedna_config = config.get_config_parser(fake_relative_path) fake_sedna_config_path = SednaConfigPath() self.absolute_fake_sedna_config_path =\ fake_sedna_config_path.get_config_path("./tests/fake_sedna.conf")
def main(): config_parser = SednaConfigParser() sedna_conf = config_parser.get_config_parser() port = sedna_conf.get("sampler", "port") node_sampler = NodeSampler() node_sampler.register_checker("systemd", SystemdChecker) node_sampler.register_checker("pacemaker", PacemakerChecker) node_sampler.register_checker("init.d", InitdChecker) server = NodeSamplerServer(int(port), node_sampler) server.start()
def test_fixed_sedna_conf(self): """ The test case to check class SednaConfigParser can make ConfigPaser object for sedna.conf . :return: """ sedna_config_parser = SednaConfigParser() sedna_conf = sedna_config_parser.get_config_parser() test = sedna_conf.get("sampler", "port") self.assertEquals( test, "8000", "SednaConfigParser cannot make ConfigParser obj for sedna.config.")
def test_defined_sedna_conf(self): """ The test case to check class SednaConfigParser can make ConfigPaser object for user-defined config file. :return: """ sedna_config_parser = SednaConfigParser() sedna_conf =\ sedna_config_parser.get_config_parser("./tests/fake_sedna_config") test = sedna_conf.get("sampler", "port") self.assertEquals( test, "8000", "SednaConfigParser cannot make ConfigParser obj \ for user-defined config file.")
def set_up(self): """ The wrapper of setUp method to build a fake config file of Sedna. :return: the path of the new fake config file """ f = open(self._fake_path, 'w') conf = SednaConfigParser() conf_mock = conf.get_config_parser("./tests/fake_sedna.conf") conf_mock.add_section("groups") conf_mock.set("groups", "test_group_a", "192.168.0.1, 192.168.0.2, 192.168.0.3") conf_mock.set("groups", "test_group_b", "192.168.0.4, 192.168.0.5") conf_mock.add_section("sampler") conf_mock.set("sampler", "Port", "8000") conf_mock.add_section("services") conf_mock.set("services", "test_group_a", "service_a, service_b") conf_mock.set("services", "test_group_b", "service_c, service_d") conf_mock.add_section("method") conf_mock.set("method", "service_a", "systemd") conf_mock.set("method", "service_b", "pacemaker") conf_mock.set("method", "service_c", "init.d") conf_mock.set("method", "service_d", "$$unknown_method$$") conf_mock.write(f) f.close() fake_sedna_config_relative_path = "./tests/fake_sedna.conf" return fake_sedna_config_relative_path