From 0b2c3cee077d79ca8fa8a802c94ae8ca32a0075a Mon Sep 17 00:00:00 2001 From: zhangsetsail Date: Fri, 11 Aug 2023 13:53:50 +0800 Subject: [PATCH] fix: adapt low version package to import high version --- console/services/app_import_and_export_service.py | 11 ++++++----- console/views/center_pool/app_import.py | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/console/services/app_import_and_export_service.py b/console/services/app_import_and_export_service.py index 9ef3d9a6a0..ac13cee935 100644 --- a/console/services/app_import_and_export_service.py +++ b/console/services/app_import_and_export_service.py @@ -278,7 +278,7 @@ def start_import_apps(self, scope, event_id, file_names, team_name=None, enterpr import_record.status = "importing" import_record.save() - def get_and_update_import_by_event_id(self, event_id): + def get_and_update_import_by_event_id(self, event_id, arch): import_record = app_import_record_repo.get_import_record_by_event_id(event_id) if not import_record: raise RecordNotFound("import_record not found") @@ -288,7 +288,7 @@ def get_and_update_import_by_event_id(self, event_id): if import_record.status != "success": if status == "success": logger.debug("app import success !") - self.__save_enterprise_import_info(import_record, body["bean"]["metadata"]) + self.__save_enterprise_import_info(import_record, body["bean"]["metadata"], arch) import_record.source_dir = body["bean"]["source_dir"] import_record.format = body["bean"]["format"] import_record.status = "success" @@ -427,7 +427,7 @@ def delete_import_app_dir(self, tenant, region, event_id): app_import_record_repo.delete_by_event_id(event_id) - def __save_enterprise_import_info(self, import_record, metadata): + def __save_enterprise_import_info(self, import_record, metadata, arch): rainbond_apps = [] rainbond_app_versions = [] metadata = json.loads(metadata) @@ -441,8 +441,9 @@ def __save_enterprise_import_info(self, import_record, metadata): if annotations.get("describe", ""): app_describe = annotations.pop("describe", "") app = rainbond_app_repo.get_rainbond_app_by_app_id(import_record.enterprise_id, app_template["group_key"]) - arch_map = {a.get("arch"): 1 for a in apps} - arch = "&".join(list(arch_map.keys())) + if not arch: + arch_map = {a.get("arch", "amd64"): 1 for a in apps} + arch = "&".join(list(arch_map.keys())) # if app exists, update it if app: app.scope = import_record.scope diff --git a/console/views/center_pool/app_import.py b/console/views/center_pool/app_import.py index ec2c4b6973..71185494c5 100644 --- a/console/views/center_pool/app_import.py +++ b/console/views/center_pool/app_import.py @@ -122,9 +122,10 @@ def get(self, request, event_id, *args, **kwargs): paramType: path """ sid = None + arch = request.GET.get("arch") try: sid = transaction.savepoint() - record, apps_status = import_service.get_and_update_import_by_event_id(event_id) + record, apps_status = import_service.get_and_update_import_by_event_id(event_id, arch) transaction.savepoint_commit(sid) result = general_message(200, 'success', "查询成功", bean=record.to_dict(), list=apps_status) except Exception as e: