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 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 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_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 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 wait_for_download_complete(): time.sleep(10) # This is to wait the download process to start download_path = ConfigAdapter.get_testdata_path().replace("\\\\", "\\") temp_file = '' for file in os.listdir(download_path): if re.match(r'restore_.*\.part$', file): temp_file = os.path.join(download_path, file) if temp_file == '': # KPIHelper.log_error(category="Web", kpiname="Download", result="SUCCESS", message="Download Completed.") LogHelper.info('Download Completed!') return True else: time.sleep(5) for i in range(100): if os.path.isfile(temp_file): time.sleep(4) else: # KPIHelper.log_error(category="Web", kpiname="Download", result="SUCCESS", message="Download Completed.") LogHelper.info('Download Completed!') return True # KPIHelper.log_error(category="Web", kpiname="Download", result="Fail", message="Timeout.") LogHelper.error('ERROR: Download Failed!') return False
def step_impl(context, number): LogHelper.info("start to create files") testdata_config = ConfigAdapter.get_testdata_pros() testdata_root = ConfigAdapter.get_testdata_path() testdata_dir = testdata_root file_size = 0 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)) context.file_size = file_size
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 step_impl(context): root_path = ConfigAdapter.get_testdata_path() actual_results = LinuxGUIClient.backupset_cmd.list_allfiles() LogHelper.info( "listallfiles result {result}".format(result=actual_results)) for row in context.table.rows: expected_value = row.get('paths') or row.get('path') expected_file = os.path.join(root_path, expected_value) LogHelper.info("checking " + expected_file) actual_results.shouldnot.have(expected_file)
def step_impl(context): #Generate dir full path LogHelper.info('Generate directory full path') root = ConfigAdapter.get_testdata_path() for row in context.table: dir_name = row.get('entity') full_path = os.path.join(root, dir_name) #remve unwanted empty string drill_down_list = filter(lambda x: len(x) > 0, full_path.split(os.path.sep)) if RUNNER_CONFIG.get('PRODUCT').upper() in ('MAC', "LINUX", 'MAC_MACFRYR'): drill_down_list.insert(0, os.path.sep) # Drill down folders result = FreyjaPage.drill_down_folders(drill_down_list[0:-1]) try: (result).should.be(True) except AssertionError: LogHelper.error("Frejya fail to Expand folder.") FreyjaPage.quit() else: # Select folder checkbox result = FreyjaPage.check_entity(full_path) try: (result).should.be(True) except AssertionError: LogHelper.error("Frejya fail to check folder checkbox.") FreyjaPage.quit() else: context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Create MZD", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = FreyjaPage.create_mzd() try: (result).should.be(True) except AssertionError: context.kpi.message = "Frejya fail to create MZD." FreyjaPage.quit() else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None Page.quit()
def step_impl(context, file_path): testdata_root = ConfigAdapter.get_testdata_path() full_file_path = os.path.join(testdata_root, file_path) last_version = LinuxGUIClient.info_cmd.get_last_remote_info( full_file_path, True) LogHelper.info("lastest version for %s is %s" % (full_file_path, last_version)) if last_version is not None: last_version.get('DELETE').should.be('Y') else: last_version.should.be(None)
def step_impl(context): """ Useage list backupdirs and check backup dirs from listbackupdirs """ 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('check path for %s' % full_path) dirs = LinuxGUIClient().listbackupdir_cmd.listbackupdirs() dirs.should.contain(full_path)
def step_impl(context): root_path = ConfigAdapter.get_testdata_path('MAC') raw_path = '' rule_name = '' for row in context.table: rule_name = row.get('name') or 'default_backupset' raw_path = row.get('path') or '' #TODO: add more fields there path = os.path.join(root_path, raw_path) backuprule = BackupRule(name=rule_name, path=path) MacCliClient.rule_cmd.remove_all_rules() MacCliClient.rule_cmd.add_rule(backuprule)
def clear_download_folder(): directory = ConfigAdapter.get_installer_path('MACFRYR') if platform.system() == "Windows": directory = "C:/" + ConfigAdapter.get_testdata_path( 'WINFRYR').split('\\\\')[1] for file in FileHelper.find_file(directory, '*'): LogHelper.debug('Delete file %s' % file) os.remove(file) for folder in FileHelper.find_dir(directory, '*'): LogHelper.debug('Delete folder %s' % folder) try: shutil.rmtree(folder) except: pass
def step_impl(context, raw_path, raw_output): LogHelper.info("start to download %s to %s" % (raw_path, raw_output)) root_path = ConfigAdapter.get_testdata_path() path = os.path.join(root_path, raw_path) root_output = ConfigAdapter.get_output_path() output = os.path.join(root_output, raw_output) LogHelper.info("start to download %s to %s" % (path, output)) if FileHelper.dir_exist(output): FileHelper.delete_directory(output) FileHelper.create_directory(output) result = LinuxGUIClient.download_cmd.download(path=path, output=output, overwrite=None) LogHelper.info(result)
def step_impl(context, location): if location == 'backup': LogHelper.info("start to clean backup folder") testdata_root = ConfigAdapter.get_testdata_path() testdata_dir = testdata_root FileHelper.delete_directory(testdata_dir) elif location == 'restore': LogHelper.info("start to clean restore folder") testdata_root = ConfigAdapter.get_restore_path() testdata_dir = testdata_root FileHelper.delete_directory(testdata_dir) elif location == 'output': testdata_root = ConfigAdapter.get_output_path() testdata_dir = testdata_root LogHelper.info("start to clean output folder: %s" % testdata_dir) FileHelper.delete_directory(testdata_dir)
def before_tag(context, tag): if tag == "cleanup": testdata = ConfigAdapter.get_testdata_path() output = ConfigAdapter.get_output_path() installer_path = ConfigAdapter.get_installer_path() FileHelper.delete_directory(testdata) FileHelper.delete_directory(output) FileHelper.delete_directory(installer_path) if tag == "cleandownload": downloadpath = ConfigAdapter.get_output_path() FileHelper.delete_directory(downloadpath) if tag == "mac_setup": MacCliClient().rule_cmd.remove_all_rules() MacController().restart_mozypro_pid()
def step_impl(context): LogHelper.info("start to overwrite files") testdata_root = ConfigAdapter.get_testdata_path() for row in context.table: testdata_dir = os.path.join(testdata_root, row.get('file_folder')) testdatas = FileHelper.find_file(testdata_dir, '*') max_size = int(row.get('maxsize')) min_size = int(row.get('minsize')) length = random.randrange(min_size, max_size) for testdata in testdatas: offset_pattern = row.get('offset_pattern') if offset_pattern == 'random': size = FileHelper.file_size(testdata) offset = random.randrange(1, size) elif offset_pattern.isdigit(): size = FileHelper.file_size(testdata) offset = min(int(offset_pattern), size) FileHelper.overwrite_file_random(testdata, offset, length)
def step_impl(context): step_str = 'When I visit "Files & Folders" tab' context.execute_steps(unicode(step_str)) # MacCliClient().rule_cmd.remove_all_rules() files_folder_tab = MacGUIClient().files_folder_tab files_folder_tab.click_advance_button() testdata_root = ConfigAdapter.get_testdata_path() for row in context.table: files_folder_tab.show_add_files_browser() time.sleep(1) files_folder_tab.select_root_dest() time.sleep(1) entity = row.get('include_dirs') or row.get('include_files') backup_full_path = os.path.join(testdata_root, entity) from lib.filehelper import FileHelper w_time = 60 while not FileHelper.dir_exist(backup_full_path) and w_time > 0: w_time -= 5 files_folder_tab.select_backupdir(backup_full_path) files_folder_tab.click_OK_button()
def step_impl(context): testdata_root = ConfigAdapter.get_testdata_path() testdata_config = ConfigAdapter.get_testdata_pros() for row in context.table.rows: if "file_folder" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_folder') or '') elif "file_dir" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_dir') or '') length = row.get('length') or testdata_config.get("FILE_SIZE") or 10 length = int(length) pattern = row.get('content') or 'random' testdatas = FileHelper.find_file(testdata_dir, '*') for testdata in testdatas: LogHelper.info("Patch test files %s %d %s" % (testdata, length, pattern)) FileHelper.append_file_content(testdata, length, pattern)
def delete_test_files(context, params): testdata_root = ConfigAdapter.get_testdata_path() for row in context.table.rows: if "file_folder" in row.headings or "file_dir" in row.headings: testdata_dir = os.path.join( testdata_root, row.get('file_folder') or row.get('file_dir') or '') if params.upper() == "DIRS": LogHelper.debug("Delete dirs " + testdata_dir) FileHelper.delete_directory(testdata_dir) return if params.upper() == "FILES": pattern = row.get('pattern') or '*' file_list = FileHelper.find_file(testdata_dir, pattern) for file in file_list: LogHelper.debug("delete file %s" % file) FileHelper.delete_file(file) return
def step_impl(context, file_path, is_changed): testdata_root = ConfigAdapter.get_testdata_path() full_file_path = os.path.join(testdata_root, file_path) current_vesion = LinuxGUIClient.info_cmd.get_last_version(full_file_path) LogHelper.info( "current version is {version}".format(version=current_vesion)) if is_changed.upper() == "UNCHANGED": current_vesion.should.equal(context.version_before) if is_changed.upper() == 'CHANGED': #Check whether linux client is running at conntinous mode or manual mode current_mode = LinuxGUIClient.continuous_cmd.get_mode() if current_mode == LinuxGUIClient.continuous_cmd.ON_DEMAND: LogHelper.debug("On demand mode, check version...") current_vesion.shouldnot.eql(context.version_before) if current_mode == LinuxGUIClient.continuous_cmd.CONTINUOUS: LogHelper.debug( "On continous mode, wait a new version with 300 second") if current_vesion != context.version_before: is_version_changed = True else: is_version_changed = False eslapsed_time = 0 wait_time = 10 while (not is_version_changed) and eslapsed_time <= 300: time.sleep(wait_time) eslapsed_time += wait_time current_vesion = LinuxGUIClient.info_cmd.get_last_version( full_file_path) if current_vesion != context.version_before: is_version_changed = True else: LogHelper.info("Current version is %s, it is same as %s" % (current_vesion, context.version_before)) is_version_changed.should.be(True)
def step_impl(context): root_path = ConfigAdapter.get_testdata_path() expected_paths = [] actual_paths = [] dumpall_output = LinuxGUIClient.backupset_cmd.dumpall() for line in dumpall_output.splitlines(): if line.lstrip().startswith('+'): actual_paths.append(unicode(line)) for row in context.table.rows: path = row.get('paths') full_path = path.replace('{root}', root_path) expected_paths.append(full_path) LogHelper.info("Check paths account...") len(actual_paths).should.be(len(expected_paths)) LogHelper.info("check each item ") for path in expected_paths: LogHelper.info('Checking path {path}'.format(path=path)) actual_paths.should.have(path)
def step_impl(context, restore_dir, backup_dir): testdata_root = ConfigAdapter.get_testdata_path() output_root = ConfigAdapter.get_output_path() restore_file_path = os.path.join(output_root, restore_dir) backup_file_path = os.path.join(testdata_root, backup_dir) LogHelper.info('restore_file_path is {0}'.format(restore_file_path)) LogHelper.info('backup_file_path is {0}'.format(backup_file_path)) if PlatformHelper.is_mac(): result = FileHelper.is_dir_same(restore_file_path, backup_file_path, exclude_pattern='.DS_Store') else: result = FileHelper.is_dir_same(restore_file_path, backup_file_path) if result: for diff in result: LogHelper.error("diff files found {path}".format(path=diff)) try: len(result).should.equal(0) except AssertionError as e: LogHelper.error(e.message) raise e
def step_impl(context): #Generate dir full path LogHelper.info('Generate directory full path') root = ConfigAdapter.get_testdata_path() for row in context.table: dir_name = row.get('entity') full_path = os.path.join(root, dir_name) #remve unwanted empty string drill_down_list = filter(lambda x: len(x) > 0, full_path.split(os.path.sep)) if RUNNER_CONFIG.get('PRODUCT').upper() in ('MAC', "LINUX", 'MAC_MACFRYR'): drill_down_list.insert(0, os.path.sep) try: starttime = datetime.datetime.now() result = FreyjaPage.drill_down_folders(drill_down_list[0:-1]) endtime = datetime.datetime.now() expand_folder_time = (endtime - starttime).seconds context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Direct Download", result="Fail", message="Expand file: %s" % expand_folder_time, hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) LogHelper.info("Expand file complete.") (result).should.be(True) except AssertionError: context.kpi.write_to_elasticsearch(context.senddb) FreyjaPage.quit() else: cb_target = '//tr[contains(@id, "{entity_name}")]//span[contains(@class, "check")]'.format( entity_name=drill_down_list[-1]) FreyjaPage.locate_element(cb_target, 30).click() #FreyjaPage.check_entity(drill_down_list[-1]) # context.execute_steps(unicode('When I log web "Frejya Direct Download" KPI start time')) context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Direct Download", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = FreyjaPage.download_now() try: (result).should.be(True) except AssertionError: context.kpi.message = "Frejya fail to direct download." else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None Page.quit()
def step_impl(context, number): LogHelper.info("start to judge whether to create files") testdata_config = ConfigAdapter.get_testdata_pros() testdata_root = ConfigAdapter.get_testdata_path() testdata_dir = testdata_root file_size = 0 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')) if not FileHelper.dir_exist(testdata_dir): FileHelper.create_directory(testdata_dir) if not FileHelper.get_file_count_in_dir(testdata_dir) == int(number): FileHelper.delete_file(testdata_dir) for row in context.table: 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)) context.file_size = file_size else: for row in context.table: length = row.get('length') or testdata_config.get( "FILE_SIZE") or 10 length = int(length) size = row.get('file_size') or testdata_config.get("FILE_SIZE") pattern = row.get('content') or 'random' testdatas = FileHelper.find_file(testdata_dir, '*') patch_method = row.get('patch_method') if patch_method == "append": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) FileHelper.append_file_content(testdata, length, pattern) elif patch_method == "truncate": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) FileHelper.truncate_file(testdata, length) elif patch_method == "insert": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) size_offset = random.randrange(1, size) FileHelper.insert_file_content(testdata, size_offset, length, pattern)
def step_impl(context): LinuxGUIClient.backupset_cmd.clear_backup_set() root_path = ConfigAdapter.get_testdata_path() for row in context.table: paths = [] excludes = [] filenames = [] exclude_filenames = [] filetypes = [] exclude_filetypes = [] backupset_name = row.get('name') or 'default_backupset' raw_paths = row.get('paths') or '' raw_excludes = row.get('excludes') or '' exclusionary = row.get('exclusionary') or 'False' raw_filenames = row.get('filenames') # filenames rule raw_exclude_filenames = row.get('exclude_filenames') raw_filetypes = row.get('filetypes') raw_exclude_filetypes = row.get('exclude_filetypes') for relative_path in re.split(r",|;|:", raw_paths): paths.append( os.path.join(root_path, relative_path.strip().lstrip())) if raw_excludes: for relative_path in re.split(r",|;|:", raw_excludes): excludes.append( os.path.join(root_path, relative_path.strip().lstrip())) if raw_filenames: for each_filename in re.split(r",|;|:", raw_filenames): filenames.append(each_filename) if raw_exclude_filenames: for each_exclude_filename in re.split(r",|;|:", raw_exclude_filenames): exclude_filenames.append(each_exclude_filename) if raw_filetypes: for each_filetype in re.split(r",|;|:", raw_filetypes): filetypes.append(each_filetype) if raw_exclude_filetypes: for each_exclude_filetype in re.split(r",|;|:", raw_exclude_filetypes): exclude_filetypes.append(each_exclude_filetype) LogHelper.info("add backupset {name} {paths} {excludes}".format( name=backupset_name, paths=paths, excludes=excludes)) bs = Backupset(name=backupset_name, paths=paths, excludes=excludes, exclusionary=exclusionary, filenames=filenames, exclude_filenames=exclude_filenames, filetypes=filetypes, exclude_filetypes=exclude_filetypes) bs.generate_json_file(filename=backupset_name) if LinuxGUIClient.continuous_cmd.get_mode( ) == LinuxGUIClient.continuous_cmd.ON_DEMAND: LogHelper.info("refresh backupset for on-demand mode") re_try = 3 while re_try > 0: output = LinuxGUIClient.backupset_cmd.refresh() LogHelper.info(output) if output.upper().find("SUCCEED") == -1: LogHelper.warn("Refresh looks failed") LogHelper.debug("re-try refresh after 5 seconds") time.sleep(5) re_try -= 1 else: LogHelper.info("Refresh success") break
def step_impl(context, file_path): testdata_root = ConfigAdapter.get_testdata_path() full_file_path = os.path.join(testdata_root, file_path) last_version = LinuxGUIClient.info_cmd.get_last_remote_info( full_file_path, True) last_version.should.be(None)