コード例 #1
0
def start(case_name, **kwargs):
    try:
        log.info('Begin to start case {}'.format(case_name))
        result_file = os.path.join(get_current_dir(), r'Test_Report',
                                   '{}.yaml'.format(check_ip_yaml()))
        new_cases_result(result_file, case_name)
        SwitchThinProMode(switch_to='admin')
        default_method = get_connection_method()
        wired = Wired()
        if dynamic_ip_check(case_name, result_file, wired) is False:
            reset_connection_method(default_method)
            return
        if dynamic_ip_ping(case_name, result_file) is False:
            reset_connection_method(default_method)
            return
        ip = get_ip()
        mask = wired.get_mask('eth0')
        gateway = wired.gateway()
        if static_ip_check(case_name, result_file, wired, ip, mask,
                           gateway) is False:
            reset_connection_method(default_method)
            return
        if static_ip_ping(case_name, result_file) is False:
            reset_connection_method(default_method)
            return
    except:
        log.error(traceback.format_exc())
        error_pic = os.path.join(get_current_dir(), r'Test_Report', 'img',
                                 '{}.png'.format(case_name))
        capture_screen(error_pic)
        os.system("wmctrl -c 'Control Panel'")
コード例 #2
0
 def website_test(self, url, flag, case_name, report_file):
     if flag:
         expect = 200
         msg = "verify {} can be accessed".format(url)
     else:
         expect = 'Error'
         msg = "verify {} can not be accessed".format(url)
     steps = {
         'step_name': "test {}".format(url),
         'result': '',
         'expect': 'status code should be {}'.format(expect),
         'actual': '',
         'note': ''
     }
     log.info(msg)
     log.info('current ip: {}'.format(common_function.get_ip()))
     log.info('get status code from {}'.format(url))
     data = self.get_website_response()
     actual = 'status code is {}'.format(data)
     log.info(actual)
     if data == expect:
         s = 'Pass'
         rs = True
     else:
         s = 'Fail'
         rs = False
     log.info('test {}'.format(s))
     steps['result'] = s
     steps['actual'] = actual
     common_function.update_cases_result(report_file, case_name, steps)
     return rs
コード例 #3
0
 def access_website(self):
     log.info('current ip: {}'.format(common_function.get_ip()))
     expect = 200
     data = self.get_website_response()
     log.info('status code is: {}'.format(data))
     if data == expect:
         rs = True
     else:
         rs = False
     return rs
コード例 #4
0
def start(case_name, **kwargs):
    log = Logger()
    report_file = os.path.join(cf.get_current_dir(), "Test_Report",
                               "{}.yaml".format(cf.get_ip()))

    cf.case_steps_run_control(steps_list,
                              __name__,
                              case_name=case_name,
                              log=log,
                              report_file=report_file)
コード例 #5
0
def modify_ip(gateway):
    n = int(gateway.split('.')[-1])
    ip = get_ip()
    ip_lis = ip.split('.')
    m = int(ip_lis[-1])
    if n < m < n + 13:
        m += 1
    ip_lis[-1] = str(m)
    ip = ".".join(ip_lis)
    return ip
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
コード例 #7
0
 def connected_wireless_info(self):
     """
     :return: {'ssid': 'R1-TC_5G_n', 'ip': '15.83.252.84', 'network mask': '255.255.255.192',
               'gatewary': '15.83.252.65', 'channel': '161'}
     """
     info = dict()
     s = subprocess.getoutput("iwconfig wlan0 | grep SSID")
     ssid = re.findall('"(.*)"', s)
     if ssid:
         info["ssid"] = ssid[0]
         info["ip"] = cf.get_ip()
         info["network mask"] = self.get_wlan_mask()
         info["gatewary"] = self.gateway()
         w = subprocess.getoutput("iwconfig wlan0 | grep -i 'access point'")
         mac = w.split("Access Point:")[-1].strip()
         command = "iwlist wlan0 scan | grep '{}' -A 2 | grep Channel".format(
             mac)
         chan = subprocess.getoutput(command)
         channel = chan.strip().split(":")[1].split("\n")[0]
         info["channel"] = channel
         return info
     else:
         return None