def get_team_names(noerror=False): """ Retrieve all teams user has access to """ try: username = ConfigModule.get_config_value(AUTHENTICATION_TAG, USERNAME_TAG) password = ConfigModule.get_config_value(AUTHENTICATION_TAG, PASSWORD_TAG) if password == "YourUserNameGoesHere": password = password else: password = pass_decode("zeuz", password) user_info_object = {USERNAME_TAG: username, PASSWORD_TAG: password} if not check_server_online(): return [] r = RequestFormatter.Get("get_user_teams_api", user_info_object) teams = [x[0] for x in r] # Convert into a simple list return teams except: if noerror == False: CommonUtil.ExecLog("", "Error retrieving team names", 4, False) return []
def get_project_names(team): """ Retrieve projects for given team """ try: username = ConfigModule.get_config_value(AUTHENTICATION_TAG, USERNAME_TAG) password = ConfigModule.get_config_value(AUTHENTICATION_TAG, PASSWORD_TAG) if password == "YourUserNameGoesHere": password = password else: password = pass_decode("zeuz", password) user_info_object = { USERNAME_TAG: username, PASSWORD_TAG: password, TEAM_TAG: team, } if not check_server_online(): return [] r = RequestFormatter.Get("get_user_projects_api", user_info_object) projects = [x[0] for x in r] # Convert into a simple list return projects except: CommonUtil.ExecLog("", "Error retrieving project names", 4, False) return []
def get_url(): # Find node id file node_id_file_path = Path( os.path.abspath(__file__).split("Framework")[0] ) / Path("node_id.conf") unique_id = ConfigModule.get_config_value( "UniqueID", "id", node_id_file_path ) node_id = ( ConfigModule.get_config_value("Authentication", "username") + "_" + str(unique_id) ) server_url = urlparse(ConfigModule.get_config_value("Authentication", "server_address")) path = f"faster/v1/ws/live_log/send/{node_id}" if server_url.scheme == "https": protocol = "wss" else: protocol = "ws" if server_url.hostname in ("localhost", "127.0.0.1"): # Development URL (as websocket server runs on a different port) ws_url = f"{protocol}://{server_url.hostname}:8080/{path}" else: # Production URL (path prefixed with `faster`) ws_url = f"{protocol}://{server_url.netloc}/{path}" return ws_url
def TakeScreenShot(function_name, local_run=False): """ Puts TakeScreenShot into a thread, so it doesn't block test case execution """ # if debug_status: return # Todo: Comment this line out try: if upload_on_fail and rerun_on_fail and not rerunning_on_fail and not debug_status: return sModuleInfo = inspect.currentframe( ).f_code.co_name + " : " + MODULE_NAME # Read values from config file take_screenshot_settings = ConfigModule.get_config_value( "RunDefinition", "take_screenshot") image_folder = ConfigModule.get_config_value("sectionOne", "screen_capture_folder", temp_config) try: if not os.path.exists(image_folder): os.mkdir(image_folder) except: pass Method = screen_capture_type Driver = screen_capture_driver # Decide if screenshot should be captured if (take_screenshot_settings.lower() == "false" or Method == "none" or Method is None): ExecLog( sModuleInfo, "Skipping screenshot due to screenshot or local_run setting", 0) return ExecLog( "", "********** Capturing Screenshot for Action: %s Method: %s **********" % (function_name, Method), 4, ) image_name = "Step#" + current_step_no + "_Action#" + current_action_no + "_" + str( function_name) thread = executor.submit(Thread_ScreenShot, function_name, image_folder, Method, Driver, image_name) SaveThread("screenshot", thread) except: return Exception_Handler(sys.exc_info())
def zeuz_authentication_prompts_for_cli(): prompts = ["server_address", "api-key"] values = [] for prompt in prompts: if prompt == "password": value = getpass() ConfigModule.add_config_value(AUTHENTICATION_TAG, prompt, password_hash(False, "zeuz", value)) else: display_text = prompt.replace("_", " ").capitalize() value = input(f"{display_text}: ") if prompt == "server_address": if value[-1] == "/": value = value[:-1] ConfigModule.add_config_value(AUTHENTICATION_TAG, prompt, str(value)) values.append(value) return values
def check_offline(): """ Checks the value set in the temp config file to tell sequential actions to exit, if set to true """ # Set by the user via the GUI value = ConfigModule.get_config_value("sectionOne", "exit_script", temp_config) if value == "True": return True else: return False
def Local_run(log_dir=None): try: PreProcess(log_dir=log_dir) user_info_object = {} user_info_object['project'] = ConfigModule.get_config_value( "sectionOne", PROJECT_TAG, temp_ini_file) user_info_object['team'] = ConfigModule.get_config_value( "sectionOne", TEAM_TAG, temp_ini_file) device_dict = All_Device_Info.get_all_connected_device_info() rem_config = {"local_run": True} ConfigModule.remote_config = rem_config MainDriverApi.main(device_dict, user_info_object) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] Error_Detail = ((str(exc_type).replace("type ", "Error Type: ")) + ";" + "Error Message: " + str(exc_obj) + ";" + "File Name: " + fname + ";" + "Line: " + str(exc_tb.tb_lineno)) CommonUtil.ExecLog("", Error_Detail, 4, False)
def update(): try: path = ChromeDriverManager().install() print("Downloaded Chrome driver into:", path) ConfigModule.add_config_value("Selenium_driver_paths", "chrome_path", path, location) except: print(sys.exc_info()) try: path = GeckoDriverManager().install() print("Downloaded Firefox driver into:", path) ConfigModule.add_config_value("Selenium_driver_paths", "firefox_path", path, location) except: print(sys.exc_info()) try: path = EdgeChromiumDriverManager().install() print("Downloaded Edge driver into:", path) ConfigModule.add_config_value("Selenium_driver_paths", "edge_path", path, location) except: print(sys.exc_info()) try: path = OperaDriverManager().install() print("Downloaded Opera driver into:", path) ConfigModule.add_config_value("Selenium_driver_paths", "opera_path", path, location) except: print(sys.exc_info()) try: path = IEDriverManager().install() print("Downloaded Internet Explorer driver into:", path) ConfigModule.add_config_value("Selenium_driver_paths", "ie_path", path, location) except: print(sys.exc_info())
def setLocalUser(self, custom_id): """ Set node_id from node_cli Command Line Interface and returns local userid """ try: node_id_file_path = Path( os.path.abspath(__file__).split("Framework") [0]) / "node_id.conf" if os.path.isfile(node_id_file_path): ConfigModule.clean_config_file(node_id_file_path) ConfigModule.add_section("UniqueID", node_id_file_path) custom_id = custom_id.lower()[:10] ConfigModule.add_config_value("UniqueID", "id", custom_id, node_id_file_path) else: f = open(node_id_file_path, "w") f.close() ConfigModule.add_section("UniqueID", node_id_file_path) custom_id = custom_id.lower()[:10] ConfigModule.add_config_value("UniqueID", "id", custom_id, node_id_file_path) except Exception: ErrorMessage = "Unable to set create a Node key. Please check class MachineInfo() in commonutil" return Exception_Handler(sys.exc_info(), None, ErrorMessage)
def Add_File_To_Current_Test_Case_Log(src): try: # get the current test case locations dest_folder = ConfigModule.get_config_value("sectionOne", "test_case_folder", temp_config) file_name = [x for x in src.split("/") if x != ""][-1] if file_name: des_path = os.path.join(dest_folder, file_name) FL.copy_file(src, des_path) return True else: return False except Exception as e: return Exception_Handler(sys.exc_info())
def command_line_args() -> Path: """ This function handles command line scripts with given arguments. Returns: `log_dir` - the custom log directory if specified, otherwise `None`. Example 1: 1. python node_cli.py 2. node_cli.py These 2 scripts will skip all kind of actions in this function because they dont have any arguments and will execute Login(CLI=true) from __main__ Example 2: 1. python node_cli.py --logout 2. node_cli.py --logout 3. node_cli.py -l These 3 scripts will will execute logout from server and then will execute Login(CLI=true) from __main__ then you have to provide server, username, password one by one in the terminal to login Example 3: 1. python node_cli.py --username USER_NAME --password PASS_XYZ --server https://zeuz.zeuz.ai 2. node_cli.py --logout --username USER_NAME --password PASS_XYZ --server https://zeuz.zeuz.ai 3. node_cli.py -u USER_NAME -p PASS_XYZ -s https://zeuz.zeuz.ai 4. python node_cli.py -k YOUR_API_KEY --server https://zeuz.zeuz.ai These 3 scripts will will execute logout from server and then will execute Login(CLI=true) from __main__ but you don't need to provide server, username, password again. It will execute the login process automatically for you Example 3: 1. python node_cli.py --help 2. node_cli.py --help 3. node_cli.py -h These 3 scripts will show the documentation for every arguments and will execute sys.exit() Example 4: 1. python node_cli.py --ussssername USER_NAME --password PASS_XYZ --server https://zeuz.zeuz.ai 2. node_cli.py --u USER_NAME -p PASS_XYZ -s 3. node_cli.py --logout https://zeuz.zeuz.ai Above are some invalid arguments which will show some log/documentation and will execute sys.exit() """ # try: parser_object = argparse.ArgumentParser("node_cli parser") parser_object.add_argument("-u", "--username", action="store", help="Enter your username", metavar="") parser_object.add_argument("-p", "--password", action="store", help="Enter your password", metavar="") parser_object.add_argument("-s", "--server", action="store", help="Enter server address", metavar="") parser_object.add_argument("-k", "--api_key", action="store", help="Enter api key", metavar="") parser_object.add_argument("-n", "--node_id", action="store", help="Enter custom node_id", metavar="") parser_object.add_argument( "-m", "--max_run_history", action="store", help="How many latest histories do you want to keep", metavar="") parser_object.add_argument("-l", "--logout", action="store_true", help="Logout from the server") parser_object.add_argument("-a", "--auto_update", action="store_true", help="Updates your Zeuz Node") parser_object.add_argument("-r", "--local_run", action="store_true", help="Performs a local run") parser_object.add_argument( "-o", "--once", action="store_true", help= "If specified, this flag tells node to run only one session (test set/deployment) and then quit immediately" ) parser_object.add_argument( "-d", "--log_dir", action="store", help="Specify a custom directory for storing Run IDs and logs.", metavar="") all_arguments = parser_object.parse_args() username = all_arguments.username password = all_arguments.password server = all_arguments.server api = all_arguments.api_key node_id = all_arguments.node_id max_run_history = all_arguments.max_run_history logout = all_arguments.logout auto_update = all_arguments.auto_update # Check if custom log directory exists, if not, we'll try to create it. If # we can't create the custom log directory, we should error out. log_dir = None try: if all_arguments.log_dir: log_dir = Path(all_arguments.log_dir.strip()) log_dir.mkdir(parents=True, exist_ok=True) # Try creating a temporary file to see if we have enough permissions # to write in the specified log directory. touch_file = log_dir / "touch" touch_file.touch() touch_file.unlink() except PermissionError: raise Exception( f"ERR: Zeuz Node does not have enough permissions to write to the specified log directory: {log_dir}" ) except: raise Exception( f"ERR: Invalid custom log directory, or failed to create directory: {log_dir}" ) global local_run local_run = all_arguments.local_run global RUN_ONCE RUN_ONCE = all_arguments.once if server and server[-1] == "/": server = server[:-1] if auto_update: check_for_updates() if username or password or server or logout or api: if api and server: ConfigModule.remove_config_value(AUTHENTICATION_TAG, "api-key") ConfigModule.add_config_value(AUTHENTICATION_TAG, "api-key", api) ConfigModule.remove_config_value(AUTHENTICATION_TAG, "server_address") ConfigModule.add_config_value(AUTHENTICATION_TAG, "server_address", server) elif username and password and server: ConfigModule.remove_config_value(AUTHENTICATION_TAG, "server_address") ConfigModule.add_config_value(AUTHENTICATION_TAG, "username", username) ConfigModule.add_config_value( AUTHENTICATION_TAG, "password", password_hash(False, "zeuz", password)) ConfigModule.add_config_value(AUTHENTICATION_TAG, "server_address", server) elif logout: ConfigModule.remove_config_value(AUTHENTICATION_TAG, "server_address") zeuz_authentication_prompts_for_cli() else: CommonUtil.ExecLog( "AUTHENTICATION FAILED", "Enter the command line arguments in correct format. Type -h for help.", 3, ) sys.exit() # exit and let the user try again from command line if node_id: CommonUtil.MachineInfo().setLocalUser(node_id) if max_run_history: pass """argparse module automatically shows exceptions of corresponding wrong arguments and executes sys.exit(). So we don't need to use try except""" # except: # CommonUtil.ExecLog("\ncommand_line_args : node_cli.py","Did not parse anything from given arguments",4) # sys.exit() return log_dir
def CreateJsonReport(logs=None, stepInfo=None, TCInfo=None, setInfo=None): try: if debug_status: return elif upload_on_fail and rerun_on_fail and not rerunning_on_fail and logs: return global all_logs_json, report_json_time, tc_error_logs, passed_after_rerun start = time.perf_counter() if logs or stepInfo or TCInfo or setInfo: log_id = ConfigModule.get_config_value("sectionOne", "sTestStepExecLogId", temp_config) if not log_id: return log_id_vals = log_id.split("|") if logs: log_id, now, iLogLevel, status, sModuleInfo, sDetails = logs if len(log_id_vals) == 4: # these loops can be optimized by saving the previous log_id_vals and comparing it with current one runID, testcase_no, step_id, step_no = log_id_vals run_id_info = all_logs_json[runid_index] if setInfo: run_id_info["execution_detail"] = setInfo return all_testcases_info = run_id_info["test_cases"] testcase_info = all_testcases_info[tc_index] if TCInfo: testcase_info["execution_detail"] = TCInfo fail_reason_str = "" if TCInfo["status"] in ("Failed", "Blocked"): count = -min(len(tc_error_logs), 3) while count <= -1: fail_reason_str += tc_error_logs[count] if count != -1: fail_reason_str += "\n---------------------------------------------\n" count += 1 elif passed_after_rerun: fail_reason_str = "** Test case Failed on first run but Passed when Rerun **" passed_after_rerun = False testcase_info["execution_detail"][ "failreason"] = fail_reason_str return if step_id == "none": return all_step_info = testcase_info["steps"] step_info = all_step_info[step_index] if stepInfo: step_info["execution_detail"] = stepInfo step_error_logs = [] if stepInfo["status"].lower( ) == "failed" and "log" in step_info: count, err_count, max_count = -1, 0, -len( step_info["log"]) # Can be optimized by taking error when occurs and append it if the step fails only while count >= max_count and err_count < 3: each_log = step_info["log"][count] if each_log["status"].lower() == "error": step_error_logs.append(each_log["details"]) err_count += 1 count -= 1 step_error_logs.reverse() tc_error_logs += step_error_logs return log_info = { "status": status, "modulename": sModuleInfo, "details": sDetails, "tstamp": now, "loglevel": iLogLevel, "logid": log_id } if "log" in step_info: step_info["log"].append(log_info) else: step_info["log"] = [log_info] elif stepInfo: pass report_json_time += (time.perf_counter() - start) except: debug_code_error(sys.exc_info())
def ExecLog(sModuleInfo, sDetails, iLogLevel=1, _local_run="", sStatus="", force_write=False, variable=None): # Do not log anything if load testing is going on and we're not forced to write logs if load_testing and not force_write: return if not print_execlog: return # For bypass_bug() function dont print logs # Read from settings file debug_mode = ConfigModule.get_config_value("RunDefinition", "debug_mode") # ";" is not supported for logging. So replacing them sDetails = sDetails.replace(";", ":").replace("%22", "'") # Terminal output color line_color = "" # Convert logLevel from int to string for clarity if iLogLevel == 0: if debug_mode.lower() == "true": status = ( "Debug" # This is not displayed on the server log, just in the console ) else: # Do not display this log line anywhere return elif iLogLevel == 1: status = "Passed" line_color = Fore.GREEN elif iLogLevel == 2: status = "Warning" line_color = Fore.YELLOW elif iLogLevel == 3: status = "Error" line_color = Fore.RED elif iLogLevel == 4: status = "Console" elif iLogLevel == 5: status = "Info" iLogLevel = 1 line_color = Fore.CYAN elif iLogLevel == 6: status = "BrowserConsole" else: print("*** Unknown log level - Set to Info ***") status = "Info" iLogLevel = 5 line_color = Fore.CYAN if not sModuleInfo: sModuleInfo = "" info = "" else: info = f"{sModuleInfo}\t\n" # Display on console # Change the format for console, mainly leave out the status level if "saved variable" not in sDetails.lower(): if status == "Console": msg = f"{info}{sDetails}" if sModuleInfo else sDetails print(line_color + msg) else: print(line_color + f"{status.upper()} - {info}{sDetails}") current_log_line = f"{status.upper()} - {sModuleInfo} - {sDetails}" global previous_log_line # Skip duplicate logs if previous_log_line and previous_log_line.strip( ) == current_log_line.strip(): return # Set current log as the next previous log previous_log_line = current_log_line ws.log(sModuleInfo, iLogLevel, sDetails) if iLogLevel > 0: if iLogLevel == 6: FWLogFolder = ConfigModule.get_config_value( "sectionOne", "log_folder", temp_config) if os.path.exists(FWLogFolder) == False: FL.CreateFolder(FWLogFolder) # Create log directory if missing if FWLogFolder == "": BrowserConsoleLogFile = (ConfigModule.get_config_value( "sectionOne", "temp_run_file_path", temp_config) + os.sep + "BrowserLog.log") else: BrowserConsoleLogFile = FWLogFolder + os.sep + "BrowserLog.log" logger = logging.getLogger(__name__) browser_log_handler = None if os.name == "posix": try: browser_log_handler = logging.FileHandler( BrowserConsoleLogFile) except: pass elif os.name == "nt": browser_log_handler = logging.FileHandler( BrowserConsoleLogFile) formatter = logging.Formatter( "%(asctime)s - %(levelname)s - %(message)s") if browser_log_handler: browser_log_handler.setFormatter(formatter) logger.addHandler(browser_log_handler) logger.setLevel(logging.DEBUG) logger.info(sModuleInfo + " - " + sDetails + "" + sStatus) logger.removeHandler(browser_log_handler) else: # Except the browser logs global all_logs, all_logs_count, all_logs_list log_id = ConfigModule.get_config_value("sectionOne", "sTestStepExecLogId", temp_config) if not log_id: return now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") if variable and variable["key"] not in skip_list: sDetails = "%s\nVariable value: %s" % (sDetails, variable["val"]) if upload_on_fail and rerun_on_fail and not rerunning_on_fail: pass else: CreateJsonReport(logs=(log_id, now, iLogLevel, status, sModuleInfo, sDetails)) all_logs[all_logs_count] = { "logid": log_id, "modulename": sModuleInfo, "details": sDetails, "status": status, "loglevel": iLogLevel, "tstamp": str(now), } if len(all_logs_list) >= 1: # start logging to the log file instead of logging to the server try: # filepath = Path(ConfigModule.get_config_value('sectionOne', 'log_folder', temp_config)) / 'execution.log' filepath = (Path( ConfigModule.get_config_value( "sectionOne", "temp_run_file_path", temp_config)) / "execution.log") with open(filepath, "a+") as f: print("[%s] %s" % (now, current_log_line), file=f) except FileNotFoundError: pass # log warnings and errors if iLogLevel in (2, 3) or len(all_logs_list) < 1: # log to server in case of logs less than 2k all_logs_count += 1 if all_logs_count > 2000: all_logs_list.append(all_logs) all_logs_count = 0 all_logs = {}
def update_machine(dependency, default_team_and_project_dict): try: # Get Local Info object oLocalInfo = CommonUtil.MachineInfo() local_ip = oLocalInfo.getLocalIP() testerid = (oLocalInfo.getLocalUser()).lower() project = default_team_and_project_dict["project_name"] team = default_team_and_project_dict["team_name"] if not dependency: dependency = "" _d = {} for x in dependency: t = [] for i in x[1]: _t = ["name", "bit", "version"] __t = {} for index, _i in enumerate(i): __t.update({_t[index]: _i}) if __t: t.append(__t) _d.update({x[0]: t}) dependency = _d available_to_all_project = ConfigModule.get_config_value( "Advanced Options", "available_to_all_project") allProject = "no" if str(available_to_all_project).lower() == "true": allProject = "yes" update_object = { "machine_name": testerid, "local_ip": local_ip, "dependency": dependency, "project": project, "team": team, "device": device_dict, "allProject": allProject, } r = RequestFormatter.Get("update_automation_machine_api", update_object) if r["registered"]: CommonUtil.ExecLog( "", "Zeuz Node is online: %s" % (r["name"]), 4, False, ) else: if r["license"]: CommonUtil.ExecLog("", "Machine is not registered as online", 4, False) else: if "message" in r: CommonUtil.ExecLog("", r["message"], 4, False) CommonUtil.ExecLog("", "Machine is not registered as online", 4, False) else: CommonUtil.ExecLog("", "Machine is not registered as online", 4, False) return r except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] Error_Detail = ((str(exc_type).replace("type ", "Error Type: ")) + ";" + "Error Message: " + str(exc_obj) + ";" + "File Name: " + fname + ";" + "Line: " + str(exc_tb.tb_lineno)) CommonUtil.ExecLog("", Error_Detail, 4, False)
def PreProcess(log_dir=None): current_path_file = temp_ini_file ConfigModule.clean_config_file(current_path_file) ConfigModule.add_section("sectionOne", current_path_file) if not ConfigModule.has_section("Selenium_driver_paths"): ConfigModule.add_section("Selenium_driver_paths") ConfigModule.add_config_value("Selenium_driver_paths", "chrome_path", "") ConfigModule.add_config_value("Selenium_driver_paths", "firefox_path", "") ConfigModule.add_config_value("Selenium_driver_paths", "edge_path", "") ConfigModule.add_config_value("Selenium_driver_paths", "opera_path", "") ConfigModule.add_config_value("Selenium_driver_paths", "ie_path", "") if not ConfigModule.get_config_value("Selenium_driver_paths", "electron_chrome_path"): ConfigModule.add_config_value("Selenium_driver_paths", "electron_chrome_path", "") # If `log_dir` is not specified, then store all logs inside Zeuz Node's # "AutomationLog" folder if log_dir is None: log_dir = temp_ini_file.parent ConfigModule.add_config_value( "sectionOne", "temp_run_file_path", str(log_dir), current_path_file, ) ConfigModule.add_config_value("sectionOne", "sTestStepExecLogId", "node_cli", temp_ini_file)
def Login(cli=False, run_once=False, log_dir=None): username = ConfigModule.get_config_value(AUTHENTICATION_TAG, USERNAME_TAG) password = ConfigModule.get_config_value(AUTHENTICATION_TAG, PASSWORD_TAG) server_name = ConfigModule.get_config_value(AUTHENTICATION_TAG, "server_address") api = ConfigModule.get_config_value(AUTHENTICATION_TAG, "api-key") api_flag = True if not api or not server_name: zeuz_authentication_prompts_for_cli() for i in range( 30): # it takes time to save in the file. so lets wait 15 sec time.sleep(0.5) api = ConfigModule.get_config_value(AUTHENTICATION_TAG, "api-key") server_name = ConfigModule.get_config_value( AUTHENTICATION_TAG, "server_address") if api and server_name: break while api and server_name: url = '/api/auth/token/verify?api_key=%s' % (api) r = RequestFormatter.Get(url) if r: try: token = r['token'] res = RequestFormatter.Get( "/api/user", headers={'Authorization': "Bearer %s" % token}) info = res[0] username = info['username'] api_flag = False ConfigModule.add_config_value(AUTHENTICATION_TAG, "username", username) break except: print("Incorrect API key...") server_name, api = zeuz_authentication_prompts_for_cli() continue else: print("Server down. Trying again after 30 seconds") time.sleep(30) if password == "YourUserNameGoesHere": password = password else: password = pass_decode("zeuz", password) # form payload object user_info_object = { "username": username, "password": password, "project": "", "team": "", } # Iniitalize GUI Offline call CommonUtil.set_exit_mode(False) global exit_script global processing_test_case exit_script = False # Reset exit variable while True: if exit_script: break # if not user_info_object["username"] or not user_info_object["password"]: # break # Test to ensure server is up before attempting to login r = check_server_online() # Login to server if r: # Server is up try: default_team_and_project = RequestFormatter.UpdatedGet( "get_default_team_and_project_api", {"username": username}) if not default_team_and_project: CommonUtil.ExecLog( "AUTH FAILED", "Failed to get TEAM and PROJECT information. Incorrect username or password.", 3, False, ) break user_info_object["project"] = default_team_and_project[ "project_name"] user_info_object["team"] = default_team_and_project[ "team_name"] CommonUtil.ExecLog("", f"Authenticating user: {username}", 4, False) if api_flag: r = RequestFormatter.Post("login_api", user_info_object) if r or (isinstance(r, dict) and r['status'] == 200): CommonUtil.ExecLog( "", f"Authentication successful: USER='******', " f"PROJECT='{user_info_object['project']}', TEAM='{user_info_object['team']}', SERVER='{server_name}'", 4) ConfigModule.add_config_value("sectionOne", PROJECT_TAG, user_info_object['project'], temp_ini_file) ConfigModule.add_config_value("sectionOne", TEAM_TAG, user_info_object['team'], temp_ini_file) global device_dict device_dict = All_Device_Info.get_all_connected_device_info( ) machine_object = update_machine( dependency_collection(default_team_and_project), default_team_and_project, ) if machine_object["registered"]: tester_id = machine_object["name"] try: # send machine's time zone local_tz = str(get_localzone()) time_zone_object = { "time_zone": local_tz, "machine": tester_id, } executor = CommonUtil.GetExecutor() executor.submit(RequestFormatter.Get, "send_machine_time_zone_api", time_zone_object) # RequestFormatter.Get("send_machine_time_zone_api", time_zone_object) # end except Exception as e: CommonUtil.ExecLog( "", "Time zone settings failed {}".format(e), 4, False) # Telling the node_manager that the node is ready to deploy CommonUtil.node_manager_json({ "state": "idle", "report": { "zip": None, "directory": None, } }) run_again = RunProcess(tester_id, user_info_object, run_once=run_once, log_dir=log_dir) if not run_again: break # Exit login else: return False elif not r: # Server should send "False" when user/pass is wrong CommonUtil.ExecLog( "", f"Authentication Failed. Username or password incorrect. SERVER='{server_name}'", 4, False, ) if cli: zeuz_authentication_prompts_for_cli() Login(cli=True) break else: # Server likely sent nothing back or RequestFormatter.Get() caught an exception CommonUtil.ExecLog( "", "Login attempt failed, retrying in 60 seconds...", 4, False, ) if cli: zeuz_authentication_prompts_for_cli() Login(cli=True) time.sleep(60) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] Error_Detail = ( (str(exc_type).replace("type ", "Error Type: ")) + ";" + "Error Message: " + str(exc_obj) + ";" + "File Name: " + fname + ";" + "Line: " + str(exc_tb.tb_lineno)) CommonUtil.ExecLog("", Error_Detail, 4, False) CommonUtil.ExecLog( "", "Error logging in, waiting 60 seconds before trying again", 4, False, ) time.sleep(60) # Server down, wait and retry else: CommonUtil.ExecLog( "", "Server down or verify the server address, waiting 60 seconds before trying again", 4, False, ) # if cli: # zeuz_authentication_prompts_for_cli() # Login(cli=True) time.sleep(60) if run_once: print( "[OFFLINE]", "Zeuz Node is going offline after running one session, since `--once` or `-o` flag is specified." ) else: CommonUtil.ExecLog( "[OFFLINE]", "Zeuz Node Offline", 3 ) # GUI relies on this exact text. GUI must be updated if this is changed processing_test_case = False
def set_exit_mode(emode): """ Sets a value in the temp config file to tell sequential actions to exit, if set to true """ # Set by the user via the GUI ConfigModule.add_config_value("sectionOne", "exit_script", str(emode), temp_config)
)) # Tells node whether it should run a test set/deployment only once and quit. RUN_ONCE = False local_run = False # Move to Framework directory, so all modules can be seen os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Framework")) sys.path.append("..") from Framework.Utilities import (RequestFormatter, CommonUtil, FileUtilities as FL, All_Device_Info, self_updater) from Framework import MainDriverApi temp_ini_file = (Path(PROJECT_ROOT) / "AutomationLog" / ConfigModule.get_config_value("Advanced Options", "_file")) import subprocess def signal_handler(sig, frame): CommonUtil.run_cancelled = True print("Disconnecting from server...") disconnect_from_server() sys.exit(0) def password_hash(encrypt, key, pw): """ Encrypt, decrypt password and encode in plaintext """ # This is just an obfuscation technique, so the password is not immediately seen by users # Zeuz_Node.py has a similar function that will need to be updated if this is changed
def getUniqueId(self): """ This function is not used any more :return: returns the local pc unique ID """ try: node_id_file_path = Path( os.path.abspath(__file__).split("Framework")[0]) / Path( "node_id.conf") if os.path.isfile(node_id_file_path): unique_id = ConfigModule.get_config_value( "UniqueID", "id", node_id_file_path) if unique_id == "": ConfigModule.clean_config_file(node_id_file_path) ConfigModule.add_section("UniqueID", node_id_file_path) unique_id = uuid.uuid4() unique_id = str(unique_id)[:10] ConfigModule.add_config_value("UniqueID", "id", unique_id, node_id_file_path) machine_name = str(unique_id) return machine_name[:100] machine_name = str(unique_id) else: # create the file name f = open(node_id_file_path, "w") f.close() unique_id = uuid.uuid4() unique_id = str(unique_id)[:10] ConfigModule.add_section("UniqueID", node_id_file_path) ConfigModule.add_config_value("UniqueID", "id", unique_id, node_id_file_path) machine_name = str(unique_id) return machine_name[:100] except Exception: ErrorMessage = "Unable to set create a Node key. Please check class MachineInfo() in commonutil" return Exception_Handler(sys.exc_info(), None, ErrorMessage)
def getLocalUser(self): """ :return: returns the local pc name """ try: # node_id_file_path = os.path.join(FL.get_home_folder(), os.path.join('Desktop', 'node_id.conf')) # node_id_file_path = os.path.join (os.path.realpath(__file__).split("Framework")[0] , os.path.join ('node_id.conf')) node_id_file_path = Path( os.path.abspath(__file__).split("Framework")[0]) / Path( "node_id.conf") if os.path.isfile(node_id_file_path): unique_id = ConfigModule.get_config_value( "UniqueID", "id", node_id_file_path) if unique_id == "": ConfigModule.clean_config_file(node_id_file_path) ConfigModule.add_section("UniqueID", node_id_file_path) unique_id = uuid.uuid4() unique_id = str(unique_id)[:10] ConfigModule.add_config_value("UniqueID", "id", unique_id, node_id_file_path) machine_name = (ConfigModule.get_config_value( "Authentication", "username") + "_" + str(unique_id)) return machine_name[:100] machine_name = (ConfigModule.get_config_value( "Authentication", "username") + "_" + str(unique_id)) else: # create the file name f = open(node_id_file_path, "w") f.close() unique_id = uuid.uuid4() unique_id = str(unique_id).lower()[:10] ConfigModule.add_section("UniqueID", node_id_file_path) ConfigModule.add_config_value("UniqueID", "id", unique_id, node_id_file_path) machine_name = (ConfigModule.get_config_value( "Authentication", "username") + "_" + str(unique_id)) return machine_name[:100] except Exception: ErrorMessage = "Unable to set create a Node key. Please check class MachineInfo() in commonutil" return Exception_Handler(sys.exc_info(), None, ErrorMessage)