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(src_exec_dir) 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)
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 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)
def actual_output(request, write_config): if platform.system() == 'Windows': # Run agent and yield its output. try: exit_code, _stdout, _stderr = run_subprocess([main_exe] + Globals.param) if _stdout: sys.stdout.write(_stdout.decode(encoding='cp1252')) if _stderr: sys.stderr.write(_stderr.decode(encoding='cp1252')) expected_code = 13 if Globals.param[0] == 'bad' else 0 assert expected_code == exit_code # Usage is written to stderr, actual cmd output to stdout. work_load = _stdout.decode(encoding='cp1252') yield work_load.splitlines() finally: pass else: # Not on Windows, test run remotely, nothing to be done. yield
def actual_output(request, write_config): if platform.system() == 'Windows': # Run agent and yield its output. try: save_cwd = os.getcwd() os.chdir(src_exec_dir) cmd = [] exit_code, stdout, stderr = run_subprocess([src_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