Пример #1
0
 def test_returns_false_on_unknown_long_option(self):
     self.assertFalse(is_option_expecting_value("--not-specified-long-opt"))
Пример #2
0
 def test_returns_false_on_dash_dash(self):
     self.assertFalse(is_option_expecting_value("--"))
Пример #3
0
 def test_returns_false_on_long_option_without_value(self):
     self.assertFalse(is_option_expecting_value("--clone"))
Пример #4
0
 def test_returns_false_on_unknown_short_option(self):
     self.assertFalse(is_option_expecting_value("-x"))
Пример #5
0
 def test_returns_true_on_long_option_with_value(self):
     self.assertTrue(is_option_expecting_value("--name"))
Пример #6
0
 def test_returns_false_on_short_option_without_value(self):
     self.assertFalse(is_option_expecting_value("-h"))
Пример #7
0
 def test_returns_false_on_option_including_value(self):
     self.assertFalse(is_option_expecting_value("--name=Name"))
     self.assertFalse(is_option_expecting_value("-fvalue"))
Пример #8
0
 def test_returns_true_on_long_option_with_value(self):
     self.assertTrue(is_option_expecting_value("--name"))
Пример #9
0
 def test_returns_false_on_unknown_long_option(self):
     self.assertFalse(is_option_expecting_value("--not-specified-long-opt"))
Пример #10
0
 def test_returns_false_on_dash_dash(self):
     self.assertFalse(is_option_expecting_value("--"))
Пример #11
0
 def test_returns_false_on_unknown_short_option(self):
     self.assertFalse(is_option_expecting_value("-x"))
Пример #12
0
 def test_returns_false_on_long_option_without_value(self):
     self.assertFalse(is_option_expecting_value("--clone"))
Пример #13
0
 def test_returns_false_on_short_option_without_value(self):
     self.assertFalse(is_option_expecting_value("-h"))
Пример #14
0
 def test_returns_false_on_option_including_value(self):
     self.assertFalse(is_option_expecting_value("--name=Name"))
     self.assertFalse(is_option_expecting_value("-fvalue"))
Пример #15
0
 def test_returns_true_on_short_option_with_value(self):
     self.assertTrue(is_option_expecting_value("-f"))
Пример #16
0
def _non_root_run(argv_cmd):
    """
    This function will run commands which has to be run as root for users which
    are not root. If it required to run such command as root it will do that by
    sending it to the local pcsd and then it will exit.
    """
    # matching the commands both in here and in pcsd expects -o and --options
    # to be at the end of a command
    argv_and_options = argv_cmd[:]
    for option, value in utils.pcs_options.items():
        if parse_args.is_option_expecting_value(option):
            argv_and_options.extend([option, value])
        else:
            argv_and_options.append(option)

    # specific commands need to be run under root account, pass them to pcsd
    # don't forget to allow each command in pcsd.rb in "post /run_pcs do"
    root_command_list = [
        ["cluster", "auth", "..."],
        ["cluster", "corosync", "..."],
        ["cluster", "destroy", "..."],
        ["cluster", "disable", "..."],
        ["cluster", "enable", "..."],
        ["cluster", "node", "..."],
        ["cluster", "pcsd-status", "..."],
        ["cluster", "start", "..."],
        ["cluster", "stop", "..."],
        ["cluster", "sync", "..."],
        # ['config', 'restore', '...'], # handled in config.config_restore
        ["host", "auth", "..."],
        ["host", "deauth", "..."],
        ["pcsd", "deauth", "..."],
        ["pcsd", "sync-certificates"],
        ["quorum", "device", "status", "..."],
        ["quorum", "status", "..."],
        ["status"],
        ["status", "corosync", "..."],
        ["status", "pcsd", "..."],
        ["status", "quorum", "..."],
        ["status", "status", "..."],
    ]

    for root_cmd in root_command_list:
        if (argv_and_options == root_cmd) or (
            root_cmd[-1] == "..."
            and argv_and_options[: len(root_cmd) - 1] == root_cmd[:-1]
        ):
            # handle interactivity of 'pcs cluster auth'
            if argv_and_options[0:2] in [["cluster", "auth"], ["host", "auth"]]:
                if "-u" not in utils.pcs_options:
                    username = utils.get_terminal_input("Username: "******"-u", username])
                if "-p" not in utils.pcs_options:
                    password = utils.get_terminal_password()
                    argv_and_options.extend(["-p", password])

            # call the local pcsd
            err_msgs, exitcode, std_out, std_err = utils.call_local_pcsd(
                argv_and_options
            )
            if err_msgs:
                for msg in err_msgs:
                    utils.err(msg, False)
                sys.exit(1)
            if std_out.strip():
                print(std_out)
            if std_err.strip():
                sys.stderr.write(std_err)
            sys.exit(exitcode)
Пример #17
0
 def test_returns_true_on_short_option_with_value(self):
     self.assertTrue(is_option_expecting_value("-f"))