Beispiel #1
0
    def test_node_failure_skip_offline(self):
        (self.config.fs.open(
            self.config_path, mock.mock_open(read_data="")(),
            name="open.conf").corosync_conf.load().http.booth.send_config(
                self.name,
                "",
                communication_list=[
                    dict(
                        label=self.node_list[0],
                        response_code=400,
                        output=self.reason,
                    ),
                    dict(label=self.node_list[1], )
                ]))

        commands.config_sync(self.env_assist.get_env(),
                             skip_offline_nodes=True)
        self.env_assist.assert_reports([
            fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED),
            fixture.info(report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                         node=self.node_list[1],
                         name_list=[self.name]),
            fixture.warn(
                report_codes.NODE_COMMUNICATION_COMMAND_UNSUCCESSFUL,
                node=self.node_list[0],
                reason=self.reason,
                command="remote/booth_set_config",
            ),
        ])
Beispiel #2
0
    def test_authfile_not_accessible(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)

        (self.config.fs.open(self.config_path,
                             mock.mock_open(read_data=config_content)(),
                             name="open.conf").fs.open(
                                 auth_file_path,
                                 mode="rb",
                                 name="open.authfile",
                                 side_effect=EnvironmentError(
                                     0, self.reason, auth_file_path),
                             ).corosync_conf.load().http.booth.send_config(
                                 self.name,
                                 config_content,
                                 node_labels=self.node_list,
                             ))

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.FILE_IO_ERROR,
                reason="{}: '{}'".format(self.reason, auth_file_path),
                file_role=file_roles.BOOTH_KEY,
                file_path=auth_file_path,
                operation="read",
            ),
            fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)
        ] + [
            fixture.info(report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                         node=node,
                         name_list=[self.name]) for node in self.node_list
        ])
Beispiel #3
0
    def test_node_offline_skip_offline(self):
        (self.config.fs.open(
            self.config_path, mock.mock_open(read_data="")(),
            name="open.conf").corosync_conf.load().http.booth.send_config(
                self.name,
                "",
                communication_list=[
                    dict(
                        label=self.node_list[0],
                        errno=1,
                        error_msg=self.reason,
                        was_connected=False,
                    ),
                    dict(label=self.node_list[1], )
                ],
            ))

        commands.config_sync(self.env_assist.get_env(),
                             skip_offline_nodes=True)
        self.env_assist.assert_reports([
            fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED),
            fixture.info(report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                         node=self.node_list[1],
                         name_list=[self.name]),
            fixture.warn(
                report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
                node=self.node_list[0],
                reason=self.reason,
                command="remote/booth_set_config",
            ),
        ])
Beispiel #4
0
    def test_no_authfile(self):
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data="")(),
                name="open.conf"
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, "", node_labels=self.node_list,
            )
        )

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)]
            +
            [
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=node,
                    name_list=[self.name]
                ) for node in self.node_list
            ]
        )
Beispiel #5
0
    def test_success(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)
        auth_file_content = b"auth"
        (self.config.fs.open(self.config_path,
                             mock.mock_open(read_data=config_content)(),
                             name="open.conf").fs.open(
                                 auth_file_path,
                                 mock.mock_open(read_data=auth_file_content)(),
                                 mode="rb",
                                 name="open.authfile",
                             ).corosync_conf.load().http.booth.send_config(
                                 self.name,
                                 config_content,
                                 authfile=auth_file,
                                 authfile_data=auth_file_content,
                                 node_labels=self.node_list,
                             ))

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)] + [
                fixture.info(report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                             node=node,
                             name_list=[self.name]) for node in self.node_list
            ])
Beispiel #6
0
    def test_authfile_not_in_booth_dir(self):
        config_file_content = "authfile=/etc/my_booth.conf"

        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data=config_file_content)(),
                name="open.conf"
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, config_file_content, node_labels=self.node_list,
            )
        )

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [
                fixture.warn(report_codes.BOOTH_UNSUPPORTED_FILE_LOCATION),
                fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)
            ]
            +
            [
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=node,
                    name_list=[self.name]
                ) for node in self.node_list
            ]
        )
