Beispiel #1
0
    def ensure_dependency_satisfied(
        self,
        main_option: str,
        dependent_options: Iterable[str],
    ) -> None:
        """
        Raise a `CmdLineInputError` exception if any of `dependent_options` is
        present without `main_option` being present.

        main_option -- option on which `dependent_options` depend
        dependent_options -- none of these options can be specified if
            `main_option` was not
        """
        if main_option in self._defined_options:
            return
        disallowed = self._defined_options & set(dependent_options)
        if disallowed:
            raise CmdLineInputError("{} cannot be used without '{}'".format(
                format_list(sorted(disallowed)), main_option))
Beispiel #2
0
 def ensure_only_supported(self,
                           *supported_options,
                           hint_syntax_changed: bool = False):
     unsupported_options = (
         # --debug is supported in all commands
         self._defined_options - set(supported_options) - set(["--debug"]))
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             hint="Syntax has changed from previous version. {}".format(
                 SEE_MAN_CHANGES.format("0.11"))
             if hint_syntax_changed else None,
         )
Beispiel #3
0
 def ensure_only_supported(self,
                           *supported_options,
                           hint_syntax_changed: bool = False):
     unsupported_options = (
         # --debug is supported in all commands
         self._defined_options - set(supported_options) - set(["--debug"]))
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             # Print error messages which point users to the changes section
             # in pcs manpage.
             # To be removed in the next significant version.
             hint=(HINT_SYNTAX_CHANGE if hint_syntax_changed else None),
         )
Beispiel #4
0
 def ensure_only_supported(
     self,
     *supported_options: str,
     hint_syntax_changed: bool = False,
     output_format_supported: bool = False,
 ) -> None:
     # --debug is supported in all commands
     supported_options_set = set(supported_options) | {"--debug"}
     if output_format_supported:
         supported_options_set.add(_OUTPUT_FORMAT_OPTION)
     unsupported_options = self._defined_options - supported_options_set
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             hint="Syntax has changed from previous version. {}".format(
                 SEE_MAN_CHANGES.format("0.11"))
             if hint_syntax_changed else None,
         )
Beispiel #5
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_misc")
     write_file_to_tmpfile(rc("cib-empty.xml"), self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     self.allowed_roles = format_list(const.PCMK_ROLES)
Beispiel #6
0
 def test_custom_separator(self):
     self.assertEqual(
         tools.format_list(["item2", "item0", "item1"], separator=" and "),
         "'item0' and 'item1' and 'item2'",
     )
Beispiel #7
0
 def test_multiple_items(self):
     self.assertEqual(
         tools.format_list(["item2", "item0", "item1"]),
         "'item0', 'item1', 'item2'",
     )
Beispiel #8
0
 def test_one_item(self):
     self.assertEqual(tools.format_list(["item"]), "'item'")
Beispiel #9
0
 def test_empty_list(self):
     self.assertEqual(tools.format_list([]), "")
Beispiel #10
0
 def ensure_not_mutually_exclusive(self, *mutually_exclusive):
     options_to_report = self._defined_options & set(mutually_exclusive)
     if len(options_to_report) > 1:
         raise CmdLineInputError("Only one of {} can be used".format(
             format_list(sorted(options_to_report))))