def set_eth0_speed(ethernet_speed): try: cf.SwitchThinProMode("admin") wired = network_setting.Wired() wired.open_network_wired_dialog() wired.set_ethernet_speed(speed=ethernet_speed) wired.apply() log.info("close control panel") wired.close_control_panel() time.sleep(1) s = subprocess.getoutput( "mclient --quiet get root/Network/Wired/EthernetSpeed") if s == ethernet_speed: log.info( "set 'Ethernet Speed' is '{}' success".format(ethernet_speed)) return True else: log.error( "set 'Ethernet Speed' is '{}' fail".format(ethernet_speed)) return False except: log.error(traceback.format_exc()) pyautogui.screenshot( cf.get_current_dir( "Test_Report/check_speed_{}.png".format(ethernet_speed))) return False
def restore(): log.info("start restore test environment") wireless = network_setting.Wireless() wired = network_setting.Wired() wireless.close_control_panel() wireless.del_wireless_profile_from_reg() wireless.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0()
def pre_check(): wired = network_setting.Wired() wired_state = wired.check_wired_is_connected() if not wired_state: log.error("thinpro wired is not connected") del wired return False else: del wired return True
def reset_test_environment(): log.info("start reset test environment") wired = network_setting.Wired() os.system( "mclient --quiet set root/Network/Wired/EthernetSpeed 'Automatic'") os.system("mclient commit") wired.disable_eth0() time.sleep(2) wired.enable_eth0() for i in range(12): log.info("wait wired reconnect...") time.sleep(5) if wired.check_wired_is_connected(): log.info("wired is connected") break del wired
def userlock_is_1(**kwargs): report_file = kwargs.get("report_file") case_name = kwargs.get("case_name") hostname = get_default_hostname() log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) cf.SwitchThinProMode("admin") modify_hostname_registry("asdfgh") wired = network_setting.Wired() wired_connection_mode = subprocess.getoutput( "mclient --quiet get root/Network/Wired/Method") if wired_connection_mode is not "Automatic": subprocess.call( "mclient --quiet set root/Network/Wired/Method 'Automatic'", shell=True) subprocess.call("mclient commit", shell=True) for i in range(20): log.info("wait connect network...") time.sleep(2) if wired.check_wired_is_connected(): log.info("wired is connected") break set_userlock("1") export_profile() if not set_static_network(): log.error("set static network error") report = { 'step_name': 'set static network', 'result': 'fail', 'expect': "set static network success", 'actual': "set static network fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) teardown_test_environment() modify_hostname_registry(hostname) cf.import_profile() os.remove(cf.get_current_dir("Test_Data/profile_file.xml")) log.error("{:+^80}".format("test case fail")) return False import_profile() log.info("reboot") time.sleep(30)
def set_static_network(): try: log.info("start set static network") ip = cf.get_ip() if cf.get_ip() else "" log.info("ip: {}".format(ip)) wired = network_setting.Wired() network_mask = wired.get_mask("eth0") mask = network_mask if network_mask else "255.255.255.192" log.info("mask: {}".format(mask)) gateway = wired.gateway() if wired.gateway() else "" log.info("gateway: {}".format(gateway)) wired.open_network_wired_dialog() wired.set_static_ip(ip_address=ip, subnet_mask=mask, default_gateway=gateway) return True except: log.error(traceback.format_exc()) pyautogui.screenshot( cf.get_current_dir("Test_Report/set_static_network.png")) return False
def start(case_name, **kwargs): ssid = kwargs.get("ssid", "R1-TC_2.4G_n_WPA2P") report_file = os.path.join(cf.get_current_dir(), "Test_Report", "{}.yaml".format(cf.check_ip_yaml())) cf.new_cases_result(report_file, case_name) log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) wireless = network_setting.Wireless() if not wireless.check_wireless_card(): log.error("not found the wireless card on thin client") report = { 'step_name': 'check wireless card', 'result': 'fail', 'expect': "thin client has wireless card", 'actual': "not found wireless card on thin client", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.error("{:+^80}".format("test case fail")) return False cf.SwitchThinProMode("admin") wireless.close_control_panel() wired = network_setting.Wired() if wired.check_wired_is_connected(): wired.set_wired_and_wireless_simultaneously() wired.disable_eth0() wireless.del_wireless_profile_from_reg() if not connect_wireless(ssid=ssid): # connect wireless log.error("add wireless {} profile fail".format(ssid)) wireless.close_control_panel() wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0() log.info("wait connect wired") time.sleep(10) report = { 'step_name': 'add wireless ' + ssid + ' profile fail', 'result': 'fail', 'expect': "connect wireless success", 'actual': "connect wireless fail, time out", 'note': '' } cf.update_cases_result(report_file, case_name, report) return False for i in range(24): log.info("wait connect wireless...") time.sleep(5) if wireless.check_wireless_connected(): log.info("wireless connect success") break else: log.error("connect wireless time out") report = { 'step_name': 'connect wireless', 'result': 'fail', 'expect': "connect wireless success", 'actual': "connect wireless fail, time out", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'connect wireless', 'result': 'Pass', 'expect': "connect wireless success", 'actual': "connect wireless success", 'note': '' } cf.update_cases_result(report_file, case_name, report) if not network.ping_server(ip="15.83.240.98"): # ping 15.83.240.98 report = { 'step_name': 'ping "15.83.240.98"', 'result': 'fail', 'expect': "ping server success", 'actual': "ping server fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'ping "15.83.240.98"', 'result': 'pass', 'expect': "ping server success", 'actual': "ping server success", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info("set 'root/Network/disableLeftClickMenu' is 0") for i in range(2): os.system("mclient --quiet set root/Network/disableLeftClickMenu 0") time.sleep(2) os.system("mclient commit") time.sleep(5) disableLeftvalue = os.system( "mclient --quiet get root/Network/disableLeftClickMenu") if disableLeftvalue == 0: log.info("disableLeftvalue edit successful") break else: log.info("disableLeftvalue edit fail") continue time.sleep(1) if not stop_network(): # stop network report = { 'step_name': 'stop network', 'result': 'fail', 'expect': "stop network from network systray icon success", 'actual': "stop network from network systray icon fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() os.system("mclient --quiet set root/Network/disableLeftClickMenu 1") os.system("mclient commit") log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'stop network', 'result': 'pass', 'expect': "stop network from network systray icon success", 'actual': "stop network from network systray icon success", 'note': '' } cf.update_cases_result(report_file, case_name, report) if not start_network(): # start network report = { 'step_name': 'start network', 'result': 'fail', 'expect': "start network from network systray icon success", 'actual': "start network from network systray icon fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() os.system("mclient --quiet set root/Network/disableLeftClickMenu 1") os.system("mclient commit") log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'start network', 'result': 'pass', 'expect': "start network from network systray icon success", 'actual': "start network from network systray icon success", 'note': '' } cf.update_cases_result(report_file, case_name, report) if not restart_network(): # start network report = { 'step_name': 'restart network', 'result': 'fail', 'expect': "restart network from network systray icon success", 'actual': "restart network from network systray icon fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() os.system("mclient --quiet set root/Network/disableLeftClickMenu 1") os.system("mclient commit") log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'restart network', 'result': 'pass', 'expect': "restart network from network systray icon success", 'actual': "restart network from network systray icon success", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info("start delete the wireless profile") wireless.del_wireless_profile_from_reg() log.info("wait wireless disconnect") time.sleep(10) if wireless.check_wireless_connected(): log.error("wireless connected") report = { 'step_name': 'check wireless status', 'result': 'fail', 'expect': "wireless is disconnect after delete wireless profile", 'actual': "wireless is connect after delete wireless profile", 'note': '' } cf.update_cases_result(report_file, case_name, report) wired.set_wired_connection_priority() os.system("mclient --quiet set root/Network/disableLeftClickMenu 1") os.system("mclient commit") log.error("{:+^80}".format("test case fail")) return False report = { 'step_name': 'check wireless status', 'result': 'pass', 'expect': "wireless is disconnect after delete wireless profile", 'actual': "wireless is disconnect after delete wireless profile", 'note': '' } cf.update_cases_result(report_file, case_name, report) wired.set_wired_connection_priority() os.system("mclient --quiet set root/Network/disableLeftClickMenu 1") os.system("mclient commit") if not wired.check_wired_is_connected(): log.info("wired is not connected") wired.enable_eth0() time.sleep(20) log.info("{:+^80}".format("test case pass")) return True
def step_1_2(**kwargs): case_name = kwargs.get("case_name") report_file = kwargs.get("report_file") ssid = kwargs.get("ssid") log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) cf.SwitchThinProMode("admin") wireless = network_setting.Wireless() wireless.close_control_panel() if not wireless.check_wireless_card(): try: wireless.restore_wireless() except Exception as e: log.error(traceback.print_exc()) traceback.print_exc() raise e finally: wireless.close_control_panel() time.sleep(3) if not wireless.check_wireless_card(): log.error("not found the wireless card on thin client") report = { 'step_name': 'check wireless card', 'result': 'fail', 'expect': "thin client has wireless card", 'actual': "not found wireless card on thin client", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False ssid_list = [ "R1-Linux-5N_thinpro_store", "R1-Linux-5N_ssl_store", "R1-Linux-AC" ] if ssid in ssid_list: # import ROOTCA.cer if not cf.import_cert(): log.error("import cert fail") report = { 'step_name': 'import cert', 'result': 'fail', 'expect': "import cert success", 'actual': "import cert fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False if ssid == "R1-Linux-2.4N": folder = subprocess.getoutput("ls /media") rootca_path = os.path.join("/media", folder, "Certs", "ROOTCA.cer") cert_8021x = os.path.join("/media", folder, "Certs", "802.1X.pfx") if not os.path.exists(rootca_path) or not os.path.exists(cert_8021x): log.error( "not found the cert 'ROOTCA.cer' or '802.1X.pfx' in /media/{}/Certs" .format(format(folder))) report = { 'step_name': "check cert 'ROOTCA.cer' and '802.1X.pfx'", 'result': 'fail', 'expect': "found 'ROOTCA.cer' and '802.1X.pfx' in USB store", 'actual': "not found the cert 'ROOTCA.cer' or '802.1X.pfx' in /media/.../Certs", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False wired = network_setting.Wired() if wired.check_wired_is_connected(): wired.set_wired_and_wireless_simultaneously() wired.disable_eth0() wireless.del_wireless_profile_from_reg() con_res = connect_wireless(wireless=wireless, ssid=ssid) if con_res is False or con_res: # connect wireless log.error("add wireless {} profile fail".format(ssid)) wireless.close_control_panel() wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0() log.info("wait connect wired") time.sleep(10) report = { 'step_name': 'add wireless ' + ssid + ' profile fail', 'result': 'fail', 'expect': "connect wireless success", 'actual': "connect wireless fail, time out", 'note': f'{con_res}' } cf.update_cases_result(report_file, case_name, report) wireless.restore_wireless() return False for i in range(24): log.info("wait connect wireless {}...".format(ssid)) time.sleep(5) if wireless.check_wireless_connected(): log.info("wireless connect success") break else: log.error("connect wireless time out") report = { 'step_name': 'connect wireless', 'result': 'fail', 'expect': "connect wireless success", 'actual': "connect wireless fail, time out", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() wired.enable_eth0() log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False report = { 'step_name': 'connect wireless', 'result': 'Pass', 'expect': "connect wireless success", 'actual': "connect wireless success", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info('Wait 30 seconds to stabilize the network') time.sleep(30) if not network.ping_server(ip="15.83.240.98"): # ping 15.83.240.98 report = { 'step_name': 'ping "15.83.240.98"', 'result': 'fail', 'expect': "ping server success", 'actual': "ping server fail", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() wired.enable_eth0() log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False report = { 'step_name': 'ping "15.83.240.98"', 'result': 'pass', 'expect': "ping server success", 'actual': "ping server success", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info("start reboot") os.system("reboot") time.sleep(60)
def step_3_4(**kwargs): case_name = kwargs.get("case_name") report_file = kwargs.get("report_file") ssid = kwargs.get("ssid") log.info("check wireless status after reboot") cf.SwitchThinProMode("admin") wireless = network_setting.Wireless() wired = network_setting.Wired() for i in range(24): if wireless.check_wireless_connected(): log.info("wireless auto connect success after reboot") break log.info("wait connect wireless {}...".format(ssid)) time.sleep(5) else: log.error("connect wireless time out") report = { 'step_name': 'check wireless status', 'result': 'fail', 'expect': "wireless auto connect success after reboot", 'actual': "wireless auto connect fail after reboot", 'note': '' } cf.update_cases_result(report_file, case_name, report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() wired.enable_eth0() log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False report = { 'step_name': 'check wireless status', 'result': 'pass', 'expect': "wireless auto connect success after reboot", 'actual': "wireless auto connect success after reboot", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info("start delete the wireless profile") wireless.del_wireless_profile_from_reg() log.info("wait wireless disconnect") time.sleep(10) if wireless.check_wireless_connected(): log.error("wireless connected") report = { 'step_name': 'check wireless status', 'result': 'fail', 'expect': "wireless is disconnect after delete wireless profile", 'actual': "wireless is connect after delete wireless profile", 'note': '' } cf.update_cases_result(report_file, case_name, report) wired.set_wired_connection_priority() wired.enable_eth0() log.error("{:+^80}".format("test case fail")) wireless.restore_wireless() return False report = { 'step_name': 'check wireless status', 'result': 'pass', 'expect': "wireless is disconnect after delete wireless profile", 'actual': "wireless is disconnect after delete wireless profile", 'note': '' } cf.update_cases_result(report_file, case_name, report) wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): log.info("wired is not connected") wired.enable_eth0() time.sleep(20) log.info("{:+^80}".format("test case pass")) return True
def start(case_name, **kwargs): ethernet_speed = kwargs.get("ethernet_speed", "Automatic") speed = kwargs.get("speed", "1000Mb/s") duplex = kwargs.get("duplex", "Full") auto_negotiation = kwargs.get("auto_negotiation", "on") log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) report_file = os.path.join(cf.get_current_dir(), "Test_Report", "{}.yaml".format(cf.check_ip_yaml())) cf.new_cases_result(report_file, case_name) before = subprocess.getoutput( "mclient --quiet get root/Network/userLockEngaged") log.info("current userLockEngaged value {}".format(before)) if not pre_check(): pre_check_report = { 'step_name': 'pre_check', 'result': 'Fail', 'expect': 'ThinPro connected wired', 'actual': 'ThinPro not connected wired', 'note': '' } cf.update_cases_result(report_file, case_name, pre_check_report) log.error("{:+^80}".format("test case fail")) return False wired = network_setting.Wired() if not set_eth0_speed(ethernet_speed=ethernet_speed): # set Ethernet Speed set_speed_report = { 'step_name': 'set eth0 speed', 'result': 'Fail', 'expect': "set 'Ethernet Speed' success", 'actual': "set 'Ethernet Speed' fail", 'note': '' } cf.update_cases_result(report_file, case_name, set_speed_report) wired.close_control_panel() reset_test_environment() log.error("{:+^80}".format("test case fail")) return False for i in range(24): log.info("wait wired reconnect...") time.sleep(5) if wired.check_wired_is_connected(): log.info("wired is connected") break else: log.error("reconnect wired time out 2 minutes") reconnect_wired_report = { 'step_name': 'reconnect wired', 'result': 'Fail', 'expect': "reconnect wired success", 'actual': "reconnect wired time out 2 minutes", 'note': '' } cf.update_cases_result(report_file, case_name, reconnect_wired_report) reset_test_environment() log.error("{:+^80}".format("test case fail")) return False eth0_speed = get_eth0_speed() if eth0_speed["speed"] == speed and eth0_speed["duplex"] == duplex and \ eth0_speed["auto-negotiation"] == auto_negotiation: log.info("eth0 speed is '{}'".format(eth0_speed["speed"])) log.info("eth0 duplex is '{}'".format(eth0_speed["duplex"])) log.info("eth0 auto-negotiation is '{}'".format( eth0_speed["auto-negotiation"])) else: log.error("eth0 speed is '{}'".format(eth0_speed["speed"])) log.error("eth0 duplex is '{}'".format(eth0_speed["duplex"])) log.error("eth0 auto-negotiation is '{}'".format( eth0_speed["auto-negotiation"])) check_speed_report = { 'step_name': 'check eth0 speed', 'result': 'Fail', 'expect': "eth0 speed is '{}', '{}', '{}'".format(speed, duplex, auto_negotiation), 'actual': "eth0 speed is '{speed}', '{duplex}', '{auto-negotiation}'". format_map(eth0_speed), 'note': '' } cf.update_cases_result(report_file, case_name, check_speed_report) reset_test_environment() log.error("{:+^80}".format("test case fail")) return False reset_test_environment() check_speed_report = { 'step_name': 'check eth0 speed', 'result': 'Pass', 'expect': "eth0 speed is '{}', '{}', '{}'".format(speed, duplex, auto_negotiation), 'actual': "eth0 speed is '{speed}', '{duplex}', '{auto-negotiation}'".format_map( eth0_speed), 'note': '' } cf.update_cases_result(report_file, case_name, check_speed_report) del wired after = subprocess.getoutput( "mclient --quiet get root/Network/userLockEngaged") log.info("after userLockEngaged value {}".format(after)) if after == before: log.info( "after and before value are same as,not restore userLockEngaged value" ) else: log.info( "userLockEngaged Different values before and after operation") order = ("mclient --quiet set root/Network/userLockEngaged {}".format( before)) commit = "mclient commit" cmd = order + '&&' + commit subprocess.getoutput(cmd) time.sleep(3) log.info("edit userLockEngaged value successful") log.info("{:+^80}".format("test case pass")) return True
def start(case_name, **kwargs): log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) report_file = os.path.join(cf.get_current_dir(), "Test_Report", "{}.yaml".format(cf.check_ip_yaml())) cf.new_cases_result(report_file, case_name) before = subprocess.getoutput( "mclient --quiet get root/Network/userLockEngaged") log.info("current userLockEngaged value {}".format(before)) wired = network_setting.Wired() wireless = network_setting.Wireless() if not wireless.check_wireless_card(): # check wireless card log.error("not found the wireless card on thinpro") pre_check_report = { 'step_name': 'pre_check', 'result': 'Fail', 'expect': 'ThinPro has wireless card', 'actual': 'not found the wireless card on thin client', 'note': '' } cf.update_cases_result(report_file, case_name, pre_check_report) log.error("{:+^80}".format("test case fail")) return False wireless.del_wireless_profile_from_reg() if wired.check_wired_is_connected(): # check wired connected log.info("wired is connected") wired.set_wired_and_wireless_simultaneously() wired.disable_eth0() time.sleep(3) value = subprocess.getoutput( "mclient --quiet get root/Network/EncryptWpaConfig" ) # step 1------------- if int(value) != 1: log.error("the default value of 'network/EncryptWpaConfig' not is '1'") step_1_report = { 'step_name': 'check value of "root/Network/EncryptWpaConfig"', 'result': 'Fail', 'expect': 'the value of "root/Network/EncryptWpaConfig" is 1', 'actual': 'the value of "root/Network/EncryptWpaConfig" not is 1', 'note': '' } cf.update_cases_result(report_file, case_name, step_1_report) wired.set_wired_connection_priority() log.error("{:+^80}".format("test case fail")) return False log.info("the default value of 'network/EncryptWpaConfig' is '1'") step_1_report = { 'step_name': 'check value of "root/Network/EncryptWpaConfig"', 'result': 'Pass', 'expect': 'the value of "root/Network/EncryptWpaConfig" is 1', 'actual': 'the value of "root/Network/EncryptWpaConfig" is 1', 'note': '' } cf.update_cases_result(report_file, case_name, step_1_report) log.info("start connect a wireless ap") # step 2------------- cf.SwitchThinProMode("admin") wireless.open_network() wireless.switch_to_wireless_tab() wireless.add(ssid="R1-Linux-disconnect") # wireless.add(ssid="R1-TC_5G_n") wireless.apply_and_ok() wireless.apply() wireless.close_control_panel() for i in range(12): log.info("wait connect wireless...") time.sleep(5) if wireless.check_wireless_connected(): log.info("wireless connected success") break else: log.error("connect wireless time out") step_2_report = { 'step_name': 'connect wireless', 'result': 'Fail', 'expect': 'connect wireless success', 'actual': 'connect wireless fail', 'note': '' } cf.update_cases_result(report_file, case_name, step_2_report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0() log.error("{:+^80}".format("test case fail")) return False step_2_report = { 'step_name': 'connect wireless', 'result': 'Pass', 'expect': 'connect wireless success', 'actual': 'connect wireless success', 'note': '' } cf.update_cases_result(report_file, case_name, step_2_report) password = subprocess.getoutput( "cat /etc/wpasupplicant.wireless.wlan0.conf") # step 3 ------------- if "neoware1234".lower() in password.lower(): log.error("wireless password not is encryption") step_3_report = { 'step_name': 'check wireless password profile is encryption', 'result': 'Fail', 'expect': 'check wireless password profile is encryption', 'actual': 'check wireless password profile not is encryption', 'note': '' } cf.update_cases_result(report_file, case_name, step_3_report) wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0() log.error("{:+^80}".format("test case fail")) return False log.info("wireless password is encryption") step_3_report = { 'step_name': 'check wireless password profile is encryption', 'result': 'Pass', 'expect': 'check wireless password profile is encryption', 'actual': 'check wireless password profile is encryption', 'note': '' } cf.update_cases_result(report_file, case_name, step_3_report) log.info("start reset test environment") wireless.del_wireless_profile_from_reg() wired.set_wired_connection_priority() if not wired.check_wired_is_connected(): wired.enable_eth0() for i in range(20): time.sleep(3) if wired.check_wired_is_connected(): break after = subprocess.getoutput( "mclient --quiet get root/Network/userLockEngaged") log.info("after userLockEngaged value {}".format(after)) if after == before: log.info( "after and before value are same as,not restore userLockEngaged value" ) else: log.info( "userLockEngaged Different values before and after operation") order = ("mclient --quiet set root/Network/userLockEngaged {}".format( before)) commit = "mclient commit" cmd = order + '&&' + commit subprocess.getoutput(cmd) time.sleep(3) log.info("edit userLockEngaged value successful") log.info("{:+^80}".format("test case pass")) return True
def userlock_is_0(**kwargs): report_file = kwargs.get("report_file") case_name = kwargs.get("case_name") hostname = get_default_hostname() cf.SwitchThinProMode("admin") if get_hostname_registry() != "asdfgh": log.error("hostname not is 'asdfgh'") report = { 'step_name': 'check hostname after import profile', 'result': 'fail', 'expect': "hostname is 'asdfgh'", 'actual': "hostname not is 'asdfgh'", 'note': '' } cf.update_cases_result(report_file, case_name, report) teardown_test_environment() modify_hostname_registry(hostname) cf.import_profile() os.remove(cf.get_current_dir("Test_Data/profile_file.xml")) log.error("{:+^80}".format("test case fail")) return False log.info("hostname is 'asdfgh'") report = { 'step_name': 'check hostname after import profile', 'result': 'pass', 'expect': "hostname is 'asdfgh'", 'actual': "hostname is 'asdfgh'", 'note': '' } cf.update_cases_result(report_file, case_name, report) connection_mode = subprocess.getoutput( "mclient --quiet get root/Network/Wired/Method") ip_list = get_static_network_value() if connection_mode != "Static" or ip_list.count( "") == 3: # check mode and static ip log.error( "connection mode and static ip info has modified after import profile" ) report = { 'step_name': 'userLock is 1 and after import profile', 'result': 'fail', 'expect': "check connection mode is static and static ip not has clear", 'actual': "check connection mode not is static or static ip has clear", 'note': '' } cf.update_cases_result(report_file, case_name, report) cf.import_profile() teardown_test_environment() modify_hostname_registry(hostname) os.remove(cf.get_current_dir("Test_Data/profile_file.xml")) log.error("{:+^80}".format("test case fail")) return False log.info( "connection mode and static ip info not modified after import profile") report = { 'step_name': 'userLock is 1 and after import profile', 'result': 'pass', 'expect': "check connection mode is static and static ip not has clear", 'actual': "check connection mode is static and static ip not has clear", 'note': '' } cf.update_cases_result(report_file, case_name, report) log.info("set userLock=0 and test again") # set userLock = 0 teardown_test_environment() set_userlock("0") export_profile() set_static_network() wired = network_setting.Wired() for i in range(20): log.info("wait wired connect...") time.sleep(2) if wired.check_wired_is_connected(): log.info("wired is connected") break else: log.error("connect wired time out") report = { 'step_name': 'connect wired', 'result': 'fail', 'expect': "connect wired success after set static ip", 'actual': "connect wired time out", 'note': '' } cf.update_cases_result(report_file, case_name, report) cf.import_profile() teardown_test_environment() modify_hostname_registry(hostname) os.remove(cf.get_current_dir("Test_Data/profile_file.xml")) log.error("{:+^80}".format("test case fail")) return False import_profile() log.info("reboot") time.sleep(30)
def step_1(**kwargs): case_name = kwargs.get("case_name") log.info("{:-^80}".format("start a case test")) log.info("case name: " + case_name) log.info("start prepare the pre_condition") wireless = network_setting.Wireless() # check wireless card if not wireless.check_wireless_card(): try: restore_wireless() except Exception as e: log.error(traceback.print_exc()) traceback.print_exc() finally: wireless.close_control_panel() time.sleep(3) if not wireless.check_wireless_card(): log.error("not found wireless card on thin client") return [ False, "found wireless card but not found wlan0 on thin client" ] wired = network_setting.Wired() if wired.check_wired_is_connected(): log.info("wired is connected") wired.set_wired_and_wireless_simultaneously() wired.disable_eth0() time.sleep(2) wireless.del_wireless_profile_from_reg() log.info("start connect wireless 'R1-TC_5G_n'") cf.SwitchThinProMode("admin") wireless.open_network() wireless.switch_to_wireless_tab() wireless.add(ssid="R1-TC_5G_n") wireless.apply_and_ok() wireless.apply() wireless.close_control_panel() for i in range(24): log.info("wait connect wireless...") time.sleep(5) if wireless.check_wireless_connected(): log.info("wireless has connected") break else: log.error("connect wireless time out") wireless.set_wired_connection_priority() wired.enable_eth0() return [False, "connect wireless time out"] log.info("start test case-----------------------------") log.info("start disable wireless") wireless.open_network() wireless.switch_to_wireless_tab() wireless.disable_wireless() # disable wireless wireless.apply() add_edit_del = wait_element(pic("_gray_add_edit_del"), rate=0.99) if not add_edit_del: log.error("add, edit, delete not is gray") restore_wireless() return [False, "add, edit, delete not is gray"] log.info("add, edit, delete is gray") wireless.close_control_panel() if wireless.check_wireless_connected(): log.error("wireless is connected") restore_wireless() return [False, "wireless is connected"] log.info("wireless is disconnected") if wait_element(pic("_systray_not_connect")): log.error("systray wireless icon is exist") restore_wireless() return [False, "systray wireless icon is exist"] wlan0 = subprocess.getoutput("ifconfig | grep -i wlan0") if wlan0: log.error("found the 'wlan0' use command 'ifconfig'") restore_wireless() return [False, "found the 'wlan0' use command 'ifconfig'"] log.info("systray wireless icon is not exist") log.info("start reboot") return [True, "step_1 test pass"]
def start(case_name, **kwargs): log.info("{:-^80}".format("start a case test")) log.info("case name:" + case_name) report_file = os.path.join(cf.get_current_dir(), "Test_Report", "{}.yaml".format(cf.check_ip_yaml())) cf.new_cases_result(report_file, case_name) cf.SwitchThinProMode("admin") default_profile = cf.get_current_dir("Test_Data/profile.xml") if not os.path.exists(default_profile): log.error("not found the default profile") check_profie_report = { 'step_name': 'check default profile file', 'result': 'Fail', 'expect': "found default profile file", 'actual': "not found default profile file", 'note': '' } cf.update_cases_result(report_file, case_name, check_profie_report) log.error("{:+^80}".format("test case fail")) return False log.info("found the default profile") log.info("start import the default profile") cf.import_profile() log.info( "start check the value of userLockEngaged") # step 1 ------------- if userlockengaged_value() is not "0": log.error("the default value of userLockEngaged not is '0'") check_userLockEngaged_report = { 'step_name': 'check default profile file', 'result': 'Fail', 'expect': "userLockEngaged is '0'", 'actual': "userLockEngaged not is '0'", 'note': '' } cf.update_cases_result(report_file, case_name, check_userLockEngaged_report) log.error("{:+^80}".format("test case fail")) return False log.info("the default value of userLockEngaged is '0'") check_userLockEngaged_report = { 'step_name': 'check default profile file', 'result': 'Pass', 'expect': "userLockEngaged is '0'", 'actual': "userLockEngaged is '0'", 'note': '' } cf.update_cases_result(report_file, case_name, check_userLockEngaged_report) log.info("start modify the hostname") # step 2 --------------- dns = network_setting.DNS() dns.open_dns() dns.dns_set_hostname("123456") dns.apply() dns.close_control_panel() log.info("check the value of userLockEngaged again" ) # step 3 ------------------- if userlockengaged_value() is not "1": log.error("the value of userLockEngaged not is '1'") check_userLockEngaged_report = { 'step_name': 'check default profile file', 'result': 'Fail', 'expect': "userLockEngaged auto changed to '1'", 'actual': "userLockEngaged not auto changed to '1'", 'note': '' } cf.update_cases_result(report_file, case_name, check_userLockEngaged_report) cf.import_profile() log.error("{:+^80}".format("test case fail")) return False log.info("the value of userLockEngaged is '1'") check_userLockEngaged_report = { 'step_name': 'check default profile file', 'result': 'Pass', 'expect': "userLockEngaged auto changed to '1'", 'actual': "userLockEngaged auto changed to '1'", 'note': '' } cf.update_cases_result(report_file, case_name, check_userLockEngaged_report) cf.import_profile() wired = network_setting.Wired() for i in range(20): if wired.check_wired_is_connected(): break time.sleep(2) log.info("set 'root/Network/userLockEngaged' is 0") os.system("mclient --quiet set root/Network/userLockEngaged 0") os.system("mclient commit") time.sleep(1) log.info("{:+^80}".format("test case pass")) return True