def download_package(): request_data = request.json required_parameters = ['version', 'url'] check_config(request_data, required_parameters) if not request_data['url']: raise Exception(f"illegal url {request_data['url']}") if not request_data['version']: raise Exception(f"illegal url {request_data['version']}") os.makedirs(os.path.join(get_project_base_directory(), 'packages'), exist_ok=True) package_dir = get_package_dir_by_version(request_data.get('version')) if os.path.exists(package_dir): return get_json_result(retcode=100, retmsg=f"Downloading mirror with version {request_data.get('version')} failed, " f"package dir {package_dir} already exists.") package_instance = Package.get_or_none(Package.f_version == request_data['version'], Package.f_status == 'success') if package_instance: return get_json_result(retcode=100, retmsg=f"Downloading mirror with version {request_data.get('version')} failed, " f"version info has been stored in database.") request_data['dir'] = package_dir p = Process(target=do_download, args=(request_data, )) p.start() return get_json_result(retmsg=f"Start downloading mirror from url: {request_data.get('url')}.", data= {'version': request_data.get('version')})
def check_local_package(): request_data = request.json required_parameters = ['dir'] check_config(request_data, required_parameters) if os.path.exists(request_data['dir']) and os.path.exists(os.path.join(request_data['dir'], 'roles')): # get package module version var_fp = os.path.join(request_data['dir'], 'example', 'var_files', 'exp', 'fate_init') versions = {} if os.path.exists(var_fp): with open(var_fp, 'r') as fin: versions = yaml.safe_load(fin.read()).get('versions', {}) output = getoutput(f"du -d 1 -h {os.path.join(request_data['dir'], 'roles')}").split('\n') result = [] for s in output: items = s.split() module_name = os.path.basename(items[1]) if module_name != 'roles': result.append({ 'module': module_name, 'size': items[0], 'time': datetime.fromtimestamp(os.path.getctime(items[1])).strftime('%Y%m%d'), 'description': module_name if not versions.get(module_name) else f"{module_name} {versions.get(module_name)}", 'version': versions.get(module_name, None) }) return get_json_result(data={'version': versions.get('fate_flow'), 'list': result}) return get_json_result(retcode=100, retmsg='package dir not exists.')
def toy_test(): request_data = request.json required_parameters = [ 'host', 'guest_party_id', 'host_party_id', 'work_mode' ] check_config(request_data, required_parameters) retcode, retmsg = status_utils.toy_test(**request_data) return get_json_result(retcode=retcode, retmsg=retmsg)
def query_package(): request_data = request.json required_paramters = ['version'] check_config(request_data, required_paramters) p = get_package_download_record(request_data['version']) if p: return get_json_result(data=p.to_json()) return get_json_result(retcode=100, retmsg=f"can not found version {request_data['version']} record")
def fast_test(): request_data = request.json required_parameters = [ 'host', 'guest_party_id', 'host_party_id', 'arbiter_party_id' ] check_config(request_data, required_parameters) request_data['test_type'] = 'fast' retcode, retmsg = status_utils.min_test(**request_data) return get_json_result(retcode=retcode, retmsg=retmsg)
def retry_play(): request_data = request.json required_parameters = ['job_id', 'play_id'] check_config(request_data, required_parameters) retcode, retmsg = PlayController.retry_play( job_id=request_data['job_id'], play_id=request_data['play_id'], test_mode=TEST_MODE) return get_json_result(retcode=retcode, retmsg=retmsg, data={'play_id': request_data['play_id']})
def status_check(): request_data = request.json required_parameters = ['party_id'] check_config(request_data, required_parameters) if request_data.get('module_name'): retcode, retmsg, data = do_status_check( party_id=request_data['party_id'], module_name=request_data['module_name']) else: retcode, retmsg, data = do_status_check( party_id=request_data['party_id']) return get_json_result(retcode=retcode, retmsg=retmsg, data=data)
def single_test(): request_data = request.json required_parameters = ['host', 'party_id'] check_config(request_data, required_parameters) retcode, retmsg = status_utils.single_test(**request_data) return get_json_result(retcode=retcode, retmsg=retmsg)
def upload_data(): request_data = request.json required_parameters = ['host'] check_config(request_data, required_parameters) retcode, retmsg = status_utils.upload_data_for_min_test(**request_data) return get_json_result(retcode=retcode, retmsg=retmsg)
def query_log(): request_data = request.json required_parameters = ['host', 'test_type'] check_config(request_data, required_parameters) retcode, retmsg, data = status_utils.get_test_log(**request_data) return get_json_result(retcode=retcode, retmsg=retmsg, data=data)