def start_dobby_daemon(): """Starts DobbyDaemon service, this service is then run in background and must be closed with stop_dobby_daemon. Parameters: None Returns: subproc (subprocess.Popen): DobbyDaemon service process, True for platform xi_6 """ if test_utils.selected_platform == test_utils.Platforms.xi_6: subprocess.run(["systemctl", "stop", "dobby"]) else: subprocess.run(["sudo", "pkill", "DobbyDaemon"]) test_utils.print_log("Starting Dobby Daemon (logging to Journal)...", test_utils.Severity.debug) # as this process is running infinitely we cannot use run_command_line as it waits for execution to end subproc = subprocess.Popen(["sudo", "DobbyDaemon", "--nofork", #"--noconsole", "--journald" ], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) sleep(1) return subproc
def stop_dobby_daemon(): """Stops DobbyDaemon service. For Xi6 DobbyDaemon is running all the time so this function returns does nothing Parameters: None Returns: subproc (subprocess.run): killing DobbyDaemon process, True for platform xi_6 """ test_utils.print_log("Stopping Dobby Daemon", test_utils.Severity.debug) subproc = test_utils.run_command_line(["sudo", "pkill", "DobbyDaemon"]) sleep(0.2) return subproc
def execute_test(): output_table = [] with test_utils.dobby_daemon(): for test in tests: process = dobby_tool_command(test.command, test.container_id) test_utils.print_log("command output = %s" % process.stdout, test_utils.Severity.debug) result = test.expected_output in process.stdout if test.negation: result = not result output = test_utils.create_simple_test_output(test, result) output_table.append(output) test_utils.print_single_result(output) return test_utils.count_print_results(output_table)
def get_gui_test_path(): """Gets path to gui test, which reads websocket. This is done so no external high-python-version library were required Parameters: None Returns: gui_path (path): path to JS gui test """ js_test_name = "gui_test.js" # relative path "test_location/%s" % js_test_name" gui_path = path.abspath(path.join(path.dirname(__file__), js_test_name)) test_utils.print_log("JS gui test path is %s" % gui_path, test_utils.Severity.debug) return gui_path
def get_websocket_data(): """Runs gui_test.js inside Spark. Gets as/apps/status and closes spark. Parameters: None Returns: buffer (string): string that contains json with running apps """ script_to_run = ["./Spark", get_gui_test_path()] starting_point = "-----------------------begin_as_apps_status-----------------------" end_point = "----------------------end_of_as_apps_status----------------------" original_path = path.abspath(path.dirname(__file__)) chdir("/home/root/") subproc = subprocess.Popen(script_to_run, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) buffer = "" inside_block = False while True: line = subproc.stdout.readline() test_utils.print_log("Spark - %s" % line, test_utils.Severity.debug) if end_point in line: break if inside_block: buffer += line if starting_point in line: inside_block = True # send ctrl + c to end process subproc.send_signal(signal.SIGINT) chdir(original_path) return buffer
def wait_for_string(proc, string_to_find): """Waits indefinitely until string is found in process. Must be run with timeout multiprocess. Parameters: proc (process): process in which we want to read string_to_find (string): what we want to find in process Returns: None: Returns nothing if found, never ends if not found """ while True: # notice that all data are in stderr not in stdout, this is DobbyDaemon design output = proc.stderr.readline() if string_to_find in output: test_utils.print_log("Found string \"%s\"" % string_to_find, test_utils.Severity.debug) return
def start_wpeframework_vm(): """Starts wpeframework on virtual machine Parameters: None Returns: subproc (process): process containing wpeframework """ test_utils.print_log("Starting WPEFramework", test_utils.Severity.debug) # as this process is running infinitely we cannot use run_command_line as it waits for execution to end subproc = subprocess.Popen(["/usr/local/bin/WPEFramework"], universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) sleep(2) return subproc
def test_container(container_id, expected_output): """Runs container and check if output contains expected output Parameters: container_id (string): name of container to run expected_output (string): output that should be provided by container Returns: (pass (bool), message (string)): Returns if expected output found and message """ test_utils.print_log("Running %s container test" % container_id, test_utils.Severity.debug) with test_utils.untar_bundle(container_id) as bundle_path: launch_result = test_utils.launch_container(container_id, bundle_path) if launch_result: return validate_output_file(container_id, expected_output) return False, "Container did not launch successfully"
def run_all_tests(): success_count = 0 total_count = 0 tested_groups_count = 0 for test in supported_tests: test_utils.print_log("\nExecuting test \"%s\"" % test.__name__, test_utils.Severity.info) success, total = test.execute_test() success_count += success total_count += total if total > 0: tested_groups_count += 1 sleep(1) test_utils.print_log("\n\nSummary:", test_utils.Severity.info) skipped_test_count = len(supported_tests) - tested_groups_count if skipped_test_count: test_utils.print_log("Skipped %d test groups" % skipped_test_count, test_utils.Severity.info) test_utils.print_log("Tested %d test groups" % tested_groups_count, test_utils.Severity.info) test_utils.print_results(success_count, total_count)
def read_asynchronous(proc, string_to_find, timeout): """Reads asynchronous from process. Ends when found string or timeout occurred. Parameters: proc (process): process in which we want to read string_to_find (string): what we want to find in process timeout (float): how long we should wait if string not found (seconds) Returns: found (bool): True if found string_to_find inside proc. """ # as this function should not be used outside asynchrounous read, it is moved inside it def wait_for_string(proc, string_to_find): """Waits indefinitely until string is found in process. Must be run with timeout multiprocess. Parameters: proc (process): process in which we want to read string_to_find (string): what we want to find in process Returns: None: Returns nothing if found, never ends if not found """ while True: # notice that all data are in stderr not in stdout, this is DobbyDaemon design output = proc.stderr.readline() if string_to_find in output: test_utils.print_log("Found string \"%s\"" % string_to_find, test_utils.Severity.debug) return found = False reader = multiprocessing.Process(target=wait_for_string, args=(proc, string_to_find), kwargs={}) test_utils.print_log("Starting multithread read", test_utils.Severity.debug) reader.start() reader.join(timeout) # if thread still running if reader.is_alive(): test_utils.print_log("Reader still exists, closing", test_utils.Severity.debug) reader.terminate() test_utils.print_log("Not found string \"%s\"" % string_to_find, test_utils.Severity.error) else: found = True return found
def create_successful_regex_answer(additional_content=""): expression = '{"jsonrpc":"2\.0","id":3,"result":{%s"success":true}}' % additional_content test_utils.print_log('Regular expression is: @%s@' % expression, test_utils.Severity.debug) return expression