Beispiel #7
0
 def test_do_not_skip_offline(self, mock_sync, mock_read_key, mock_parse,
                              mock_get_authfile):
     mock_get_authfile.return_value = "/key/path.key"
     mock_read_key.return_value = "key"
     commands.config_sync(self.mock_env, "name")
     self.mock_env.booth.get_config_content.assert_called_once_with()
     mock_read_key.assert_called_once_with(self.mock_rep, "/key/path.key")
     mock_parse.assert_called_once_with("config")
     mock_sync.assert_called_once_with(self.mock_com,
                                       self.mock_rep,
                                       self.node_list,
                                       "name",
                                       "config",
                                       authfile="/key/path.key",
                                       authfile_data="key",
                                       skip_offline=False)
Beispiel #8
0
    def test_all_node_names_missing(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)
        auth_file_content = b"auth"
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data=config_content)(),
                name="open.conf"
            )
            .fs.open(
                auth_file_path,
                mock.mock_open(read_data=auth_file_content)(),
                mode="rb",
                name="open.authfile",
            )
            .corosync_conf.load(filename="corosync-no-node-names.conf")
        )

        self.env_assist.assert_raise_library_error(
            lambda: commands.config_sync(self.env_assist.get_env(), self.name),
            [
                fixture.error(
                    report_codes.COROSYNC_CONFIG_NO_NODES_DEFINED,
                ),
            ]
        )
        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                fatal=False,
            ),
        ])
Beispiel #9
0
    def test_some_node_names_missing(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)
        auth_file_content = b"auth"
        nodes = ["rh7-2"]
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data=config_content)(),
                name="open.conf"
            )
            .fs.open(
                auth_file_path,
                mock.mock_open(read_data=auth_file_content)(),
                mode="rb",
                name="open.authfile",
            )
            .corosync_conf.load(filename="corosync-some-node-names.conf")
            .http.booth.send_config(
                self.name, config_content,
                authfile=auth_file,
                authfile_data=auth_file_content,
                node_labels=nodes,
            )
        )

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [
                fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED),
                fixture.warn(
                    report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                    fatal=False,
                ),
            ]
            +
            [
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=node,
                    name_list=[self.name]
                ) for node in nodes
            ]
        )
Beispiel #10
0
    def test_authfile_not_accessible(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)

        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data=config_content)(),
                name="open.conf"
            )
            .fs.open(
                auth_file_path,
                mode="rb",
                name="open.authfile",
                side_effect=EnvironmentError(0, self.reason, auth_file_path),
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, config_content, node_labels=self.node_list,
            )
        )

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [
                fixture.warn(
                    report_codes.FILE_IO_ERROR,
                    reason="{}: '{}'".format(self.reason, auth_file_path),
                    file_role=file_roles.BOOTH_KEY,
                    file_path=auth_file_path,
                    operation="read",
                ),
                fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)
            ]
            +
            [
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=node,
                    name_list=[self.name]
                ) for node in self.node_list
            ]
        )
Beispiel #11
0
 def test_do_not_skip_offline(
     self, mock_sync, mock_read_key, mock_parse, mock_get_authfile
 ):
     mock_get_authfile.return_value = "/key/path.key"
     mock_read_key.return_value = "key"
     commands.config_sync(self.mock_env, "name")
     self.mock_env.booth.get_config_content.assert_called_once_with()
     mock_read_key.assert_called_once_with(self.mock_rep, "/key/path.key")
     mock_parse.assert_called_once_with("config")
     mock_sync.assert_called_once_with(
         self.mock_com,
         self.mock_rep,
         self.node_list,
         "name",
         "config",
         authfile="/key/path.key",
         authfile_data="key",
         skip_offline=False
     )
