def get(self, parent_job_id): job_id = g.token['job']['id'] if not validate_uuid4(parent_job_id): abort(400, "Invalid uuid") dependencies = g.db.execute_one( ''' SELECT dependencies FROM job WHERE id = %s ''', [job_id])[0] is_valid_dependency = False for dep in dependencies: if dep['job-id'] == parent_job_id: is_valid_dependency = True break if not is_valid_dependency: abort(404, "Job not found") key = "%s.tar.gz" % parent_job_id key = key.replace('/', '_') g.release_db() f = storage.download_output(key) if not f: abort(404) return send_file(f)
def get(self, parent_job_id): job_id = g.token['job']['id'] if not validate_uuid4(parent_job_id): abort(400, "Invalid uuid") filename = request.args.get('filename', None) if not filename: abort(400, "Invalid filename") dependencies = g.db.execute_one(''' SELECT dependencies FROM job WHERE id = %s ''', [job_id])[0] is_valid_dependency = False for dep in dependencies: if dep['job-id'] == parent_job_id: is_valid_dependency = True break if not is_valid_dependency: abort(404, "Job not found") key = "%s/%s" % (parent_job_id, filename) g.release_db() f = storage.download_output(key) if not f: abort(404) return send_file(f)
def get(self, project_id, job_id): key = '%s.tar.gz' % job_id f = storage.download_output(key) if not f: abort(404) return send_file(f, attachment_filename=key)
def get(self, project_id, job_id): ''' Returns the the content of /infrabox/output of the job ''' g.release_db() key = '%s.tar.snappy' % job_id f = storage.download_output(key) if not f: abort(404) return send_file(f, attachment_filename=key)
def test_output(self): filename = 'output.tar.gz' file_path = getcwd() + '/' + filename test_data = open(file_path, 'rb') files = { 'output.tar.gz': test_data } r = TestClient.post(self.url_ns + '/output', data=files, headers=self.job_headers, content_type='multipart/form-data') self.assertEqual(r, {}) # Check if output was uploaded successfully result_key = "%s.tar.gz" % self.job_id print("Key:!!!!! %s" % result_key) r = storage.download_output(result_key)
def get(self, parent_job_id): job_id = g.token['job']['id'] if not validate_uuid(parent_job_id): abort(400, "Invalid uuid") filename = request.args.get('filename', None) if not filename: abort(400, "Invalid filename") dependencies = g.db.execute_one( ''' SELECT dependencies FROM job WHERE id = %s ''', [job_id])[0] is_valid_dependency = False for dep in dependencies: if dep['job-id'] == parent_job_id: is_valid_dependency = True break if not is_valid_dependency: abort(404, "Job not found") key = "%s/%s" % (parent_job_id, filename) f = storage.download_output(key) if f: g.release_db() return send_file(f) c = g.db.execute_one_dict( ''' SELECT * FROM cluster WHERE name= ( SELECT cluster_name FROM job where id = %s) ''', [parent_job_id]) g.release_db() if c['name'] == os.environ['INFRABOX_CLUSTER_NAME']: abort(404) token = encode_job_token(job_id) headers = {'Authorization': 'token ' + token} url = '%s/api/job/output/%s?filename=%s' % (c['root_url'], parent_job_id, filename) try: r = requests.get(url, headers=headers, timeout=120, verify=False) if r.status_code != 200: f = None else: f = BytesIO(r.content) f.seek(0) except: f = None if not f: abort(404) return send_file(f, attachment_filename=filename)