def test_normal(self, command, dry_run, expected):
        SubprocessRunner.is_save_history = False
        SubprocessRunner.clear_history()

        loop_count = 3
        for _i in range(loop_count):
            SubprocessRunner(command, dry_run=dry_run).run()
        assert len(SubprocessRunner.get_history()) == 0

        SubprocessRunner.is_save_history = True
        for _i in range(loop_count):
            SubprocessRunner(command, dry_run=dry_run).run()
        assert len(SubprocessRunner.get_history()) == loop_count
Esempio n. 2
0
def main():
    options = parse_option()

    set_log_level(options.log_level)

    subprocrunner.Which("tc").verify()

    subprocrunner.SubprocessRunner.is_save_history = True
    if options.tc_command_output != TcCoomandOutput.NOT_SET:
        subprocrunner.SubprocessRunner.is_dry_run = True

    tc_param = {}
    for device in options.device:
        try:
            verify_network_interface(device)
        except NetworkInterfaceNotFoundError as e:
            logger.debug(str(e))
            continue

        tc_param.update(TcShapingRuleParser(device, logger).get_tc_parameter())

    command_history = "\n".join(SubprocessRunner.get_history())

    if options.tc_command_output == TcCoomandOutput.STDOUT:
        print(command_history)
        return 0

    if options.tc_command_output == TcCoomandOutput.SCRIPT:
        write_tc_script("tcshow", command_history)
        return 0

    logger.debug("command history\n{}".format(command_history))
    print(json.dumps(tc_param, indent=4))

    return 0