def get_encrypted_file(): download_path = ConfigAdapter.get_testdata_path().replace("\\\\", "\\") for file in os.listdir(download_path): if os.path.isfile(os.path.join(download_path, file)): file = os.path.join(download_path, file) LogHelper.info("Get encrypted file path: " + file) return file
def get_decrypted_file(): restore_path = FRYR_CONFIG['WIN_RESTORE'] for file in os.listdir(restore_path): if os.path.isfile(os.path.join(restore_path, file)): file = os.path.join(restore_path, file) LogHelper.info("Get decrypted file path: " + file) return file
def start_fb(cls): if PlatformHelper.is_mac(): fb_binary_dir = os.path.join(cls.config_path, cls.package_name.split(".tar.gz")[0]) os.chdir(fb_binary_dir) cmd = "./filebeat -c filebeat.yml &" output = os.system(cmd) if PlatformHelper.is_Linux(): cmd = "service filebeat start" output = CmdHelper.run(cmd) if PlatformHelper.is_win(): cmd = "sc start filebeat" # This is to make sure filebeat service can be started after install time.sleep(1) output = CmdHelper.run(cmd) # service = "Get-WmiObject -ClassWin32_Service-Filter name='filebeat'" # service.StartService() # service.StopService() LogHelper.info("start filebeat result %s" % output) return output
def create_mzd(self): try: self.locate_element(self.xpaths['restoreName']).click() time.sleep(1) self.locate_element(self.xpaths['restoreName']).send_keys( FRYR_CONFIG['RESTORE']['MZD_TAG']) self.locate_element(self.xpaths['restoreNextBtn']).click() self.locate_element(self.xpaths['mzdRadioBtn']).click() self.locate_element(self.xpaths['restoreNextBtn']).click() skip_btn = self.is_element_exist(self.xpaths['skipDownloadLink'], 10) if skip_btn: skip_btn.click() else: el = self.is_element_exist(self.xpaths['downloadFryRLink'], 2) if el: el.click() self.locate_element(self.xpaths['beginDownloadBtn']).click() time.sleep(5) self.locate_element(self.xpaths['closeBtn']).click() return True except Exception, e: LogHelper.error(repr(e)) LogHelper.error("Fail to create mzd file.") return False
def download_and_install(cls, build=-1, job='', pattern=r''): if build == 0: # keep current build return True if not pattern: pattern = cls.default_pattern if not job: job = cls.default_job version = MacController().get_version() LogHelper.info('Current build number is {}'.format(version)) if version == 0: # not installed package = cls.download_package(job=job, build=build, pattern=pattern) result = cls.install_package(package[0]) elif build == -1 or version != build: cls.uninstall_package() package = cls.download_package(job=job, build=build, pattern=pattern) result = cls.install_package(package[0]) else: # not install happen result = True return result
def get_encrypted_folder(): download_path = ConfigAdapter.get_testdata_path().replace("\\\\", "\\") for folder in os.listdir(download_path): if re.match(r'.*\.zip', folder): folder = os.path.join(download_path, folder) LogHelper.info("Get encrypted folder path: " + folder) return folder
def get_mzd_path(): download_path = ConfigAdapter.get_testdata_path() for file in os.listdir(download_path): if re.match(r'restore_.*\.mzd$', file): file = os.path.join(download_path, file) LogHelper.info("Get mzd target path: " + file) return file
def write_to_elasticsearch(self, sendes=True): if sendes: url = GLOBAL_CONFIG['ELASTICSEARCH'].get( 'URL') or "http://localhost" port = GLOBAL_CONFIG['ELASTICSEARCH'].get('PORT') or "8080" es = ElasticsearchHelper(url, port) #LogHelper.debug("Start to Write testresult to ES") result = es.index(index='kpi', doc_type='kpi', body=self.__create_es_body(), _id=self.id) if result: message = result.get('result') print message # if message.strip().lstrip() not in ("created", 'updated'): # LogHelper.error("create testresult message is %s" %message) # else: # LogHelper.warn("create test result is %s" %message) return result else: LogHelper.error("Fail to send KPI info to ES.") return else: print "Don't Send KPI to ES..." return self.read()
def step_impl(context, file_path): testdata_root = ConfigAdapter.get_testdata_path() full_file_path = os.path.join(testdata_root, file_path) version = LinuxGUIClient.info_cmd.get_last_version(full_file_path) LogHelper.info("current version is {version}".format(version=version)) context.version_before = version
def after_tag(context, tag): if tag == "mac_teardown": cmd = str('''osascript -e 'tell application "System Preferences" to quit' ''') output = CmdHelper.run(cmd) LogHelper.info(output) # cmd = str('''osascript -e 'tell application "MozyPro Restore" to quit' ''') # output = CmdHelper.run(cmd) if tag.lower() == 'web_teardown': pass if tag.lower() == 'macfryr_teardown': cmd = str('sudo pkill "Mozy Restore Manager"') output = CmdHelper.run(cmd) LogHelper.info(output) if tag.lower() == 'winfryr_teardown': close_fryr = 'taskkill /F /IM MozyRestoreManager.exe' output = CmdHelper.run(close_fryr) LogHelper.info(output) close_ff = 'taskkill /F /IM firefox.exe' output = CmdHelper.run(close_ff) LogHelper.info(output) if tag.lower() == 'winfryr_lsh_teardown': close_lsh_fryr = 'taskkill /F /IM MozyLshRestoreManager.exe' try: output = CmdHelper.run(close_lsh_fryr) except Exception: LogHelper.info(output)
def step_impl(context): testdata_root = ConfigAdapter.get_testdata_path() for row in context.table.rows: relative_path = row.get('path') or row.get('paths') full_path = os.path.join(testdata_root, relative_path) LogHelper.info('remove path for %s' % full_path) LinuxGUIClient.removebackupdirs_cmd.removebackupdirs(full_path)
def exe_cmd(cls, param=None): cmd = "{} {}".format(cls._mozyutil, cls._command_name) if param is not None: cmd = cmd + param LogHelper.info("MozyUtil CMD: {cmd}".format(cmd=cmd)) return CmdHelper.run(cmd)
def after_scenario(context, scenario): context.tc.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.tc.duration = int(scenario.duration) context.tc.test_result = scenario.status if context.senddb: if not (RUNNER_CONFIG.get("PRODUCT") or '').lower() == 'mts': native_client = NativeClientFactory.get_client(product=RUNNER_CONFIG.get("PRODUCT"), oem=RUNNER_CONFIG.get("OEM_CLIENT")) KPIHelper.testcase = context.tc.name KPIHelper.extract_kpi(native_client.controller.log, starttime=context.log_starttime, hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) if "-" in KPIHelper.thost: context.tc.thost = KPIHelper.thost.split("-")[1] # tds06-ut4.triton.mozy.com else: context.tc.thost = KPIHelper.thost # ut4.triton.mozy.com context.tc.write_to_elasticsearch() log = context.log_capture for line in log.getvalue().splitlines(): if line.find("ERROR") >=0: LogHelper.error(line)
def select_nodes(browser_handle, tree, node_matcher='AXStaticText'): import re nodes = re.split(r'/', tree) nodes = filter(lambda x: len(x) > 0, nodes) current_level = -1 for node in nodes: current_level += 1 LogHelper.info("search {node} node!".format(node=node)) scroll_area_top = MacUIUtils.wait_element(browser_handle, method='findFirstR', AXRole='AXScrollArea') scroll_areas = MacUIUtils.wait_element(scroll_area_top, method='findAllR', AXRole='AXScrollArea') sc = scroll_areas[current_level] entities = MacUIUtils.wait_element(sc, method='findAllR', AXRole=node_matcher) result = False for entity in entities: name = entity.AXValue if name == node: LogHelper.info('{name} node found!'.format(name=name)) result = True entity.activate() entity.clickMouseButtonLeft( MacUIUtils.__rect_center(entity)) time.sleep(1) entity.activate() if result: break if not result: raise Exception( "node {node} is not selected".format(node=node)) return
def step_impl(context, number, folder): LogHelper.info("start to create files") testdata_config = ConfigAdapter.get_testdata_pros() testdata_root = os.path.expanduser("~/{folder}".format(folder=folder)) testdata_dir = testdata_root for row in context.table: if "file_folder" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_folder')) elif "file_dir" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_dir')) for i in range(0, int(number)): file_prefix = row.get("file_prefix") or testdata_config.get( "FILE_PREFIX") or "td" file_txt = row.get("file_ext") or testdata_config.get( "FILE_EXT") or "txt" name = row.get('file_name') or testdata_config.get( "FILE_NAME") or None if name: file_name = "%s_%s_%s.%s" % (file_prefix, name, i, file_txt) else: file_name = "%s_%s.%s" % (file_prefix, i, file_txt) file_size = row.get("file_size") or testdata_config.get( "FILE_SIZE") or 0 DataHelper.create_testfile(file_name, testdata_dir, int(file_size))
def get_mzdx_path(): download_path = ConfigAdapter.get_download_path().replace("\\\\", "\\") for file in os.listdir(download_path): if re.match(r'export_.*\.mzdx$', file): file = os.path.join(download_path, file) LogHelper.info("Get mzd target path: " + file) return file
def step_impl(context): winclient = Windows_Client(RUNNER_CONFIG.get('OEM_CLIENT', "mozypro")) result = winclient.controller.search_result_in_history() if result[0] == -9: LogHelper.info("backup is cancelled successfully") else: LogHelper.error("backup is cancelled unsuccessfully")
def verify_history(self): self.navigate_to() self.locate_element(self.xpaths['history_image']).click() assert self.locate_element(self.xpaths['history_image']).is_displayed() assert self.locate_element(self.xpaths['history_info']).is_displayed() LogHelper.info("History Info: " + self.locate_element(self.xpaths['history_info']).text) print("History Info: " + self.locate_element(self.xpaths['history_info']).text)
def worker_setup(task=None): try: LogHelper.info("Retrieve task to setup worker.") worker_info = ConfigHelper.load(os.path.dirname(__file__), "worker_info.yaml") return worker_info except SoftTimeLimitExceeded: return {}
def download_files(context): root_path = ConfigAdapter.get_testdata_path() output_path = ConfigAdapter.get_output_path(product='linux') for row in context.table.rows: raw_download_path = row.get('path') raw_download_output = row.get('output') raw_download_ext = row.get('extensions') #add other parameters args = {} download_path = os.path.join(root_path, raw_download_path) args['path'] = download_path if raw_download_output: download_output = os.path.join(output_path, raw_download_output) FileHelper.create_directory(download_output) args['output'] = download_output if raw_download_ext: args['extensions'] = raw_download_ext #TODO: add overwrite as condition args['overwrite'] = None output = LinuxGUIClient.download_cmd.download(**args) LogHelper.info(output)
def public_restore_flow(encrypt_type='default', encrypt_key=None): # If multiple restore jobs found, then automation will select the latest job to do the restore. # Below try catch is to process the multi-restore job scenarios try: MacFryrElement({'AXRole': 'AXRow'}, -1, 10).left_click() LogHelper.info("Multiple restore jobs found, automation will select the latest job to do the restore.") MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() except: LogHelper.info("Only one restore job found, automation will do restore with the default job.") MacFryrElement({'AXRole': 'AXRadioButton', 'AXDescription': 'selectNewLocationRadio'}).click() MacFryrElement({'AXValue': 'Documents'}).left_click() MacFryrElement({'AXIdentifier': '_NS:64'}).mouse_click({'AXValue': 'auto_restore'}) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:97'}).click() MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() if encrypt_type == 'pkey': MacFryrElement({'AXRole': 'AXTextField', 'AXIdentifier': '_NS:502'}).force_send(encrypt_key) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() elif encrypt_type == 'ckey' or encrypt_type == 'rkey': command = 'cp ' + os.path.dirname(os.path.dirname(__file__)) + '/' + encrypt_key + ' ' + ConfigAdapter.get_installer_path() CmdHelper.run(command) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:495'}).click() MacFryrElement({'AXIdentifier': '_NS:81'}).click() MacFryrElement({'AXTitle': 'Macintosh HD'}).click() MacFryrElement({'AXIdentifier': '_NS:64'}).mouse_click({'AXValue': 'fryr_installer'}) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:97'}).click() MacFryrElement({'AXIdentifier': '_NS:64'}).mouse_click({'AXValue': encrypt_key}) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:97'}).click() MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click()
def wait_state(self, state, timeout=None, granularity=None): """ :param state: :param timeout: :param granularity: :return: """ result = True if timeout is None: timeout = GLOBAL_CONFIG["TIMEOUT"] if granularity is None: granularity = GLOBAL_CONFIG["GRANULARITY"] expected_state = [] if type(state) == str: expected_state.append(state) else: expected_state = state current = self.current_state() elapsed = 0 while (current.upper() not in expected_state) and elapsed <= timeout: LogHelper.debug("current state is %s" % current) time.sleep(granularity) elapsed += granularity current = self.current_state() if current.upper() not in expected_state: LogHelper.error("wait %s failed" % expected_state) raise Exception("Expected Result %s is not shownup" % expected_state) return result
def click_button(btn_handle): #LogHelper.info('click button {}'.format(btn_handle.AXTitle)) try: btn_handle.Press() except ErrorCannotComplete as e: LogHelper.error(e.message) except Error as e: LogHelper.error(e.message)
def main(): # ----create log files for runner----- logger_path = ConfigAdapter.get_log_path() logfile = os.path.join(logger_path, PlatformHelper.get_ip_address(), "worker_logger.log") LogHelper.create_logger(logfile, fmt=PlatformHelper.get_ip_address() + " %(asctime)s %(levelname)s " + "worker" + " | %(message)s |") LogHelper.info("Worker %s" %(PlatformHelper.get_ip_address()))
def start_use_mozy(cls): try: Page.delayed_click(cls.xpaths['start_using_mozy_btn'], sleep_time=2) return True except Exception: LogHelper.error("Click Start Using Mozy Button failed.") # Page.quit() return False
def get_email(self): email = None account_str = self.get_account() account_dict = self.parse_account_to_dict(account_str) if account_dict.get("EMAIL"): email = account_dict["EMAIL"] LogHelper.debug(email) return email
def step_impl(context): is_installed = LinuxClient().controller.is_client_installed() LogHelper.info("Check Whether Linux Client Installed successfully") try: is_installed.should.equal(True) except AssertionError as e: LogHelper.error(e.message) raise e
def click_client_configuration(cls): try: Page.delayed_click(cls.xpaths['client_configuration_link'], sleep_time=2) return True except Exception: LogHelper.error("Click Client Configration link failed.") # Page.quit() return False
def check_md5(target1, target2): string1 = FileHelper.md5(target1) string2 = FileHelper.md5(target2) LogHelper.debug(target1 + " md5: " + string1) LogHelper.debug(target2 + " md5: " + string2) if string1 == string2: return True return False
def select_folder(self): try: Page.wait_for_element_list(self.xpaths['folderIcon']).click() return True except Exception: LogHelper.error("Select folder failed.") # Page.quit() return False