Best Python code snippet using yandex-tank
cli.py
Source:cli.py
...56 lp_job.push_test_data(data['data'], data['stats'])57 sys.stdout.write('.')58 sys.stdout.flush()59 sys.stdout.write('\n')60def upload_monitoring(shooting_dir, log_name, lp_job):61 data_log = os.path.join(shooting_dir, log_name)62 check_log(data_log)63 sys.stdout.write('Uploading monitoring data')64 with open(data_log, 'r') as f:65 for line in f:66 lp_job.push_monitoring_data(line.strip())67 sys.stdout.write('.')68 sys.stdout.flush()69 sys.stdout.write('\n')70def send_config_snapshot(config, lp_job):71 config.set(SECTION, 'launched_from', 'post-loader')72 output = StringIO()73 config.write(output)74 lp_job.send_config_snapshot(output.getvalue())75def edit_metainfo(lp_config, lp_job):76 lp_job.edit_metainfo(is_regression=lp_config.get('regress'),77 regression_component=lp_config.get('component'),78 cmdline=lp_config.get('cmdline'),79 ammo_path=lp_config.get('ammo_path'),80 loop_count=lp_config.get('loop_count'))81def get_plugin_dir(shooting_dir):82 DIRNAME = 'lunapark'83 parent = os.path.abspath(os.path.join(shooting_dir, os.pardir))84 if os.path.basename(parent) == DIRNAME:85 return parent86 else:87 plugin_dir = os.path.join(parent, DIRNAME)88 if not os.path.exists(plugin_dir):89 os.makedirs(plugin_dir)90 return plugin_dir91def make_symlink(shooting_dir, name):92 plugin_dir = get_plugin_dir(shooting_dir)93 link_name = os.path.join(plugin_dir, str(name))94 os.symlink(os.path.relpath(shooting_dir, plugin_dir), link_name)95 logger.info('Symlink created: {}'.format(os.path.abspath(link_name)))96def post_loader():97 parser = argparse.ArgumentParser()98 parser.add_argument('shooting_dir',99 help='Directory containing shooting artifacts')100 shooting_dir = parser.parse_args().shooting_dir101 assert os.path.exists(shooting_dir), 'Directory not found'102 config = read_config(shooting_dir)103 lp_config = get_lp_config(config)104 api_client = APIClient(base_url=lp_config['api_address'],105 user_agent='Lunapark/{}'.format(pkg_resources.require('yatank-internal-lunapark')[0].version)106 # todo: add timeouts107 )108 lp_job = LPJob(109 client=api_client,110 target_host=lp_config.get('target_host'),111 target_port=lp_config.get('target_port'),112 person=lp_config.get(113 'operator',114 '') or pwd.getpwuid(115 os.geteuid())[0],116 task=lp_config['task'],117 name=lp_config['job_name'],118 description=lp_config['job_dsc'],119 tank=socket.getfqdn())120 edit_metainfo(lp_config, lp_job)121 upload_data(shooting_dir, DATA_LOG, lp_job)122 send_config_snapshot(config, lp_job)123 try:124 upload_monitoring(shooting_dir, MONITORING_LOG, lp_job)125 except AssertionError as e:126 logger.error(e)127 lp_job.close(0)128 make_symlink(shooting_dir, lp_job.number)129 logger.info(130 'LP job created: {}'.format(131 urljoin(132 api_client.base_url, str(133 lp_job.number))))134if __name__ == '__main__':...
api.py
Source:api.py
...15 queryset = Monitoring.objects.all()16 serializer = MonitorSerializer(queryset, many=True)17 return Response(serializer.data)18@api_view(['POST'])19def upload_monitoring(request):20 # bypass, do nothing....
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!!