Beispiel #1
0
    def fixture_corosync_conf(self, node1_name=True, node2_name=True):
        # nodelist is enough, nothing else matters for the tests
        config = dedent("""\
            nodelist {
                node {
                    ring0_addr: node-1-addr
                    nodeid: 1
                    name: node-1
                }

                node {
                    ring0_addr: node-2-addr
                    nodeid: 2
                    name: node-2
                }
            }
            """)
        if not node1_name:
            config = re.sub(r"\s+name: node-1\n", "\n", config)
        if not node2_name:
            config = re.sub(r"\s+name: node-2\n", "\n", config)
        self.corosync_conf_text = config
        self.corosync_conf_facade = CorosyncConfigFacade(
            CorosyncParser.parse(config.encode("utf-8")))
        CorosyncConfigFacade.need_stopped_cluster = False
        CorosyncConfigFacade.need_qdevice_reload = False
Beispiel #2
0
 def test_success(self):
     new_corosync_conf_data = "totem {\n    version: 3\n}\n"
     self.config.env.push_corosync_conf(
         corosync_conf_text=new_corosync_conf_data)
     env = self.env_assistant.get_env()
     env.push_corosync_conf(
         CorosyncConfigFacade(
             CorosyncParser.parse(new_corosync_conf_data.encode("utf-8"))))
Beispiel #3
0
    def load(
        self,
        node_name_list=None,
        name="corosync_conf.load",
        filename="corosync.conf",
        auto_tie_breaker=None,
        instead=None,
    ):
        # pylint: disable=too-many-locals
        with open(rc(filename)) as a_file:
            content = a_file.read()
        corosync_conf = None
        if node_name_list:
            corosync_conf = ConfigFacade(
                Parser.parse(content.encode("utf-8"))
            ).config
            for nodelist in corosync_conf.get_sections(name="nodelist"):
                corosync_conf.del_section(nodelist)

            nodelist_section = Section("nodelist")
            corosync_conf.add_section(nodelist_section)
            for i, node_name in enumerate(node_name_list):
                node_section = Section("node")
                node_section.add_attribute("ring0_addr", node_name)
                node_section.add_attribute("nodeid", i)
                node_section.add_attribute("name", node_name)
                nodelist_section.add_section(node_section)

        if auto_tie_breaker is not None:
            corosync_conf = (
                corosync_conf
                if corosync_conf
                else ConfigFacade(Parser.parse(content.encode("utf-8"))).config
            )
            for quorum in corosync_conf.get_sections(name="quorum"):
                quorum.set_attribute(
                    "auto_tie_breaker", "1" if auto_tie_breaker else "0"
                )

        if corosync_conf:
            content = corosync_conf.export()

        self.load_content(content, name=name, instead=instead)
def _get_facade(config_text):
    return lib.ConfigFacade(Parser.parse(config_text.encode("utf-8")))
Beispiel #5
0
 def assert_value(self, value, config):
     facade = lib.ConfigFacade(Parser.parse(config.encode("utf-8")))
     self.assertEqual(value, self.getter(facade))
     self.assertFalse(facade.need_stopped_cluster)
     self.assertFalse(facade.need_qdevice_reload)