Exemple #1
0
def post_test():
    yield
    if platform.system() == 'Windows':
        try:
            if Globals.param[0] == 'install':
                cmd = ['sc', 'query', 'Check_MK_Agent']
                exit_code, stdout, stderr = run_subprocess(cmd)
                assert exit_code == 0, "'%s' failed" % ' '.join(cmd)
                assert 'SERVICE_NAME: Check_MK_Agent' in stdout, ('Agent was not installed')
            elif Globals.param[0] == 'remove':
                cmd = ['sc', 'query', 'Check_MK_Agent']
                exit_code, stdout, stderr = run_subprocess(cmd)
                assert exit_code == 1060, 'Check_MK_Agent should not be running'
        finally:
            # Make sure the service is stopped and deleted after tests:
            for subcmd in ['stop', 'delete']:
                cmd = ['sc', subcmd, 'Check_MK_Agent']
                run_subprocess(cmd)  # ignore possible failure
        if Globals.param[0] == 'unpack':
            try:
                save_cwd = os.getcwd()
                os.chdir(remotedir)
                if Globals.param[2] == 'script':
                    verify_plugin_contents()
                else:
                    verify_plugin_output()
                verify_uninstall_batch(Globals.param[2] == 'script')
            finally:
                # run_uninstall_plugins()
                os.unlink(Globals.remote_capfile)
                shutil.rmtree(Globals.testfiles[1])
                os.chdir(save_cwd)
    else:
        if Globals.param[0] == 'unpack':
            os.unlink(Globals.capfile)
def run_uninstall_plugins():
    if os.path.isfile(Globals.uninstall_batch):
        cmd = [Globals.uninstall_batch]
        exit_code, stdout, stderr = run_subprocess(cmd)
        if stdout:
            sys.stdout.write(stdout)
        if stderr:
            sys.stderr.write(stderr)
Exemple #3
0
def pre_test(request):
    if request.param[0] == 'showconfig':
        pytest.skip("Agent option '%s' is broken, skipping test..." % request.param[0])
    Globals.param = request.param
    if platform.system() == 'Windows':
        if Globals.param[0] == 'install':
            for subcmd in ['stop', 'delete']:
                cmd = ['sc', subcmd, 'Check_MK_Agent']
                run_subprocess(cmd)  # ignore possible failure
        elif Globals.param[0] == 'remove':
            assert_subprocess(['sc', 'create', 'Check_MK_Agent', 'binPath=%s' % remotedir])
        elif Globals.param[0] == 'unpack':
            run_uninstall_plugins()
    elif Globals.param[0] == 'unpack':
        pack_plugins(Globals.param[2] == 'script')
        copy_capfile()
    yield
def get_fileid(filename):
    cmd = ['fsutil', 'file', 'queryfileid', filename]
    exit_code, stdout, stderr = run_subprocess(cmd)
    if stdout:
        sys.stdout.write(stdout)
    if stderr:
        sys.stderr.write(stderr)
    assert exit_code == 0, "'%s' failed" % ' '.join(cmd)
    m = Globals.fileid_pattern.match(stdout)
    assert m is not None, "'%s' does not match fileid pattern" % stdout
    return int(m.group('fileid'), base=16)
Exemple #5
0
def rm_rf_testfiles():
    cmd = ['ssh'] + sshopts + [
        '%s@%s' % (remoteuser, remote_ip),
        ('cd %s' % remotedir + ' && del /S /F /Q * '
         '&& for /d %G in ("*") do rmdir "%~G" /Q')
    ]
    exit_code, stdout, stderr = run_subprocess(cmd)
    if stdout:
        sys.stdout.write(stdout)
    if stderr:
        sys.stderr.write(stderr)
    if exit_code != 0:
        pytest.skip(stderr)
Exemple #6
0
def actual_output(request, write_config):
    if platform.system() == 'Windows':
        # Run agent and yield its output.
        try:
            save_cwd = os.getcwd()
            os.chdir(remotedir)
            cmd = []
            exit_code, stdout, stderr = run_subprocess([agent_exe] + Globals.param)
            if stdout:
                sys.stdout.write(stdout)
            if stderr:
                sys.stderr.write(stderr)
            expected_code = 1 if Globals.param[0] == '/?' else 0
            assert expected_code == exit_code
            # Usage is written to stderr, actual cmd output to stdout.
            handle = stderr if Globals.param[0] == '/?' else stdout
            yield handle.splitlines()
        finally:
            os.chdir(save_cwd)
    else:
        # Not on Windows, test run remotely, nothing to be done.
        yield
def verify_plugin_output():
    cmd = [os.path.join(Globals.testfiles[1], Globals.binaryplugin)]
    exit_code, stdout, stderr = run_subprocess(cmd)
    assert exit_code == 0, "'%s' failed" % Globals.binaryplugin
    assert "<<<monty_python>>>\r\nMonty Python's Flying Circus\r\n" == stdout
    assert len(stderr) == 0, "Expected empty stderr, got '%s'" % stderr