Example #1
0
    def test_error(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        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.get_cib_xml(mock_runner),
            (
                Severity.ERROR,
                report_codes.CIB_LOAD_ERROR,
                {
                    "reason": expected_stderr + "\n" + expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--local", "--query"]
        )
Example #2
0
    def test_scope_error(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        expected_retval = 6
        scope = "test_scope"
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.get_cib_xml(mock_runner, scope=scope),
            (
                Severity.ERROR,
                report_codes.CIB_LOAD_ERROR_SCOPE_MISSING,
                {
                    "scope": scope,
                    "reason": expected_stderr + "\n" + expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [
                self.path("cibadmin"),
                "--local", "--query", "--scope={0}".format(scope)
            ]
        )
Example #3
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)
Example #4
0
    def test_success(self):
        expected_xml = "<xml />"
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_xml, expected_retval)

        real_xml = lib.get_cib_xml(mock_runner)

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--local", "--query"]
        )
        self.assertEqual(expected_xml, real_xml)
Example #5
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)
Example #6
0
    def test_success_scope(self):
        expected_stdout = "<xml />"
        expected_stderr = ""
        expected_retval = 0
        scope = "test_scope"
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        real_xml = lib.get_cib_xml(mock_runner, scope)

        mock_runner.run.assert_called_once_with(
            [
                self.path("cibadmin"),
                "--local", "--query", "--scope={0}".format(scope)
            ]
        )
        self.assertEqual(expected_stdout, real_xml)
Example #7
0
File: env.py Project: dchirikov/pcs
 def _get_cib_xml(self):
     if self.is_cib_live:
         return get_cib_xml(self.cmd_runner())
     else:
         return self._cib_data