def test_signal_2():
    """Testing if stop.sh is being run when handling signal
    """

    dirpath = tempfile.mkdtemp(prefix="sipplauncher_test_signal2_")
    expected_file = os.path.join(dirpath, "after_has_been_run")
    fs = {
        "test_0000": {
            "before.sh": "sleep 10",
            "uac_ua0.xml": None,
            "after.sh": "touch " + expected_file
        }
    }
    gen_file_struct(dirpath, fs)

    args = shlex.split(
        "sipplauncher --testsuite {0} --dut 1.1.1.1 --leave-temp".format(
            dirpath))
    p = subprocess.Popen(args,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    time.sleep(5)
    p.send_signal(signal.SIGINT)
    p.communicate()
    retcode = p.wait()
    assert (os.path.isfile(expected_file))
Exemplo n.º 2
0
def test(mocker, mock_fs, args, sipp_retcode, expected_ret,
         expected_elapsed_min, expected_elapsed_delta):
    """Testing SIPpTest basic sanity
    """
    dirpath = tempfile.mkdtemp(prefix="sipplauncher_test_Test")
    gen_file_struct(dirpath, mock_fs)

    def my_pysipp_process_run(self):
        time.sleep(SIPP_MOCK_RUN_TIME)  # emulate SIPp run
        sys.exit(sipp_retcode)

    mocker.patch('sipplauncher.PysippProcess.PysippProcess.run',
                 new=my_pysipp_process_run)
    logging.getLogger("pysipp").propagate = 0

    parser = generate_parser()
    parsed_args = parser.parse_args(shlex.split(args))
    parsed_args.testsuite = dirpath
    check_and_patch_args(parsed_args)

    start = time.time()
    ret = run(parsed_args)
    end = time.time()
    elapsed = end - start

    assert (ret == expected_ret)
    assert (expected_elapsed_min <= elapsed
            and elapsed <= expected_elapsed_min + expected_elapsed_delta)

    shutil.rmtree(dirpath)
Exemplo n.º 3
0
def test(mock_fs, args, expected):
    """Testing command-line argument combinations
    """
    dirpath = tempfile.mkdtemp(prefix="sipplauncher_test_args_")
    gen_file_struct(dirpath, mock_fs)

    with cd(dirpath):
        parser = generate_parser()
        if isinstance(expected, BaseException):
            with pytest.raises(type(expected)):
                parsed_args = parser.parse_args(shlex.split(args))
                check_and_patch_args(parsed_args)
        else:
            parsed_args = parser.parse_args(shlex.split(args))
            check_and_patch_args(parsed_args)
Exemplo n.º 4
0
def test(mocker, mock_fs, args, expected):
    """Testing SIPpTest basic sanity
    """
    dirpath = tempfile.mkdtemp(prefix="sipplauncher_test_Test")
    gen_file_struct(dirpath, mock_fs)

    mocker.patch('sipplauncher.PysippProcess.PysippProcess.run',
                 new=lambda x: sys.exit(0))
    logging.getLogger("pysipp").propagate = 0

    def do_test(dirpath, args):
        test = SIPpTest(os.path.join(dirpath, TEST_NAME))
        test.pre_run(args)
        try:
            # First test __do_run() method. It can raise exception.
            if test.state == STATES[1]:
                test._SIPpTest__do_run("", args)

            # Then test run() method. It shouldn't raise exception.
            test.run("", args)
        finally:
            # Always post_run after successful pre_run
            # to not to leave network config from previous run
            test.post_run(args)

        # Issue #9: Create dynamic execution test temp folder for each test execution
        exists = os.path.isdir(test._SIPpTest__temp_folder)
        assert (exists == args.leave_temp)

        return test.state

    parser = generate_parser()
    parsed_args = parser.parse_args(shlex.split(args))
    parsed_args.testsuite = dirpath

    if isinstance(expected, BaseException):
        # Exception is expected
        with pytest.raises(type(expected)):
            check_and_patch_args(parsed_args)
            do_test(dirpath, parsed_args)
    else:
        # Exception is not expected
        check_and_patch_args(parsed_args)
        do_test(dirpath, parsed_args) == expected

    shutil.rmtree(dirpath)
Exemplo n.º 5
0
def test(mocker, mock_fs, args, expected):
    """Testing SIPpTest basic sanity
    """
    dirpath = tempfile.mkdtemp(prefix="sipplauncher_test_Test")
    gen_file_struct(dirpath, mock_fs)

    # mock_call() is called from spawned process.
    # Therfore, we need to use Queue to get data back to us.
    # Just list in memory won't work.
    q = Queue()

    def mock_call(self):
        q.put([ agent.scen_file for agent in self._agents ])

    mocker.patch('pysipp.agent.ScenarioType.__call__', new=mock_call)

    logging.getLogger("pysipp").propagate = 0
    logging.getLogger("scapy.runtime").setLevel(logging.ERROR) # to not to spoil test output with warnings

    parser = generate_parser()
    parsed_args = parser.parse_args(shlex.split(args))
    parsed_args.testsuite = dirpath

    # Exception is not expected
    check_and_patch_args(parsed_args)

    test = SIPpTest(os.path.join(dirpath, TEST_NAME))
    test.pre_run(parsed_args)
    try:
        test.run("", parsed_args)
    finally:
        # Always post_run to not to leave network config from previous run
        test.post_run(parsed_args)

    res = []
    while not q.empty():
        res.append(q.get())

    assert(res == expected)

    shutil.rmtree(dirpath)