示例#1
0
文件: booth.py 项目: jmartign/pcs
def booth_cmd(lib, argv, modifiers):
    """
    routes booth command
    """
    if len(argv) < 1:
        usage.booth()
        sys.exit(1)

    sub_cmd, argv_next = argv[0], argv[1:]
    try:
        if sub_cmd == "help":
            usage.booth(argv)
        elif sub_cmd == "config":
            command.config_show(lib, argv_next, modifiers)
        elif sub_cmd == "setup":
            command.config_setup(lib, argv_next, modifiers)
        elif sub_cmd == "destroy":
            command.config_destroy(lib, argv_next, modifiers)
        elif sub_cmd == "ticket":
            if len(argv_next) < 1:
                raise CmdLineInputError()
            if argv_next[0] == "add":
                command.config_ticket_add(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "remove":
                command.config_ticket_remove(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "grant":
                command.ticket_grant(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "revoke":
                command.ticket_revoke(lib, argv_next[1:], modifiers)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "create":
            command.get_create_in_cluster(resource_create,
                                          resource_remove)(lib, argv_next,
                                                           modifiers)
        elif sub_cmd == "remove":
            command.get_remove_from_cluster(resource_remove)(lib, argv_next,
                                                             modifiers)
        elif sub_cmd == "restart":
            command.get_restart(resource_restart)(lib, argv_next, modifiers)
        elif sub_cmd == "sync":
            command.sync(lib, argv_next, modifiers)
        elif sub_cmd == "pull":
            command.pull(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            command.enable(lib, argv_next, modifiers)
        elif sub_cmd == "disable":
            command.disable(lib, argv_next, modifiers)
        elif sub_cmd == "start":
            command.start(lib, argv_next, modifiers)
        elif sub_cmd == "stop":
            command.stop(lib, argv_next, modifiers)
        elif sub_cmd == "status":
            command.status(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "booth", sub_cmd)
示例#2
0
文件: booth.py 项目: wyatt88/pcs
def booth_cmd(lib, argv, modifiers):
    """
    routes booth command
    """
    if len(argv) < 1:
        usage.booth()
        sys.exit(1)

    sub_cmd, argv_next = argv[0], argv[1:]
    try:
        if sub_cmd == "help":
            usage.booth(argv)
        elif sub_cmd == "config":
            command.config_show(lib, argv_next, modifiers)
        elif sub_cmd == "setup":
            command.config_setup(lib, argv_next, modifiers)
        elif sub_cmd == "destroy":
            command.config_destroy(lib, argv_next, modifiers)
        elif sub_cmd == "ticket":
            if len(argv_next) < 1:
                raise CmdLineInputError()
            if argv_next[0] == "add":
                command.config_ticket_add(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "remove":
                command.config_ticket_remove(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "grant":
                command.ticket_grant(lib, argv_next[1:], modifiers)
            elif argv_next[0] == "revoke":
                command.ticket_revoke(lib, argv_next[1:], modifiers)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "create":
            command.get_create_in_cluster(resource_create)(
                lib, argv_next, modifiers
            )
        elif sub_cmd == "remove":
            command.get_remove_from_cluster(resource_remove)(
                lib, argv_next, modifiers
            )
        elif sub_cmd == "sync":
            command.sync(lib, argv_next, modifiers)
        elif sub_cmd == "pull":
            command.pull(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            command.enable(lib, argv_next, modifiers)
        elif sub_cmd == "disable":
            command.disable(lib, argv_next, modifiers)
        elif sub_cmd == "start":
            command.start(lib, argv_next, modifiers)
        elif sub_cmd == "stop":
            command.stop(lib, argv_next, modifiers)
        elif sub_cmd == "status":
            command.status(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "booth", sub_cmd)
示例#3
0
 def test_call_lib_with_ticket_name(self):
     lib = mock.MagicMock()
     lib.booth = mock.MagicMock()
     lib.booth.config_ticket_add = mock.MagicMock()
     command.config_ticket_add(lib,
                               arg_list=["TICKET_A", "timeout=10"],
                               modifiers={"force": True})
     lib.booth.config_ticket_add.assert_called_once_with(
         "TICKET_A", {"timeout": "10"}, allow_unknown_options=True)
示例#4
0
 def test_lib_call_minimal(self):
     booth_cmd.config_ticket_add(self.lib, ["ticketA"],
                                 dict_to_modifiers(dict()))
     self.lib.booth.config_ticket_add.assert_called_once_with(
         "ticketA",
         {},
         instance_name=None,
         allow_unknown_options=False,
     )
示例#5
0
 def test_call_lib_with_ticket_name(self):
     lib = mock.MagicMock()
     lib.booth = mock.MagicMock()
     lib.booth.config_ticket_add = mock.MagicMock()
     command.config_ticket_add(
         lib,
         arg_list=["TICKET_A", "timeout=10"],
         modifiers={"force": True}
     )
     lib.booth.config_ticket_add.assert_called_once_with(
         "TICKET_A",
         {"timeout": "10"},
         allow_unknown_options=True
     )
示例#6
0
 def test_lib_call_full(self):
     booth_cmd.config_ticket_add(
         self.lib, ["ticketA", "a=A", "b=B"],
         dict_to_modifiers({
             "name": "my_booth",
             "force": True,
             "booth-conf": "C",
             "booth-key": "K",
         }))
     self.lib.booth.config_ticket_add.assert_called_once_with(
         "ticketA",
         {
             "a": "A",
             "b": "B"
         },
         instance_name="my_booth",
         allow_unknown_options=True,
     )
示例#7
0
 def test_call_lib_with_ticket_name(self):
     lib = mock.MagicMock()
     lib.booth = mock.MagicMock()
     lib.booth.config_ticket_add = mock.MagicMock()
     command.config_ticket_add(lib, arg_list=["TICKET_A"], modifiers={})
     lib.booth.config_ticket_add.assert_called_once_with("TICKET_A")