Best Python code snippet using yandex-tank
consoleworker.py
Source:consoleworker.py
...44 """ required for non-tty python runs to interrupt """45 raise KeyboardInterrupt()46signal.signal(signal.SIGINT, signal_handler)47signal.signal(signal.SIGTERM, signal_handler)48def apply_shorthand_options(config, options, default_section='DEFAULT'):49 """50 :type config: ConfigParser51 """52 if not options:53 return config54 for option_str in options:55 key, value = option_str.split('=')56 try:57 section, option = key.split('.')58 except ValueError:59 section = default_section60 option = key61 if not config.has_section(section):62 config.add_section(section)63 config.set(section, option, value)64 return config65def load_ini_cfgs(config_files):66 config_filenames = [resource_manager.resource_filename(config) for config in config_files]67 cfg = RawConfigParser()68 cfg.read(config_filenames)69 dotted_options = []70 if cfg.has_section('tank'):71 for option, value in cfg.items('tank'):72 if '.' in option:73 dotted_options += [option + '=' + value]74 else:75 cfg.add_section('tank')76 cfg = apply_shorthand_options(cfg, dotted_options)77 cfg.set('tank', 'pid', str(os.getpid()))78 return cfg79def get_default_configs():80 """ returns default configs list, from /etc and home dir """81 # initialize basic defaults82 configs = [resource_filename(__name__, 'config/00-base.ini')]83 baseconfigs_location = '/etc/yandex-tank'84 try:85 conf_files = sorted(os.listdir(baseconfigs_location))86 for filename in conf_files:87 if fnmatch.fnmatch(filename, '*.ini'):88 configs += [89 os.path.realpath(90 baseconfigs_location + os.sep + filename)91 ]92 except OSError:93 logger.info(94 baseconfigs_location + ' is not accessible to get configs list')95 configs += [os.path.expanduser('~/.yandex-tank')]96 return configs97def get_depr_cfg(config_files, no_rc, cmd_options, depr_options):98 try:99 all_config_files = []100 if not no_rc:101 all_config_files = get_default_configs()102 if not config_files:103 if os.path.exists(os.path.realpath('load.ini')):104 all_config_files += [os.path.realpath('load.ini')]105 elif os.path.exists(os.path.realpath('load.conf')):106 # just for old 'lunapark' compatibility107 conf_file = os.path.realpath('load.conf')108 all_config_files += [conf_file]109 else:110 for config_file in config_files:111 all_config_files.append(config_file)112 cfg_ini = load_ini_cfgs([cfg_file for cfg_file in all_config_files if is_ini(cfg_file)])113 # substitute telegraf config114 def patch_ini_config_with_monitoring(ini_config, mon_section_name):115 """116 :type ini_config: ConfigParser117 """118 CONFIG = 'config'119 telegraf_cfg = ini_config.get(mon_section_name, CONFIG)120 if not telegraf_cfg.startswith('<') and not telegraf_cfg.lower() == 'auto':121 with open(resource_manager.resource_filename(telegraf_cfg), 'rb') as telegraf_cfg_file:122 config_contents = telegraf_cfg_file.read()123 ini_config.set(mon_section_name, CONFIG, config_contents)124 return ini_config125 try:126 cfg_ini = patch_ini_config_with_monitoring(cfg_ini, 'monitoring')127 except (NoSectionError, NoOptionError):128 try:129 patch_ini_config_with_monitoring(cfg_ini, 'telegraf')130 except (NoOptionError, NoSectionError):131 pass132 for section, key, value in depr_options:133 if not cfg_ini.has_section(section):134 cfg_ini.add_section(section)135 cfg_ini.set(section, key, value)136 return apply_shorthand_options(cfg_ini, cmd_options)137 except Exception as ex:138 sys.stderr.write(RealConsoleMarkup.RED)139 sys.stderr.write(RealConsoleMarkup.RESET)140 sys.stderr.write(RealConsoleMarkup.TOTAL_RESET)141 raise ex142class ConsoleWorker(Thread, TankWorker):143 def __init__(self, configs, cli_options=None, cfg_patches=None, cli_args=None, no_local=False,144 log_handlers=None, wait_lock=False, files=None, ammo_file=None, debug=False):145 Thread.__init__(self)146 TankWorker.__init__(self, configs=configs, cli_options=cli_options, cfg_patches=cfg_patches,147 cli_args=cli_args, no_local=no_local, log_handlers=log_handlers,148 wait_lock=wait_lock, files=files, ammo_file=ammo_file, debug=debug)149 self.daemon = True150 self.status = Status.TEST_INITIATED...
apiworker.py
Source:apiworker.py
...48 logger.addHandler(stderr_hdl)49 def __add_user_options(self):50 """ override config options with user specified options"""51 if self.options.get('user_options', None):52 self.core.apply_shorthand_options(self.options['user_options'])53 def configure(self, options):54 """ Make preparations before running Tank """55 self.options = options56 if self.options.get('lock_dir', None):57 self.core.set_option(58 self.core.SECTION, "lock_dir", self.options['lock_dir'])59 while True:60 try:61 self.core.get_lock(self.options.get('ignore_lock', None))62 break63 except Exception as exc:64 if self.options.get('lock_fail', None):65 raise RuntimeError("Lock file present, cannot continue")66 self.log.info(...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!