Beispiel #12
0
    def test_node_offline_skip_offline(self):
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data="")(),
                name="open.conf"
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, "",
                communication_list=[
                    dict(
                        label=self.node_list[0],
                        errno=1,
                        error_msg=self.reason,
                        was_connected=False,
                    ),
                    dict(
                        label=self.node_list[1],
                    )
                ],
            )
        )

        commands.config_sync(self.env_assist.get_env(), skip_offline_nodes=True)
        self.env_assist.assert_reports(
            [
                fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED),
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=self.node_list[1],
                    name_list=[self.name]
                ),
                fixture.warn(
                    report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
                    node=self.node_list[0],
                    reason=self.reason,
                    command="remote/booth_set_config",
                ),
            ]
        )
Beispiel #13
0
    def test_node_failure_skip_offline(self):
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data="")(),
                name="open.conf"
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, "",
                communication_list=[
                    dict(
                        label=self.node_list[0],
                        response_code=400,
                        output=self.reason,
                    ),
                    dict(
                        label=self.node_list[1],
                    )
                ]
            )
        )

        commands.config_sync(self.env_assist.get_env(), skip_offline_nodes=True)
        self.env_assist.assert_reports(
            [
                fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED),
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=self.node_list[1],
                    name_list=[self.name]
                ),
                fixture.warn(
                    report_codes.NODE_COMMUNICATION_COMMAND_UNSUCCESSFUL,
                    node=self.node_list[0],
                    reason=self.reason,
                    command="remote/booth_set_config",
                ),
            ]
        )
Beispiel #14
0
    def test_success(self):
        auth_file = "auth.file"
        auth_file_path = os.path.join(settings.booth_config_dir, auth_file)
        config_content = "authfile={}".format(auth_file_path)
        auth_file_content = b"auth"
        (self.config
            .fs.open(
                self.config_path,
                mock.mock_open(read_data=config_content)(),
                name="open.conf"
            )
            .fs.open(
                auth_file_path,
                mock.mock_open(read_data=auth_file_content)(),
                mode="rb",
                name="open.authfile",
            )
            .corosync_conf.load()
            .http.booth.send_config(
                self.name, config_content,
                authfile=auth_file,
                authfile_data=auth_file_content,
                node_labels=self.node_list,
            )
        )

        commands.config_sync(self.env_assist.get_env(), self.name)
        self.env_assist.assert_reports(
            [fixture.info(report_codes.BOOTH_CONFIG_DISTRIBUTION_STARTED)]
            +
            [
                fixture.info(
                    report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
                    node=node,
                    name_list=[self.name]
                ) for node in self.node_list
            ]
        )
Beispiel #15
0
    def test_config_not_accessible(self):
        self.config.fs.open(
            self.config_path,
            side_effect=EnvironmentError(0, self.reason, self.config_path),
        )

        self.env_assist.assert_raise_library_error(
            lambda: commands.config_sync(self.env_assist.get_env(), self.name),
            [
                fixture.error(
                    report_codes.FILE_IO_ERROR,
                    reason="{}: '{}'".format(self.reason, self.config_path),
                    file_role=file_roles.BOOTH_CONFIG,
                    file_path=self.config_path,
                    operation="read",
                )
            ],
            expected_in_processor=False,
        )
        self.env_assist.assert_reports([])
Beispiel #16
0
    def test_config_not_accessible(self):
        self.config.fs.open(
            self.config_path,
            side_effect=EnvironmentError(0, self.reason, self.config_path),
        )

        self.env_assist.assert_raise_library_error(
            lambda: commands.config_sync(self.env_assist.get_env(), self.name),
            [
                fixture.error(
                    report_codes.FILE_IO_ERROR,
                    reason="{}: '{}'".format(self.reason, self.config_path),
                    file_role=file_roles.BOOTH_CONFIG,
                    file_path=self.config_path,
                    operation="read",
                )
            ],
            expected_in_processor=False,
        )
        self.env_assist.assert_reports([])