def create_vdi_rdp(self, step_No): for _ in range(6): self.user = vdi_connection.MultiUserManger().get_a_available_key() if self.user: break time.sleep(180) self.log.info('user: {}'.format(self.user)) for _ in range(6): self.rdp_server = vdi_connection.MultiUserManger( ).get_a_available_key('rdp win10') if self.rdp_server: break time.sleep(180) self.log.info('rdp_server: {}'.format(self.rdp_server)) setting_file = os.path.join(self.path, "Test_Data", "td_common", "thinpro_registry.yml") setting_rdp = YamlOperator(setting_file).read()["set"]["RDP"] if step_No == 'step1&2': setting = setting_rdp["screen_lock_with_password_step2"] elif step_No == 'step3&4': setting = setting_rdp["screen_lock_with_password_step3"] else: setting = '{}' self.vdi = vdi_connection.RDPLinux(user=self.user, setting=setting, rdp_server=self.rdp_server) return self.vdi, self.user, self.rdp_server
def start(case_name, **kwargs): try: log.info('Begin to start test {}'.format(case_name)) user_manager = vdi_connection.MultiUserManger() user = user_manager.get_a_available_key() rdp_server = user_manager.get_a_available_key('rdp win10') conn = vdi_connection.RDPLinux(user=user, rdp_server=rdp_server) log.info('user: {}, rdp_server: {}'.format(user, rdp_server)) report_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) common_function.new_cases_result(report_file, case_name) common_function.case_steps_run_control(steps_list, __name__, case_name=case_name, log=log, report_file=report_file, user=user, rdp_server=rdp_server, conn=conn, user_manager=user_manager) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) picture_operator.capture_screen(error_pic) reset_all_settings(num=0) return False
def create_vdi_view(self, step_No): for _ in range(6): self.user = vdi_connection.MultiUserManger().get_a_available_key() if self.user: break time.sleep(30) self.log.info('user: {}'.format(self.user)) setting_file = os.path.join(self.path, "Test_Data", "td_common", "thinpro_registry.yml") setting_view = YamlOperator(setting_file).read()["set"]["view"] if step_No == 'step1&2': setting = setting_view["screen_lock_with_password_step2"] self.parameters = {'vdi': 'view', 'session': 'blast win10'} elif step_No == 'step3&4': setting = setting_view["screen_lock_with_password_step3"] self.parameters = {'vdi': 'view', 'session': 'blast win10'} else: setting = '{}' self.parameters = {'vdi': 'view', 'session': 'blast win10'} self.vdi = vdi_connection.ViewLinux(user=self.user, setting=setting, parameters=self.parameters) return self.vdi, self.user
def start(case_name=case_names[0], **kwargs): global user, rdp_server wait_time = 30 time_path = common_function.get_current_dir("time_temp.txt") log.info("Start Wait {}".format(wait_time)) if os.path.exists(time_path): with open(time_path, "r") as f: now_time = f.read() else: with open(time_path, "w") as f: now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) f.write(now_time) current_time = time.time() before_time = time.mktime(time.strptime(now_time, "%Y-%m-%d %H:%M:%S")) if current_time - before_time > 3600: os.remove(time_path) common_function.reboot_command() common_function.SwitchThinProMode("user") query_list = ["xen", 'freerdp', "view", "firefox"] shadow_dict = {} for i in query_list: d = vdi_connection.query_item_id(i) shadow_dict.update(d) vdi_connection.hide_desktop_icon(id_dict=shadow_dict) common_function.cache_collection(3) case_name = case_name.lower() result_file = os.path.join(common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) user_manager = vdi_connection.MultiUserManger() performance = Performance.get_system_obj() test_data = os.path.join(common_function.get_current_dir(), 'Test_Data') # --------------- pre define -------------------------- log.info('Begin to start test {}'.format(case_name)) common_function.new_cases_result(result_file, case_name) pic_name = generate_pic_name(case_name) local_pic_name = generate_local_name(case_name) parameters = display_function.analyze_name(case_name) parameters = display_function.check_resolution_support(parameters) log.info('analyze parameter from case name') # display_function.LinuxTools().generate_profile(parameters['layout'], parameters['monitors']) display_function.set_display_profile(parameters) log.info('generate xml file') log.info('set local resolution, Wait 20s for background refresh') display_function.LinuxTools().set_local_resolution() log.debug("check local resolution set success") if not set_resolution_success() and common_function.need_reboot() != -1: common_function.change_reboot_status(-1) common_function.reboot_command() common_function.change_reboot_status(0) display_function.set_background() log.info('set local background success') flag, first_collect_flag = local_start(case_name, result_file, test_data, local_pic_name) if not flag: return False # check fresh rate----------------------------------------------- check_fresh_rate(case_name, result_file, parameters) # check fresh rate end------------------------------------------- user = user_manager.get_a_available_key() log.info('get valid user : {}'.format(user)) remote_collect_flag = False try: flag, remote_collect_flag = remote_start(case_name, result_file, test_data, pic_name, user_manager, parameters, performance) except: debug_path = common_function.get_current_dir("Test_Report/debug.log") with open(debug_path, "a") as f: traceback.print_exc(file=f) traceback.print_exc() steps = { 'step_name': 'case exception', 'result': 'Fail', 'expect': '', # can be string or pic path 'actual': 'img/{}.jpg'.format(case_name), 'note': traceback.format_exc()} common_function.update_cases_result(result_file, case_name, steps) finally: log.info('try to reset user') if user: user_manager.reset_key(user) if parameters['vdi'].upper() == 'RDP' and rdp_server: user_manager.reset_key(rdp_server, key=session.lower()) if first_collect_flag or remote_collect_flag: steps = { 'step_name': "Cannot find template PIC", 'result': 'Fail', 'expect': '', # can be string or pic path 'actual': '', 'note': 'This case has no pic in library'} common_function.update_cases_result(result_file, case_name, steps) log.debug(gc.garbage) gc.collect()
def reset_key(self, user, key): self.log.info('start reset user: {}'.format(user)) vdi_connection.MultiUserManger().reset_key(user, key)
def step_2(**kwargs): log = kwargs.get("log") case_name = kwargs.get("case_name") try: pmcf.SwitchThinProMode("user") multiuser = vdi_connection.MultiUserManger() for _ in range(6): user = multiuser.get_a_available_key() if user: break time.sleep(180) else: log.error("not get a valid user") return [False, "not has invalid user"] parameters = {'vdi': 'citrix', 'session': 'win10'} citrix = vdi_connection.CitrixLinux( user=user, setting=vdi_setting()["set"]["citrix"] ["screen_lock_with_password_step2"], parameters=parameters) for _ in range(2): if citrix.logon(parameters.get("session", "")): for _ in range(10): time.sleep(10) if wait_element(pic("_win10_start_icon")): break else: log.debug( "log on vdi fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) citrix.logoff() time.sleep(5) continue break else: log.debug( "log on vdi fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) os.system("wmctrl -c 'Citrix Workspace'") multiuser.reset_key(user) return [False, "log on vdi fail"] log.info("logon vdi success") screensaver = ScreenSaver() screensaver.lock_screen_by_hotkey() log.info("lock screen") time.sleep(2) pyautogui.click() time.sleep(2) if wait_element(pic("_lock_screen_dialog")): log.error("found lock screen dialog") citrix.logoff() multiuser.reset_key(user) return [False, "found lock screen dialog"] if wait_element(pic("_win10_start_icon")): log.info("unlock screen success") citrix.logoff() multiuser.reset_key(user) return [True, "unlock screen success"] log.error("unlock screen fail") citrix.logoff() multiuser.reset_key(user) return [False, "unlock screen fail"] except: log.error(traceback.format_exc()) return [False, traceback.format_exc()]
def step_9(**kwargs): log = kwargs.get("log") case_name = kwargs.get("case_name") user_password = kwargs.get("user_password", "1") try: pmcf.SwitchThinProMode("user") multiuser = vdi_connection.MultiUserManger() for _ in range(6): user = multiuser.get_a_available_key() if user: break time.sleep(180) else: log.error("not get a valid user") return [False, "not has invalid user"] parameters = {'vdi': 'citrix', 'session': 'win10'} vdi = vdi_connection.CitrixLinux(user=user, setting=vdi_setting()["set"]["citrix"] ["screen_lock_with_password_step3"], parameters=parameters) for _ in range(2): if vdi.logon(parameters.get("session", "")): for _ in range(10): time.sleep(10) if wait_element(pic("_win10_start_icon")): break else: log.debug( "log on vdi fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) vdi.logoff() time.sleep(5) continue break else: log.debug( "log on vdi fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) multiuser.reset_key(user) return [False, "log on vdi fail"] log.info("logon vdi success") log.info("start lock screen") screensaver = ScreenSaver() screensaver.lock_screen_by_hotkey() # lock screen time.sleep(2) pyautogui.click() if not wait_element(pic("_user_of_credentials")): log.error("'user' not in credentials list") vdi.logoff() multiuser.reset_key(user) return [False, "'user' not in credentials list"] log.info("'user' in credentials list") log.info("try use logon vdi password to unlock") pyautogui.typewrite(vdi_user_info()["password"], interval=0.1) time.sleep(1) pyautogui.press("enter") time.sleep(1) if not wait_element(pic("_win10_start_icon")): log.error("unlock screen fail") vdi.logoff() multiuser.reset_key(user) return [False, "unlock screen fail"] log.info("unlock screen success") time.sleep(2) screensaver.lock_screen_by_hotkey() time.sleep(2) pyautogui.click() if not wait_element(pic("_user_of_credentials")): log.error("'user' not in credentials list") vdi.logoff() multiuser.reset_key(user) return [False, "'user' not in credentials list"] log.info("'user' in credentials list") log.info("try use 'user' to unlock") if wait_element(pic("_tool")): pyautogui.press("tab", presses=5, interval=0.3) else: pyautogui.press("tab", presses=9, interval=0.3) pyautogui.typewrite("user", interval=0.1) pyautogui.press("tab") time.sleep(1) pyautogui.typewrite(user_password, interval=0.1) time.sleep(1) pyautogui.press("enter") if not wait_element(pic("_win10_start_icon")): log.error("unlock screen fail") vdi.logoff() multiuser.reset_key(user) return [False, "'user' not in credentials list"] log.info("unlock screen success") log.info("start logoff vdi") vdi.logoff() multiuser.reset_key(user) return [True, "success"] except: log.error(traceback.format_exc()) return [False, traceback.format_exc()]
def step_5_6(**kwargs): log = kwargs.get("log") session = kwargs.get("session") case_name = kwargs.get('case_name') root_password = kwargs.get("root_password", "1") try: pmcf.SwitchThinProMode("user") multiuser = vdi_connection.MultiUserManger() for _ in range(6): user = multiuser.get_a_available_key() if user: break time.sleep(180) else: log.error("not get a valid user") return [False, "not has invalid user"] citrix = vdi_connection.CitrixLinux( user=user, setting=vdi_setting()["set"]["citrix"] ["screen_lock_with_password_step5"], parameters={ 'vdi': 'citrix', 'session': 'win10' }) if not citrix.import_cert(): log.error("thinpro import rootca certificate fail") multiuser.reset_key(user) return [False, "thinpro import rootca certificate fail"] citrix.delete_vdi('xen') citrix.create_vdi('xen') time.sleep(1) citrix_id = citrix.vdi_connection_id('xen')[0] citrix.set_citrix_connection_from_yml(citrix_id) log.info("connect citrix VDI desktop") time.sleep(1) # os.popen("connection-mgr start {}".format(citrix_id)) for _ in range(2): citrix.connect_vdi_by_pic() time.sleep(10) if not wait_element(pic("_citrix_input_credentials_dialog")): log.debug( "not open input credentials dialog", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) os.system("wmctrl -c 'HP - Citrix Server Error'") os.system("wmctrl -c 'Citrix Workspace'") time.sleep(5) continue log.info("input domain, user and password") pyautogui.typewrite(r"{}\{}".format(vdi_user_info()["domain"], user), interval=0.1) pyautogui.press("tab") pyautogui.typewrite(vdi_user_info()["password"], interval=0.1) pyautogui.press("enter") log.info(r"user: '******', password: '******'".format( vdi_user_info()["domain"], user, vdi_user_info()["password"])) time.sleep(20) if not wait_element(pic("_citrix_workspace_broker")): if wait_element(pic("_win10_start_icon") ): # check whether auto logon vdi desktop log.info("auto logon vdi desktop success") pyautogui.click(1, 1) break else: log.debug( "open citrix workspace broker fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) os.system("wmctrl -c 'HP - Citrix Server Error'") os.system("wmctrl -c 'Citrix Workspace'") time.sleep(5) continue else: log.info("open citrix workspace broker success") if not citrix.logon_desktop_by_pic(): log.debug( "desktops or target desktop not found", cf.get_current_dir('Test_Report', 'img', '{}.png'.format(case_name))) os.system("wmctrl -c 'HP - Citrix Server Error'") os.system("wmctrl -c 'Citrix Workspace'") time.sleep(5) continue for i in range(15): log.info("wait log on citrix desktop...") time.sleep(10) if wait_element(pic("_win10_start_icon")): log.info("login vdi connection success") break else: continue else: log.debug( "login vdi connection fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) os.system("wmctrl -c 'HP - Citrix Server Error'") os.system("wmctrl -c 'Citrix Workspace'") time.sleep(5) continue break else: os.system("wmctrl -c 'Citrix Workspace'") multiuser.reset_key(user) return [False, "login vdi connection fail"] time.sleep(5) screensaver = ScreenSaver() screensaver.lock_screen_by_hotkey() # lock screen time.sleep(2) pyautogui.press("enter") time.sleep(2) if not wait_element(pic("_lock_screen_dialog")): log.error("not found the lock screen dialog") citrix.logoff() multiuser.reset_key(user) return [False, "not found the lock screen dialog"] if wait_element(pic("_user_of_credentials") ): # user in the list of new credentials log.error("'user' in credentials dialog") citrix.logoff() multiuser.reset_key(user) return [False, "'user' in credentials dialog"] log.info("'user' not in credentials dialog") log.info("try use 'root' to unlock") if wait_element(pic("_tool")): pyautogui.press("tab", presses=5, interval=0.3) else: pyautogui.press("tab", presses=9, interval=0.3) pyautogui.typewrite("root", interval=0.1) pyautogui.press("tab") pyautogui.typewrite(root_password, interval=0.1) pyautogui.press("enter") time.sleep(2) if not wait_element(pic( "_invalid_credentials")): # check invalid credentials dialog log.error("not found invalid credentials dialog") citrix.logoff() multiuser.reset_key(user) return [False, "not found invalid credentials dialog"] pyautogui.press("enter") cancel = wait_element(pic("_cancel")) pyautogui.click(cancel[0]) time.sleep(1) pyautogui.press("enter") time.sleep(1) pyautogui.typewrite(vdi_user_info()["password"], interval=0.1) pyautogui.press("enter") time.sleep(2) if not wait_element(pic("_win10_start_icon")): log.error("into the vdi desktop fail") citrix.logoff() multiuser.reset_key(user) return [False, "into the vdi desktop fail"] log.info("into the vdi desktop success") log.info("screen can be unlock by the credentials") citrix.logoff() multiuser.reset_key(user) return [True, "screen can be unlock by the credentials"] except: log.info(traceback.format_exc()) return [False, traceback.format_exc()]
def reset_key(user, key): vdi_connection.MultiUserManger().reset_key(user, key)