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 decrypt_files(context, source, dest): source_root = ConfigAdapter.get_installer_path('LINUX') source_full_path = os.path.join(source_root, source) LogHelper.info("Decrypt src {source}".format(source=source_full_path)) dest_root = ConfigAdapter.get_output_path('LINUX') dest_full_path = os.path.join(dest_root, dest) FileHelper.create_directory(dest_full_path, True) output = LinuxGUIClient.decrypt_cmd.decrypt(source_full_path, dest_full_path) LogHelper.info("Decrypt output {output}".format(output=output))
def stem_impl(context, output_dir): root_path = ConfigAdapter.get_installer_path(product='linux') output_path = os.path.join(ConfigAdapter.get_output_path(product='linux'), output_dir) for mzd_file in FileHelper.find_file(root_path, "*.mzd"): LogHelper.info('restore mzd file %s to %s' % (mzd_file, output_path)) FileHelper.create_directory(output_path) LinuxGUIClient.download_cmd.download(mzd=mzd_file, output=output_path, overwrite=None)
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 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_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 download_from_mozy(pattern): dl = Download_Helper(GLOBAL_CONFIG["MOZY.COM"]["URL2"]) dest = ConfigAdapter.get_installer_path(product='LINUX') packages = [] packages.append( dl.download_package(dl.get_download_url(pattern), dest=dest)) return packages
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 __get_downloaded_image(cls): result = None import glob installer_path = ConfigAdapter.get_installer_path(product='MAC') build = RUNNER_CONFIG.get("BUILD") images = glob.glob(installer_path + '/*{build}*.dmg'.format(build=build)) if len(images) != 0: # == 0: # raise StandardError('Package was not downloaded successfully') result = images[0] else: job = RUNNER_CONFIG.get("JOB") if job is None or job == 'null': job = cls.default_job brand = RUNNER_CONFIG.get("OEM_CLIENT") if brand is None or brand == 'null': pattern = cls.default_pattern else: pattern = ".*" + MacController.normalize_brand_name( brand) + ".*" packages = cls.download_package(job, build, pattern) if len(packages) != 0: result = packages[0] return result
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_archive_name(): download_path = ConfigAdapter.get_installer_path() for file in FileHelper.find_file(download_path, '*'): file = os.path.basename(file) pattern = r'restore_(.+?).zip' if re.match(pattern, file): return file
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 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 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 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 download_and_install(cls, build, job): volume_name = cls.get_subdir() if volume_name is not None: CmdHelper.run("diskutil eject '" + volume_name + "'") LogHelper.info( "Prepare download Mozy Restore Manager from jenkins, build number is " + job) jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"], GLOBAL_CONFIG["JENKINS"]["USERNAME"], GLOBAL_CONFIG["JENKINS"]["KEY"]) dest = ConfigAdapter.get_installer_path('MACFRYR') LogHelper.info('Clean up existing files') for file in FileHelper.find_file(dest, '*'): LogHelper.debug('Delete file %s' % file) FileHelper.delete_file(file) pattern = 'mozy-fryr' packages = jh.download_packages(jh.get_packages(job, build, pattern), dest=dest) TARGET_APP = '/Applications/Mozy Restore Manager.app' if os.path.exists(TARGET_APP): shutil.rmtree(TARGET_APP) image_path = packages[0] mount_cmd = 'sudo hdiutil attach {package}'.format(package=image_path) CmdHelper.run(mount_cmd) volume_name = cls.get_subdir() ORIGIN_APP = '/Volumes/' + volume_name + '/Mozy Restore Manager.app' shutil.copytree(ORIGIN_APP, TARGET_APP)
def download(job, build, pattern): jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"], GLOBAL_CONFIG["JENKINS"]["USERNAME"], GLOBAL_CONFIG["JENKINS"]["KEY"]) dest = ConfigAdapter.get_installer_path(product='LINUX') return jh.download_packages(jh.get_packages(job, build, pattern), dest=dest)
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 get_archive_path(): download_path = ConfigAdapter.get_installer_path().replace( "\\\\", "\\") for file in os.listdir(download_path): if re.match(r'.*\.zip$', file): file = os.path.join(download_path, file) LogHelper.info("Get archive target path: " + file) return file
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 step_impl(context): winclient = Windows_Client(RUNNER_CONFIG.get('OEM_CLIENT', "mozypro")) import time time.sleep(10) winclient.gui.restore_panel.select_restore_by_date( ConfigAdapter.get_output_path()) winclient.gui.restore_panel.startrestore() winclient.gui.restore_panel.apply()
def before_scenario(context, scenario): testrun = RUNNER_CONFIG.get('TESTRUN') or 'testrun' context.log_starttime = strftime("%Y-%m-%dT%H:%M:%SZ", localtime()) start_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) hostname = PlatformHelper.get_hostname() ip = PlatformHelper.get_ip_address() product = RUNNER_CONFIG.get("PRODUCT") build = RUNNER_CONFIG.get('BUILD') context.senddb = RUNNER_CONFIG.get('DATABASE_ENABLED') context.env = RUNNER_CONFIG.get('ENVIRONMENT') logger_path = os.path.join(ConfigAdapter.get_log_path(), testrun) tc_prefix = ConfigAdapter.get_testlink_prefix(product) match = filter(lambda x: x.find(tc_prefix) >= 0, scenario.tags) if len(match)>0: # differentiate scenarios in scenario outline if hasattr(context, 'active_outline') and type(context.active_outline) == behave.model.Row: suffix = match.pop() for example_key in context.active_outline: suffix += ".%s" % (example_key) tc_id = testrun + "_" + suffix else: tc_id = testrun + "_" + match.pop() else: #no test link project id foud tc_id = hashlib.md5(testrun + "_" + scenario.name.encode()).hexdigest() if not FileHelper.dir_exist(logger_path): FileHelper.create_directory(logger_path) logger_filename = "%s.log" % (tc_id) logfile = os.path.join(logger_path, logger_filename) client_ip = PlatformHelper.get_ip_address() LogHelper.create_logger(logfile, fmt=client_ip+" %(asctime)s %(levelname)s " + product+" | %(message)s |") tc = TestCase(testrun=testrun, start_time=start_time, hostname=hostname, product=product, ip=ip, summary=scenario.name, feature=scenario.filename, tags=scenario.tags, logfile=logfile, _id=tc_id, build=build) context.tc = tc LogHelper.info("test start: " + scenario.name)
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): 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 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, 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 decrypt_tar(context, dest): source_root = ConfigAdapter.get_installer_path('LINUX') source_full_path = source_root # for file in os.listdir(source_root): # print(file) # if re.match(r'.*\.tar$', file): # source_full_path = os.path.join(source_root, file) tars = FileHelper.find_file(source_root, "*.tar") LogHelper.info(tars[-1]) for file in tars: LogHelper.info(file) source_full_path = os.path.join(source_root, file) # source_full_path = os.path.join(source_root,source) LogHelper.info("Decrypt src: {source}".format(source=source_full_path)) dest_root = ConfigAdapter.get_output_path('LINUX') dest_full_path = os.path.join(dest_root, dest) FileHelper.create_directory(dest_full_path, True) output = LinuxGUIClient.decrypt_cmd.decrypt(source_full_path, dest_full_path) LogHelper.info("Decrypt output {output}".format(output=output))