def check_frequency(freq=2.4):
     response = run_command("sudo iwlist wlan0 channel")
     result = re.search(r"(?i)Current Frequency.*?([\d\.]+).*?GHZ.*?",
                        response)
     if result:
         frequency = float(result.group(1))
         if abs(frequency - freq) < 1:
             return
         raise CaseRunningError(
             f"Check Frequency Fail! Current: {frequency} Expect: {freq}")
     raise CaseRunningError("Wireless Connect Fail")
 def import_cert(self, file_path):
     dst = f"/etc/ThinProCertificates/{os.path.basename(file_path)}"
     shutil.copy(file_path, dst)
     file_name = os.path.basename(file_path).replace(".cer", ".pem")
     source = f"/etc/ssl/certs/{file_name}"
     dist = f"/etc/ThinProCertificates/{file_name}"
     if file_path in self._certs:
         log.warning(f'Cert: {file_path} has imported !')
         return
     log.info(f"Start Import Cert {file_path}")
     CertificateUtil._certs.append(file_path)
     pipe = os.popen(f'hptc-cert-mgr --non-interactive -i {file_path}')
     if '802' not in file_path:
         pipe.read()
         shutil.copy(source, dist)
         return
     try:
         time.sleep(3)
         input_window = self.cert_password
         input_window.cert_blank.send_keys(self._cert_password)
         self.cert_ok.click()
         time.sleep(10)
         log.info(f"Import Cert {file_path} Success!")
     except PicNotFoundError as e:
         raise CaseRunningError(f"Import Cert Fail! {str(e)}")
     finally:
         self.close()
 def logon(self):
     EasyRDP.delete_vdi(self.vdi)
     EasyRDP.create_vdi(self.vdi)
     connection_id_list = EasyRDP.vdi_connection_id(self.vdi)
     if len(connection_id_list) == 1:
         self.vdi_id = connection_id_list[0]
         log.info(f"start launching {self.vdi_id}")
         self.__set_vdi()
         self.open()
         time.sleep(10)
         if not self.is_active():
             self.open()
     elif len(connection_id_list) > 1:
         raise CaseRunningError("Delete RDP Fail")
     else:
         raise CaseRunningError("Create RDP Fail")
 def check_dns_info_after_reboot(self):
     """
     Index: 1
     """
     domains = run_command(
         "mclient --quiet get root/Network/SearchDomains").strip()
     servers = run_command(
         "mclient --quiet get root/Network/DNSServers").strip()
     if domains != self.format_search_domains:
         raise CaseRunningError(
             f"Chcek SearchDomains Fail! Expect: {self.format_search_domains} Actual: {domains}"
         )
     if servers != self.format_dns_server:
         raise CaseRunningError(
             f"Chcek DNSServers Fail! Expect: {self.format_dns_server} Actual: {servers}"
         )
Example #5
0
 def __wait_until_ap_appear(self, time_out=60, interval=5):
     while time_out:
         try:
             return self.network.signal
         except PicNotFoundError:
             time_out -= interval
             log.info("Waiting AP Appear")
             time.sleep(interval)
     raise CaseRunningError(f"Click Scan AP, But Waiting AP Appear Fail")
 def __ping_method(self, target_ip="15.83.240.98", expectation=True):
     ping_result = ping(target_ip, count=15)
     if ping_result is expectation:
         log.info(
             f"Ping {target_ip} Success! Expect: {expectation} Actual: {ping_result}"
         )
     else:
         raise CaseRunningError(
             f"Ping {target_ip} Fail! Expect: {expectation} Actual: {ping_result}"
         )
 def wait_until_wireless_connected(self, time_out=60, interval=5):
     while time_out:
         try:
             connected = self.wireless_connected
             return
         except PicNotFoundError:
             time_out -= interval
             log.info("Waiting Wireless Connect")
             time.sleep(interval)
     raise CaseRunningError(f"Wireless Connect Fail")
 def __wait_until_rdp_logon(self, time_out=60, interval=5):
     while time_out:
         try:
             if self.rdp.into_rdp:
                 return True
         except PicNotFoundError:
             time_out -= interval
             log.info("Waiting RDP Logon")
             time.sleep(interval)
     raise CaseRunningError(f"VDI Logon Fail VDI_ID {self.rdp.vdi_id}")
 def __set_vdi(self):
     front_command = "mclient --quiet set root/ConnectionType/"
     command = ""
     if not self.vdi_id:
         raise CaseRunningError("No VDI Select")
     if self.settings:
         for key, values in self.settings.items():
             joined_command = front_command + "{}/connections/{}/{} '{}' && ".format(
                 self.vdi, self.vdi_id, key, values)
             command += joined_command
     command += "mclient commit"
     run_command(commands=command, timeout=30)
def search_file_from_usb(file_name):
    """
    :return str, absolute file path, name can be a grep in linux
    """
    folder = run_command("ls /media").strip()
    result = run_command(
        f"find /media/{folder} -type f -iname '{file_name}'").strip()
    if not result:
        raise CaseRunningError(
            f"File {file_name} not found  in /media/{folder}")
    log.info(f'Find the File: {result}')
    return result