def submit_job(request, group_slug, project_slug, version, environment_slug): backend_name = request.POST.get('backend') if backend_name is None: return HttpResponseBadRequest("backend field is required") try: backend = Backend.objects.get(name=backend_name) except Backend.DoesNotExist: return HttpResponseBadRequest("requested backend does not exist") # project has to exist or request will result with 404 project = request.project if project is None: return HttpResponseBadRequest("malformed request") # `Environment.expected_test_runs == -1` means that environment will stop receiving submissions environment, created = project.environments.get_or_create( slug=environment_slug) if environment.expected_test_runs == -1: return HttpResponseBadRequest( "environment '%s' is disabled and squad will not accept new submissions to it" % environment_slug) # create Build object build, _ = project.builds.get_or_create(version=version) # definition can be received as a file upload or as a POST parameter definition = None if 'definition' in request.FILES: definition = read_file_upload( request.FILES['definition']).decode('utf-8') else: definition = request.POST.get('definition') if definition is None: return HttpResponseBadRequest("test job definition is required") # create TestJob object test_job = TestJob.objects.create( backend=backend, definition=definition, target=project, target_build=build, environment=environment_slug, ) log_addition(request, test_job, "Test Job submission") # schedule submission submit.delay(test_job.id) # return ID of test job return HttpResponse(test_job.id, status=201)
def submit_job(request, group_slug, project_slug, version, environment_slug): backend_name = request.POST.get('backend') if backend_name is None: return HttpResponseBadRequest("backend field is required") try: backend = Backend.objects.get(name=backend_name) except Backend.DoesNotExist: return HttpResponseBadRequest("requested backend does not exist") # project has to exist or request will result with 404 project = request.project if project is None: return HttpResponseBadRequest("malformed request") # create Build object build, _ = project.builds.get_or_create(version=version) # definition can be received as a file upload or as a POST parameter definition = None if 'definition' in request.FILES: definition = read_file_upload(request.FILES['definition']) else: definition = request.POST.get('definition') if definition is None: return HttpResponseBadRequest("test job definition is required") # create TestJob object test_job = TestJob.objects.create( backend=backend, definition=definition, target=project, target_build=build, environment=environment_slug, ) # schedule submission submit.delay(test_job.id) # return ID of test job return HttpResponse(test_job.id, status=201)
def submit_job(request, group_slug, project_slug, version, environment_slug): backend_name = request.POST.get('backend') if backend_name is None: return HttpResponseBadRequest("backend field is required") try: backend = Backend.objects.get(name=backend_name) except Backend.DoesNotExist: return HttpResponseBadRequest("requested backend does not exist") # project has to exist or request will result with 404 project = request.project if project is None: return HttpResponseBadRequest("malformed request") # create Build object build, _ = project.builds.get_or_create(version=version) # definition can be received as a file upload or as a POST parameter definition = None if 'definition' in request.FILES: definition = read_file_upload(request.FILES['definition']) else: definition = request.POST.get('definition') if definition is None: return HttpResponseBadRequest("test job definition is required") # create TestJob object test_job = TestJob.objects.create( backend=backend, definition=definition, target=project, target_build=build, environment=environment_slug, ) # schedule submission submit.delay(test_job.id) # return ID of test job return HttpResponse(test_job.id, status=201)
def submit_job(modeladmin, request, queryset): for test_job in queryset: submit.delay(test_job.id)
def submit_job(modeladmin, request, queryset): for test_job in queryset: submit.delay(test_job.id)
def submit_job(request): """ #submit_job(request, group_slug, project_slug, version, environment_slug) """ vts_versions = VtsVersion.objects.all() vts_models = VtsModel.objects.all() device_types = DeviceType.objects.all() context = { 'vts_versions': vts_versions, 'vts_models': vts_models, 'device_types': device_types, } if request.method == "GET": return render(request, 'squad/submit.jinja2', context) post_data = dict(request.POST) print(post_data) vts_version = request.POST.get('vts-version') version = request.POST.get('description') vts_version_id = request.POST.get('vts-version') vts_models = post_data.get('vts-models') vts_models_manuel = post_data.get('vts-models-manuel') device_type = request.POST.get('device-type') pac_node = request.POST.get('pac-node') verify_url = request.POST.get('verify-url') if not version: context['message'] = 'Please input description!' return render(request, 'squad/submit.jinja2', context) if not vts_version_id: context['message'] = 'Please input vts version!' return render(request, 'squad/submit.jinja2', context) if (not vts_models or '' in vts_models) and (not vts_models_manuel or '' in vts_models_manuel): context['message'] = 'Please input vts vts models!' return render(request, 'squad/submit.jinja2', context) if not device_type: context['message'] = 'Please input vts device type!' return render(request, 'squad/submit.jinja2', context) if not pac_node: context['message'] = 'Please input vts pac node!' return render(request, 'squad/submit.jinja2', context) if verify_url: res = requests.head(verify_url) if res.status_code > 300: context['message'] = 'Please input correct verify url!' return render(request, 'squad/submit.jinja2', context) vts_version = VtsVersion.objects.get(id=vts_version_id) device_type = DeviceType.objects.get(id=device_type) if vts_models: vts_models = VtsModel.objects.filter(id__in=vts_models) environment_slug = device_type.env.slug backend = device_type.backend project = device_type.project # env = project.environments.get(device_type.) # create Build object build, _ = project.builds.get_or_create(version=version) if vts_models_manuel[0]: try: definition = TestDefinition.objects.get(name='vts_common') except TestDefinition.DoesNotExist: context['message'] = 'Please create vts common in admin' return render(request, 'squad/submit.jinja2', context) definition_data = yaml.load(definition.content) try: pac_url = device_type.base_pac_url.format(pac_node) except KeyError: pac_url = device_type.base_pac_url.format(pac_node=pac_node) if pac_url.endswith('/'): pac_url = pac_url[:-1] # 替换definition中的img url, vts版本, vts model if verify_url: verifyid, burl, verify_files = verify_dowloader(verify_url, device_type.name) replace_target = '/'.join(definition_data['actions'][3]['deploy']['images']['boot']['url'].split('/')[0:-1]) for key in definition_data['actions'][3]['deploy']['images'].keys(): target_url = definition_data['actions'][3]['deploy']['images'][key]['url'].replace(replace_target, pac_url[:-1]) definition_data['actions'][3]['deploy']['images'][key]['url'] \ = target_url if verify_url: img_name = target_url.split('/')[-1] print(img_name) for f in verify_files: if f == img_name: definition_data['actions'][3]['deploy']['images'][key]['url'] = burl + verify_files[ verify_files.index(img_name)] definition_data['actions'][6]['test']['definitions'][0]['params']['TEST_URL'] = vts_version.vts_bar_url definition_data['actions'][6]['test']['definitions'][0]['params']['TEST_PARAMS'] \ = 'run vts-kernel --module {} --skip-device-info'.format(vts_models_manuel[0]) definition_data['job_name'] = version definition_data['device_type'] = device_type.name definition_s = yaml.dump(definition_data) # create TestJob object test_job = TestJob.objects.create( backend=backend, definition=definition_s, target=project, target_build=build, environment=environment_slug, ) # schedule submission submit.delay(test_job.id) group = Group.objects.get(user_groups=request.user.groups.all()[0]) return redirect('testjobs', group.slug, project.slug, version) for vts_model in vts_models: # definition can be received as a file upload or as a POST parameter definition = vts_model.test_definition definition_data = yaml.load(definition.content) try: pac_url = device_type.base_pac_url.format(pac_node) except KeyError: pac_url = device_type.base_pac_url.format(pac_node=pac_node) if pac_url.endswith('/'): pac_url = pac_url[:-1] # 替换definition中的img url, vts版本, vts model if verify_url: verifyid, burl, verify_files = verify_dowloader(verify_url, device_type.name) replace_target = '/'.join(definition_data['actions'][3]['deploy']['images']['boot']['url'].split('/')[0:-1]) for key in definition_data['actions'][3]['deploy']['images'].keys(): target_url = definition_data['actions'][3]['deploy']['images'][key]['url'].replace(replace_target, pac_url[:-1]) definition_data['actions'][3]['deploy']['images'][key]['url'] \ = target_url if verify_url: img_name = target_url.split('/')[-1] print(img_name) for f in verify_files: if f == img_name: definition_data['actions'][3]['deploy']['images'][key]['url'] = burl + verify_files[verify_files.index(img_name)] definition_data['actions'][6]['test']['definitions'][0]['params']['TEST_URL'] = vts_version.vts_bar_url definition_data['job_name'] = version definition_data['device_type'] = device_type.name definition_s = yaml.dump(definition_data) # create TestJob object test_job = TestJob.objects.create( backend=backend, definition=definition_s, target=project, target_build=build, environment=environment_slug, ) # schedule submission submit.delay(test_job.id) # return ID of test job group = Group.objects.get(user_groups=request.user.groups.all()[0]) return redirect('testjobs', group.slug, project.slug, version)