Exemplo n.º 1
0
def run_permission_add(argv):
    if len(argv) < 4:
        raise utils.CmdLineInputError()
    role_id = argv.pop(0)
    permission_info_list = argv_to_permission_info_list(argv)

    cib = get_cib(get_cib_xml())
    provide_role(cib, role_id)
    add_permissions_to_role(cib, role_id, permission_info_list)
    replace_cib_configuration(cib)
Exemplo n.º 2
0
def run_create_role(argv):
    if len(argv) < 1:
        raise utils.CmdLineInputError()
    role_id = argv.pop(0)
    description = ""
    desc_key = 'description='
    if argv and argv[0].startswith(desc_key) and len(argv[0]) > len(desc_key):
        description = argv.pop(0)[len(desc_key):]
    permission_info_list = argv_to_permission_info_list(argv)

    cib = get_cib(get_cib_xml())
    create_role(cib, role_id, description)
    add_permissions_to_role(cib, role_id, permission_info_list)
    replace_cib_configuration(cib)
Exemplo n.º 3
0
    def test_cib_upgraded(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_stdout, expected_stderr,
                                        expected_retval)

        lib.replace_cib_configuration(mock_runner,
                                      XmlManipulation.from_str(xml).tree, True)

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe"],
            stdin_string=xml)
Exemplo n.º 4
0
    def test_cib_upgraded(self):
        xml = "<xml/>"
        expected_output = "expected output"
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_output, expected_retval)

        lib.replace_cib_configuration(
            mock_runner, XmlManipulation.from_str(xml).tree, True
        )

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe"],
            stdin_string=xml
        )
Exemplo n.º 5
0
    def test_error(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = "expected stderr"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.replace_cib_configuration(
                    mock_runner,
                    XmlManipulation.from_str(xml).tree
                )
            ,
            (
                Severity.ERROR,
                report_codes.CIB_PUSH_ERROR,
                {
                    "reason": expected_stderr,
                    "pushed_cib": expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [
                self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe",
                "--scope", "configuration"
            ],
            stdin_string=xml
        )
Exemplo n.º 6
0
    def test_error(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = "expected stderr"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_stdout, expected_stderr,
                                        expected_retval)

        assert_raise_library_error(
            lambda: lib.replace_cib_configuration(
                mock_runner,
                XmlManipulation.from_str(xml).tree),
            (Severity.ERROR, report_codes.CIB_PUSH_ERROR, {
                "reason": expected_stderr,
                "pushed_cib": expected_stdout,
            }))

        mock_runner.run.assert_called_once_with([
            self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe",
            "--scope", "configuration"
        ],
                                                stdin_string=xml)