예제 #1
0
def manage_plugins(request, plugindir):
    Globals.pluginname = request.param
    targetdir = plugindir[1].replace('/', '\\')
    if platform.system() != 'Windows':
        fullbuilddir = os.path.join(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))), Globals.builddir)
        cmds = [[
            'ssh', sshopts,
            '%s@%s' % (remoteuser, remote_ip),
            'if not exist %s md %s' % (targetdir, targetdir)
        ],
                [
                    'scp', sshopts,
                    os.path.join(plugindir[0], request.param),
                    '%s@%s:%s' % (remoteuser, remote_ip, plugindir[1])
                ],
                [
                    'scp', sshopts,
                    os.path.join(fullbuilddir, Globals.binaryplugin),
                    '%s@%s:%s' % (remoteuser, remote_ip, plugindir[1])
                ]]
        for cmd in cmds:
            assert_subprocess(cmd)
    yield
    if platform.system() == 'Windows':
        for plugin in [request.param, Globals.binaryplugin]:
            for i in range(0, 5):
                try:
                    os.unlink(os.path.join(targetdir, plugin))
                    break
                except WindowsError as e:
                    # For some reason, the exe plugin remains locked for a short
                    # while every now and then. Just sleep 1 s and retry.
                    sys.stderr.write('%s\n' % str(e))
                    time.sleep(1)
예제 #2
0
def manage_plugin(request):
    Globals.newline = request.param
    plugindir = (Globals.mrpedir
                 if Globals.newline < 0 else Globals.includedir)
    source = os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
        Globals.mrpedir, Globals.pluginname)
    targetdir = os.path.join(remotedir, plugindir)
    targetdir_windows = targetdir.replace('/', '\\')
    if platform.system() != 'Windows':
        cmds = [
            ['ssh'] + sshopts + [
                '%s@%s' % (remoteuser, remote_ip),
                'if not exist "%s" md "%s"' %
                (targetdir_windows, targetdir_windows)
            ], ['scp'] + sshopts +
            [source, '%s@%s:"%s"' % (remoteuser, remote_ip, targetdir)]
        ]
        for cmd in cmds:
            assert_subprocess(cmd)
    elif Globals.newline >= 0:
        with open(os.path.join(targetdir, Globals.cfgfile), 'wb') as cfg:
            path = os.path.join(targetdir_windows, Globals.pluginname)
            if Globals.newline == 2:
                path = path.replace('\\', '/')
            cfg.write(
                'check = %s "%s"%s' %
                (Globals.checkname, path, '\n' if Globals.newline > 0 else ""))
    yield
    if platform.system() == 'Windows':
        os.unlink(os.path.join(targetdir, Globals.pluginname))
        if Globals.newline >= 0:
            os.unlink(os.path.join(targetdir, Globals.cfgfile))
예제 #3
0
def manage_ohm_binaries():
    if platform.system() != 'Windows':
        binaries = ['OpenHardwareMonitorCLI.exe', 'OpenHardwareMonitorLib.dll']

        sourcedir = os.path.normpath(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                         '..', '..', 'omd', 'packages', 'openhardwaremonitor'))

        targetdir = os.path.join(remotedir, 'bin')
        targetdir_win = targetdir.replace('/', '\\')

        cmds = [['ssh'] + sshopts + [
            '%s@%s' % (remoteuser, remote_ip),
            'if not exist %s md %s' % (targetdir_win, targetdir_win)
        ], ['scp'] + sshopts + [os.path.join(sourcedir, b) for b in binaries] +
                ['%s@%s:%s' % (remoteuser, remote_ip, targetdir)]]
        for cmd in cmds:
            assert_subprocess(cmd)
    yield
    if platform.system() != 'Windows':
        cmd = ['ssh'] + sshopts + [
            '%s@%s' % (remoteuser, remote_ip), ' && '.join(
                ['del %s' % '\\'.join([targetdir_win, b]) for b in binaries])
        ]
        assert_subprocess(cmd)
예제 #4
0
def scp_tests():
    test_files = [
        os.path.abspath(t) for t in glob.glob(os.path.join(localdir, 'test_*')) +
        [os.path.join(localdir, 'remote.py')]
    ]
    cmd = ['scp'] + sshopts + test_files + ['%s@%s:%s' % (remoteuser, remote_ip, remotedir)]
    assert_subprocess(cmd)
예제 #5
0
def scp_agent_exe():
    agents_windows_dir = os.path.dirname(localdir)
    agent_exe = os.path.join(agents_windows_dir, 'check_mk_agent-64.exe')
    cmd = ['scp'] + sshopts + [
        agent_exe, '%s@%s:%s' % (remoteuser, remote_ip, remotedir)
    ]
    assert_subprocess(cmd)
예제 #6
0
def create_event(eventid):
    if platform.system() == 'Windows':
        cmd = [
            'eventcreate.exe', '/l', Globals.testlog, '/t',
            Globals.testeventtype, '/so', Globals.testsource, '/id',
            '%d' % eventid, '/d', Globals.testdescription
        ]
        assert_subprocess(cmd)
예제 #7
0
def lock_operation(command):
    # Copy essential sources always to remote host. This is necessary as
    # another test executor might have removed the files meanwhile.
    files = [os.path.join(localdir, f) for f in ['lock.py', 'remote.py']]
    cmds = [['scp'] + sshopts + files + ['%s@%s:%s' % (remoteuser, remote_ip, remotedir)],
            lock_cmd(command)]
    for cmd in cmds:
        assert_subprocess(cmd)
예제 #8
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 copy_capfile():
    cmd = ['scp'] + sshopts + [
        Globals.capfile,
        '%s@%s:"%s"' % (remoteuser, remote_ip, remotedir)
    ]
    assert_subprocess(cmd)