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(src_exec_dir, '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)
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(src_exec_dir, 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))
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)
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' % src_exec_dir]) elif Globals.param[0] == 'unpack': run_uninstall_plugins() elif Globals.param[0] == 'unpack': pack_plugins(Globals.param[2] == 'script') copy_capfile() yield
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)
def copy_capfile(): cmd = [ 'scp', sshopts, Globals.capfile, '%s@%s:"%s"' % (remoteuser, remote_ip, src_exec_dir) ] assert_subprocess(cmd)