Exemple #1
0
 def check_vpn_result(self):
     get_result = self.vpn.get_vpn_ip('cisco')
     if not get_result:
         return False
     else:
         self.log.info('Get vpn ip {}.'.format(get_result))
     ping_result = network.ping_server('10.10.10.1')
     if not ping_result:
         return False
     else:
         self.log.info('Ping 10.10.10.1 successfully.')
     return get_result, ping_result
Exemple #2
0
def static_ip_ping(case_name, result_file):
    log.info("ping any other available host, ex.15.83.240.98")
    ping_res = ping_server(ip="15.83.240.98")
    if ping_res:
        steps = {
            'step_name': 'check ping "15.83.240.98" result',
            'result': 'Pass',
            'expect': '',
            'actual': '',
            'note': ''
        }
        update_cases_result(result_file, case_name, steps)
    else:
        steps = {
            'step_name': 'check ping "15.83.240.98" result',
            'result': 'Fail',
            'expect': 'ping success',
            'actual': 'ping result {}'.format(ping_res),
            'note': ''
        }
        update_cases_result(result_file, case_name, steps)
        return False
Exemple #3
0
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)