def restart(): cmd_output = "error: could not determine how to restart the daemon" if FileHelper.file_exist(LynxCtrl.service_path_upstart): cmd_output = LynxCtrl.restart_upstart() elif FileHelper.file_exist(LynxCtrl.service_path_initd): cmd_output = LynxCtrl.restart_initd() return cmd_output
def files_installed(cls, brand): path_app_support = "/Library/Application Support/{brand}".format( brand=brand) path_prefpane = "/Library/PreferencePanes/{brand}.prefPane".format( brand=brand) path_cache = "/Library/Caches/{brand}/cache.db".format(brand=brand) path_log = "/Library/Logs/{brand}.log".format(brand=brand) result = FileHelper.dir_exist( path_app_support) and FileHelper.dir_exist( path_prefpane) and FileHelper.file_exist( path_cache) and FileHelper.file_exist(path_log) return result
def step_impl(context, db): database_dir = LinuxClient().controller.config_db_dir state_db = os.path.join(database_dir, LinuxClient().controller.state_database) if FileHelper.file_exist(state_db): FileHelper.delete_file(state_db) metric_db = os.path.join(database_dir, LinuxClient().controller.metrics_database) if FileHelper.file_exist(metric_db): FileHelper.delete_file(metric_db) # config_db = LinuxClient().controller.config_database # if FileHelper.file_exist(config_db): # FileHelper.delete_file(config_db) context.execute_steps(unicode('When I restart Linux Client'))
def start(self): """ usage: start :return: """ cmd_output = "error: could not determine how to start the service" if FileHelper.file_exist(self.mozy_daemon): cmd_output = self.start_upstart() return cmd_output
def parse_feature(features, pattern="*.feature"): testfeatures = [] if FileHelper.file_exist(features) and FileHelper.file_ext(features) == "feature": testfeatures.append(features) else: files = FileHelper.find_file(features, pattern) # TODO: refine with FileHelper for file in files: testfeatures.append("features" + file.split("features")[1]) return testfeatures
def test_create_file(self): """ test: create test file """ testfile = "%s%s%s" %(TestFileHelper.testdatadir, os.path.sep, "testfilename") size = 2000 FileHelper.create_file(testfile, size=size ) result = FileHelper.file_exist(testfile) self.assertTrue(result) stat = FileHelper.get_file_stat(testfile) self.assertEqual(stat.st_size,size)
def is_client_installed(): """ usage: check whether linux client is installed :return: True if installed || False if not installed """ result = False if FileHelper.file_exist( LynxCtrl.service_path_upstart) or FileHelper.file_exist( LynxCtrl.service_path_initd): if FileHelper.dir_exist(LynxCtrl.conf_dir): if FileHelper.file_exist(LynxCtrl.mozyutil_daemon_path): result = True else: print "%s not present" % LynxCtrl.mozyutil_daemon_path else: print "%s not present" % LynxCtrl.conf_dir else: print "service control script not present at %s or %s" % ( LynxCtrl.service_path_initd, LynxCtrl.service_path_upstart) return result
def is_client_installed(self): """ usage: check whether windows client is installed :return: True if installed || False if not installed """ result = False if FileHelper.dir_exist(self.install_path) and FileHelper.file_exist(self.mozyutil) and FileHelper.file_exist(self.configapp) and FileHelper.file_exist(self.statusapp): result = True else: LogHelper.error("ERROR: %s is installed." % self.install_path) return result
def capture_worker_info(sender, instance, **kwargs): """ dump worker infomation whenever worker is connected """ info = PlatformHelper.get_platform_info() info['worker_name']='{0}'.format(sender) filename = os.path.join(os.path.dirname(__file__), "worker_info.yaml") if FileHelper.file_exist(filename): LogHelper.info("delete config file %s" % filename) FileHelper.delete_file(filename) data = dict((k.upper(), v) for k, v in info.items()) with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False)
def clean_conf(self): path = self.get_configuration_path() data_path = path + "conf.dat" print data_path if FileHelper.file_exist(data_path): db = SqliteHelper(data_path) db.execute("delete from rules") db.execute("delete from filesystem") db.execute("delete from fsitems") db.execute("delete from set_names") db.execute("delete from sets") db.close() else: LogHelper.error("ERROR:Could not find conf to reset. Terminating")
def search_history_result(path): data_path = path + "state.dat" print data_path if FileHelper.file_exist(data_path): db = SqliteHelper(data_path) statement = "select result from history where start_date in (select max(start_date) from history)" # print statement result = db.find(statement) print type(result) print result return result else: LogHelper.error( "ERROR:Could not find result to search. Terminating")
def download_fb( cls, product=None, dry_run=False, ): current_platform = PlatformHelper.get_system() fb_site = "https://artifacts.elastic.co/downloads/beats/filebeat/" package_name = "" if current_platform == "Linux" and PlatformHelper.get_arch( ) == "deb-64": package_name = 'filebeat-5.2.0-amd64.deb' if current_platform == "Linux" and PlatformHelper.get_arch( ) == "deb-32": package_name = 'filebeat-5.2.0-i386.deb' if current_platform == "Windows": package_name = 'filebeat-5.2.0-windows-x86_64.zip' if current_platform == "Darwin": package_name = 'filebeat-5.2.0-darwin-x86_64.tar.gz' installer_dir = ConfigAdapter.get_installer_path(product) cls.package_name = package_name installer_path = os.path.join(installer_dir, package_name) url = fb_site + package_name LogHelper.info("installer_path is " + installer_path) LogHelper.info("package url is " + url) if not FileHelper.dir_exist(installer_dir): FileHelper.create_directory(installer_dir) if FileHelper.file_exist(installer_path): FileHelper.delete_file(installer_path) if not dry_run: downloaded_package = urllib2.urlopen(url) LogHelper.info("download result is %s" % downloaded_package) with open(installer_path, 'wb') as output: output.write(downloaded_package.read()) return installer_path
def dump_options_to_config(filename="runner_config.yaml"): """ dump options dict to a yaml file :return: """ LogHelper.info("start to dump runner options to %s" % filename) if not filename.endswith(".yaml"): filename = filename + ".yaml" config_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "configuration")) config_file = os.path.join(config_dir, filename) if FileHelper.file_exist(config_file): LogHelper.info("delete config file %s" % config_file) FileHelper.delete_file(config_file) data = dict((k.upper(), v) for k, v in options.__dict__.items()) with open(config_file, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False)
def __mount_image(cls, image_path): LogHelper.debug("check that package is existed") if not FileHelper.file_exist(image_path): raise StandardError( 'file {package} is not existed'.format(package=image_path)) LogHelper.debug("mount dmg") mount_cmd = MacController.prefix_for_sudo( ) + 'sudo -S hdiutil attach {package}'.format(package=image_path) output = CmdHelper.run(mount_cmd) LogHelper.debug("mount result is {output}".format(output=output)) mounted_volumes = cls.__find_mounted_volume(pattern='.*MozyPro.*') if len(mounted_volumes) > 1: LogHelper.error( "More than one volume deteched, something went wrong") mounted_volume = mounted_volumes[-1] return mounted_volume
def activate_linux_client(context): for row in context.table.rows: email_raw = row.get('email') or row.get('username') password = row.get('password') customkeytext = row.get('customkeytext') password_file = row.get('password_file') #TODO: add other parameters regex = re.match(r"{env}_{oemclient}_?.*", email_raw) if regex: cre_with_oc = re.sub(r"{oemclient}", RUNNER_CONFIG.get('OEM_CLIENT'), email_raw) cre_with_oc_env = re.sub(r"{env}", RUNNER_CONFIG.get('ENVIRONMENT'), cre_with_oc) expected_credential = LYNX_CONFIG.get('CREDENTIAL').get( cre_with_oc_env) email = expected_credential.get('USERNAME') password_correct = expected_credential.get('PASSWORD') else: email = email_raw kargs = {} if email: kargs['email'] = email if password: kargs['password'] = password if password_file and password_file.upper() == "VALID": password_file_path = os.path.join(LYNX_CONFIG.get('TMP_PATH'), "password.txt") FileHelper.delete_file(password_file_path) if FileHelper.file_exist(password_file_path): FileHelper.delete_file(password_file_path) with open(password_file_path, "w") as text_file: text_file.write(password_correct) kargs['password-file'] = password_file_path if password_file and password_file.upper() == "INVALID": password_file_path = os.path.join(LYNX_CONFIG.get('TMP_PATH'), "wrong_password.txt") if FileHelper.file_exist(password_file_path): FileHelper.delete_file(password_file_path) with open(password_file_path, "w") as text_file: text_file.write( "{password}_wrong".format(password=password_correct)) kargs['password-file'] = password_file_path if customkeytext: kargs['customkeytext'] = customkeytext kargs['force_encryption_change'] = None output = LinuxGUIClient.activate_cmd.activate(**kargs) LogHelper.info("activate output is %s" % output)
def run(): if options.database_enabled: id = testrun.upper()+start_time.replace(":", "_").replace("-", "_") tr = TestRun(id, start_time, qa_env=options.environment, build=options.build, client=options.product, oem=options.oem_client, branch=options.job, runby="*****@*****.**") LogHelper.debug("Start to write TestRun to ES") tr.save_to_elasticsearch() LogHelper.debug("Finish to write TestRun to ES") create_runner_log() verify_options() if product == 'MAC_MACFRYR': LogHelper.debug("MAC_MACFRYR Test Case") mac_client = NativeClientFactory.get_client(product='MAC', oem=oem_client) if build: mac_client.installer.download_and_install(build[0], job[0]) mac_client.controller.prepare_environment(environment) macfryr_client = NativeClientFactory.get_client(product='MACFRYR', oem=oem_client) if build: macfryr_client.installer.download_and_install(build[1], job[1]) macfryr_client.controller.prepare_environment(environment) LogHelper.info('Install MacFryr Client') LogHelper.info('Prepare MacFryr Client Environment') elif product == 'WINDOWS_WINFRYR': LogHelper.debug("WINDOWS_WINFRYR Test Case") win_client = NativeClientFactory.get_client(product='WINDOWS', oem=oem_client) LogHelper.info('Load Configuration') if build: win_client.installer.download_and_install(build[0], job[0]) win_client.controller.prepare_environment(environment) LogHelper.info('Install WINDOWS Client') LogHelper.info('Prepare WINDOWS Client Environment') winfryr_client = NativeClientFactory.get_client(product='WINFRYR', oem=oem_client) if build: winfryr_client.installer.download_and_install(build[1], job[1]) winfryr_client.controller.prepare_environment(environment) LogHelper.info('Install WINFRYR Client') LogHelper.info('Prepare WINFRYR Client Environment') elif product == 'MTS': LogHelper.info("No need to install anything to test against MTS.") #TODO else: LogHelper.info("Standalone app ") native_client = NativeClientFactory.get_client(product=product, oem=oem_client) if build: native_client.installer.download_and_install(build, job) native_client.controller.prepare_environment(environment) dump_options_to_config() if options.taskid: print ("update task record after execution") CeleryHelper.update_task_status(options.taskid, testrun, result='STARTED') behave_cmd = "behave %s --no-capture --no-capture-stderr" % features LogHelper.info(behave_cmd) if options.tags: behave_cmd += " --tags %s" %(options.tags) dry_run = options.dry_run if dry_run: behave_cmd += ' --dry-run' output = CmdHelper.run(behave_cmd) print output if options.database_enabled: # TestRun Finish. tr.end_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) tr.save_to_elasticsearch() rerun_failed = options.rerun if rerun_failed and FileHelper.file_exist("rerun_failing.features"): LogHelper.info('Rerun failed feature') behave_cmd = "behave @rerun_failing.features" behave_output = CmdHelper.run(behave_cmd) print behave_output final_result = 'COMPLETED' if options.taskid: LogHelper.debug("update task status in databsae") CeleryHelper.update_task_status(options.taskid, testrun, result=final_result) time.sleep(2) LogHelper.debug("check testrun status") query_body = { "query": { "bool": { "must": [ { "match": { "testrun_id": testrun } } ], "must_not": [ { "match": { "status": final_result } } ] } } } result = ElasticsearchHelper().search_document(index='task', doc_type='task', body=query_body) uncompleted_tasks = result.get('hits').get('total') LogHelper.debug("%d tasks is uncompleted" % uncompleted_tasks) if uncompleted_tasks == 0: print "all tasks are completed" LogHelper.debug("all tasks are done for testrun %s" % testrun) output = CeleryHelper.detach_from_queue(testrun) print output LogHelper.debug(output)
def clear_config(self): if FileHelper.file_exist(self.config_database): FileHelper.delete_file(self.config_database) if FileHelper.file_exist(self.state_database): FileHelper.delete_file(self.state_database)
def stop(self): cmd_output = "error: could not determine how to stop the service" if FileHelper.file_exist(self.mozy_daemon): cmd_output = self.stop_upstart() return cmd_output