From 61fd2ce58e13735eb1fb03f42c1b094c7f8f1921 Mon Sep 17 00:00:00 2001 From: gongzt Date: Thu, 14 Sep 2023 14:48:24 +0800 Subject: [PATCH] fix server startup and check code --- 0002-fix-kv-bug.patch | 41 ++++++ 0003-fix-server-startup-error.patch | 106 +++++++++++++++ 0004-codecheck.patch | 193 ++++++++++++++++++++++++++++ A-Ops.spec | 8 +- 4 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 0002-fix-kv-bug.patch create mode 100644 0003-fix-server-startup-error.patch create mode 100644 0004-codecheck.patch diff --git a/0002-fix-kv-bug.patch b/0002-fix-kv-bug.patch new file mode 100644 index 0000000..409e052 --- /dev/null +++ b/0002-fix-kv-bug.patch @@ -0,0 +1,41 @@ +From f340e404d50e0d065012a946164d3a86db653306 Mon Sep 17 00:00:00 2001 +From: smjiao +Date: Wed, 13 Sep 2023 18:38:20 +0800 +Subject: fix kv bug +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 8bit + +--- + gala-ragdoll/ragdoll/utils/object_parse.py | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/gala-ragdoll/ragdoll/utils/object_parse.py b/gala-ragdoll/ragdoll/utils/object_parse.py +index 3d0976e..83d22b7 100644 +--- a/gala-ragdoll/ragdoll/utils/object_parse.py ++++ b/gala-ragdoll/ragdoll/utils/object_parse.py +@@ -71,7 +71,11 @@ class ObjectParse(object): + conf_model.load_yang_model(yang_info) + + # load conf info +- conf_model.read_conf(conf_info) ++ if conf_type == "kv": ++ spacer_type = self._yang_modules.getSpacerInModdule([yang_info]) ++ conf_model.read_conf(conf_info, spacer_type, yang_info) ++ else: ++ conf_model.read_conf(conf_info) + + # to json + conf_json = self.parse_model_to_json(conf_model) +@@ -96,6 +100,8 @@ class ObjectParse(object): + conf_model.read_json(json_list) + if conf_type == "sshd": + conf_info = conf_model.write_conf(spacer_info) ++ elif conf_type == "kv": ++ conf_info = conf_model.write_conf(spacer_info, yang_info) + else: + # to content + conf_info = conf_model.write_conf() +-- +2.37.1.windows.1 + diff --git a/0003-fix-server-startup-error.patch b/0003-fix-server-startup-error.patch new file mode 100644 index 0000000..2a633d7 --- /dev/null +++ b/0003-fix-server-startup-error.patch @@ -0,0 +1,106 @@ +From 44f16e2e840516cb4b0ce50d63e25db744451f2c Mon Sep 17 00:00:00 2001 +From: smjiao +Date: Thu, 14 Sep 2023 11:02:05 +0800 +Subject: fix server startup error +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 8bit + +--- + .../ragdoll/const/conf_handler_const.py | 8 +++ + .../ragdoll/controllers/confs_controller.py | 56 +++++++++++++++++++ + 2 files changed, 64 insertions(+) + +diff --git a/gala-ragdoll/ragdoll/const/conf_handler_const.py b/gala-ragdoll/ragdoll/const/conf_handler_const.py +index 8ef5ca6..6780dfe 100644 +--- a/gala-ragdoll/ragdoll/const/conf_handler_const.py ++++ b/gala-ragdoll/ragdoll/const/conf_handler_const.py +@@ -16,5 +16,13 @@ + @Author: JiaoSiMao + Description: + """ ++import re ++ + NOT_SYNCHRONIZE = "NOT SYNCHRONIZE" + SYNCHRONIZED = "SYNCHRONIZED" ++LIMITS_DOMAIN_RE = re.compile('(^[*]$)|(^[@|0-9A-Za-z]+[0-9A-Za-z]$)') ++LIMITS_TYPE_VALUE = "soft|hard|-|" ++LIMITS_ITEM_VALUE = "core|data|fsize|memlock|nofile|rss|stack|cpu|nproc|as|maxlogins|maxsyslogins|priority|locks|sigpending|" \ ++ "msgqueue|nice|rtprio|" ++RESOLV_KEY_VALUE = "nameserver|domain|search|sortlist|" ++FSTAB_COLUMN_NUM = 6 +\ No newline at end of file +diff --git a/gala-ragdoll/ragdoll/controllers/confs_controller.py b/gala-ragdoll/ragdoll/controllers/confs_controller.py +index 814c875..7703c7c 100644 +--- a/gala-ragdoll/ragdoll/controllers/confs_controller.py ++++ b/gala-ragdoll/ragdoll/controllers/confs_controller.py +@@ -27,6 +27,7 @@ from ragdoll.utils.conf_tools import ConfTools + from ragdoll.utils.host_tools import HostTools + from ragdoll.utils.object_parse import ObjectParse + from ragdoll import util ++from ragdoll.const.conf_files import yang_conf_list + + TARGETDIR = GitTools().target_dir + +@@ -509,3 +510,58 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + sync_res.append(host_sync_result) + + return sync_res ++ ++def query_supported_confs(body=None): ++ """ ++ query supported configuration list # noqa: E501 ++ ++ :param body: ++ :type body: dict | bytes ++ ++ :rtype: List ++ """ ++ if connexion.request.is_json: ++ body = DomainName.from_dict(connexion.request.get_json()) ++ ++ domain = body.domain_name ++ ++ check_res = Format.domainCheck(domain) ++ if not check_res: ++ code_num = 400 ++ base_rsp = BaseResponse(code_num, "Failed to verify the input parameter, please check the input parameters.") ++ return base_rsp, code_num ++ ++ is_exist = Format.isDomainExist(domain) ++ if not is_exist: ++ code_num = 404 ++ base_rsp = BaseResponse(code_num, "The current domain does not exist, please create the domain first.") ++ return base_rsp, code_num ++ ++ conf_tools = ConfTools() ++ port = conf_tools.load_port_by_conf() ++ url = "http://0.0.0.0:" + port + "/management/getManagementConf" ++ headers = {"Content-Type": "application/json"} ++ get_man_conf_body = DomainName(domain_name=domain) ++ print("body is : {}".format(get_man_conf_body)) ++ response = requests.post(url, data=json.dumps(get_man_conf_body), headers=headers) # post request ++ print("response is : {}".format(response.text)) ++ res_code = response.status_code ++ res_json = json.loads(response.text) ++ print("return code is : {}".format(response.status_code)) ++ ++ if res_code != 200: ++ code_num = res_code ++ base_rsp = BaseResponse(code_num, ++ "Failed to query the configuration items managed in the current domain. " + ++ "The failure reason is:" + res_json) ++ return base_rsp, code_num ++ ++ conf_files = res_json.get("confFiles") ++ if len(conf_files) == 0: ++ return yang_conf_list ++ ++ exist_conf_list = [] ++ for conf in conf_files: ++ exist_conf_list.append(conf.get('filePath')) ++ ++ return list(set(yang_conf_list).difference(set(exist_conf_list))) +-- +2.37.1.windows.1 + diff --git a/0004-codecheck.patch b/0004-codecheck.patch new file mode 100644 index 0000000..63b1238 --- /dev/null +++ b/0004-codecheck.patch @@ -0,0 +1,193 @@ +From faaf35ce2ed973e5bd5b997dd4304b5a24fadb82 Mon Sep 17 00:00:00 2001 +From: smjiao +Date: Thu, 14 Sep 2023 11:10:04 +0800 +Subject: code check +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 8bit + +--- + .../ragdoll/const/conf_handler_const.py | 7 +-- + .../ragdoll/controllers/confs_controller.py | 51 ++++++++++--------- + 2 files changed, 32 insertions(+), 26 deletions(-) + +diff --git a/gala-ragdoll/ragdoll/const/conf_handler_const.py b/gala-ragdoll/ragdoll/const/conf_handler_const.py +index 6780dfe..0533423 100644 +--- a/gala-ragdoll/ragdoll/const/conf_handler_const.py ++++ b/gala-ragdoll/ragdoll/const/conf_handler_const.py +@@ -22,7 +22,8 @@ NOT_SYNCHRONIZE = "NOT SYNCHRONIZE" + SYNCHRONIZED = "SYNCHRONIZED" + LIMITS_DOMAIN_RE = re.compile('(^[*]$)|(^[@|0-9A-Za-z]+[0-9A-Za-z]$)') + LIMITS_TYPE_VALUE = "soft|hard|-|" +-LIMITS_ITEM_VALUE = "core|data|fsize|memlock|nofile|rss|stack|cpu|nproc|as|maxlogins|maxsyslogins|priority|locks|sigpending|" \ +- "msgqueue|nice|rtprio|" ++LIMITS_ITEM_VALUE = "core|data|fsize|memlock|nofile|rss|stack|cpu|nproc|as|maxlogins|" \ ++ "maxsyslogins|priority|locks|sigpending|" \ ++ "msgqueue|nice|rtprio|" + RESOLV_KEY_VALUE = "nameserver|domain|search|sortlist|" +-FSTAB_COLUMN_NUM = 6 +\ No newline at end of file ++FSTAB_COLUMN_NUM = 6 +diff --git a/gala-ragdoll/ragdoll/controllers/confs_controller.py b/gala-ragdoll/ragdoll/controllers/confs_controller.py +index 7703c7c..ae766fa 100644 +--- a/gala-ragdoll/ragdoll/controllers/confs_controller.py ++++ b/gala-ragdoll/ragdoll/controllers/confs_controller.py +@@ -31,6 +31,7 @@ from ragdoll.const.conf_files import yang_conf_list + + TARGETDIR = GitTools().target_dir + ++ + def get_the_sync_status_of_domain(body=None): # noqa: E501 + """ + get the status of the domain +@@ -64,8 +65,8 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + is_host_list_exist = Format.isHostInDomain(domain) + if not is_host_list_exist: + code_num = 404 +- base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + +- "Please add the host information first") ++ base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + ++ "Please add the host information first") + return base_rsp, code_num + + # get the host info in domain +@@ -83,15 +84,15 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + + if res_code != 200: + code_num = res_code +- base_rsp = BaseResponse(code_num, "Failed to get host info in the current domain. " + +- "The failure reason is:" + res_text.get('msg')) ++ base_rsp = BaseResponse(code_num, "Failed to get host info in the current domain. " + ++ "The failure reason is:" + res_text.get('msg')) + return base_rsp, code_num + + if len(res_text) == 0: + code_num = 404 + +- base_rsp = BaseResponse(code_num, "The host currently controlled in the domain is empty." + +- "Please add host information to the domain.") ++ base_rsp = BaseResponse(code_num, "The host currently controlled in the domain is empty." + ++ "Please add host information to the domain.") + return base_rsp, code_num + + # get the host list from the git house +@@ -104,22 +105,24 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + get_man_conf_url = "http://0.0.0.0:" + port + "/management/getManagementConf" + headers = {"Content-Type": "application/json"} + get_man_conf_body = DomainName(domain_name=domain) +- get_man_conf_res = requests.post(get_man_conf_url, data=json.dumps(get_man_conf_body), headers=headers) # post request ++ get_man_conf_res = requests.post(get_man_conf_url, data=json.dumps(get_man_conf_body), ++ headers=headers) # post request + man_ronf_res_text = json.loads(get_man_conf_res.text) + manage_confs = man_ronf_res_text.get("confFiles") + print("manage_confs is : {}".format(manage_confs)) + + if len(manage_confs) == 0: + code_num = 404 +- base_rsp = BaseResponse(code_num, "The configuration is not set in the current domain." + +- "Please add the configuration information first.") ++ base_rsp = BaseResponse(code_num, "The configuration is not set in the current domain." + ++ "Please add the configuration information first.") + return base_rsp, code_num + + # query the real conf in host + print("############## query the real conf ##############") + get_real_conf_url = "http://0.0.0.0:" + port + "/confs/queryRealConfs" + query_real_body = ConfHost(domain_name=domain, host_ids=host_ids) +- get_res_conf_res = requests.post(get_real_conf_url, data=json.dumps(query_real_body), headers=headers) # post request ++ get_res_conf_res = requests.post(get_real_conf_url, data=json.dumps(query_real_body), ++ headers=headers) # post request + real_conf_res_code = get_res_conf_res.status_code + real_conf_res_text = json.loads(get_res_conf_res.text) + print("real_conf_res_text is : {}".format(real_conf_res_text)) +@@ -273,8 +276,8 @@ def query_real_confs(body=None): # noqa: E501 + print("is_host_list_exist is : {}".format(is_host_list_exist)) + if not is_host_list_exist: + code_num = 400 +- base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + +- "Please add the host information first") ++ base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + ++ "Please add the host information first") + return base_rsp, code_num + + # get all hosts managed by the current domain. +@@ -300,8 +303,8 @@ def query_real_confs(body=None): # noqa: E501 + + if len(exist_host) == 0 or len(failed_host) == len(host_list): + code_num = 400 +- base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + +- "Please add the host information first") ++ base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + ++ "Please add the host information first") + return base_rsp, code_num + + # get the management conf in domain +@@ -318,14 +321,14 @@ def query_real_confs(body=None): # noqa: E501 + + if res_code != 200: + code_num = res_code +- base_rsp = BaseResponse(code_num, "Failed to query the configuration items managed in the current domain. " + +- "The failure reason is:" + res_text) ++ base_rsp = BaseResponse(code_num, "Failed to query the configuration items managed in the current domain. " + ++ "The failure reason is:" + res_text) + return base_rsp, code_num + conf_files = res_text.get("confFiles") + if len(conf_files) == 0: + code_num = 400 +- base_rsp = BaseResponse(code_num, "The configuration is not set in the current domain." + +- "Please add the configuration information first") ++ base_rsp = BaseResponse(code_num, "The configuration is not set in the current domain." + ++ "Please add the configuration information first") + return base_rsp, code_num + + res = [] +@@ -407,7 +410,7 @@ def query_real_confs(body=None): # noqa: E501 + code_num = 400 + res_text = "The real configuration does not found." + base_rsp = BaseResponse(code_num, "Real configuration query failed." + +- "The failure reason is : " + res_text) ++ "The failure reason is : " + res_text) + return base_rsp, code_num + + return res +@@ -469,8 +472,8 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + + if len(exist_host) == 0: + code_num = 400 +- base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + +- "Please add the host information first") ++ base_rsp = BaseResponse(code_num, "The host information is not set in the current domain." + ++ "Please add the host information first") + return base_rsp, code_num + + # get the management conf in domain +@@ -478,7 +481,8 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + get_man_conf_url = "http://0.0.0.0:" + port + "/management/getManagementConf" + headers = {"Content-Type": "application/json"} + get_man_conf_body = DomainName(domain_name=domain) +- get_man_conf_res = requests.post(get_man_conf_url, data=json.dumps(get_man_conf_body), headers=headers) # post request ++ get_man_conf_res = requests.post(get_man_conf_url, data=json.dumps(get_man_conf_body), ++ headers=headers) # post request + man_conf_res_text = json.loads(get_man_conf_res.text) + manage_confs = man_conf_res_text.get("confFiles") + print("manage_confs is : {}".format(manage_confs)) +@@ -487,7 +491,7 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + sync_res = [] + for d_host in exist_host: + host_sync_result = HostSyncResult(host_id=d_host, +- sync_result=[]) ++ sync_result=[]) + for d_man_conf in manage_confs: + file_path = d_man_conf.get("filePath").split(":")[-1] + contents = d_man_conf.get("contents") +@@ -511,6 +515,7 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + + return sync_res + ++ + def query_supported_confs(body=None): + """ + query supported configuration list # noqa: E501 +-- +2.37.1.windows.1 + diff --git a/A-Ops.spec b/A-Ops.spec index 1df5a23..9c3cf07 100644 --- a/A-Ops.spec +++ b/A-Ops.spec @@ -1,11 +1,14 @@ Name: A-Ops Version: v1.3.1 -Release: 2 +Release: 3 Summary: The intelligent ops toolkit for openEuler License: MulanPSL2 URL: https://gitee.com/openeuler/A-Ops Source0: %{name}-%{version}.tar.gz Patch0001: 0001-fix-host-upload-traceability-configuration-issue.patch +Patch0002: 0002-fix-kv-bug.patch +Patch0003: 0003-fix-server-startup-error.patch +Patch0004: 0004-codecheck.patch %global debug_package %{nil} @@ -93,6 +96,9 @@ fi %changelog +* Thu Sep 14 2023 gongzhengtang - v1.3.1-3 +- fix server startup error and code check + * Wed Sep 13 2023 gongzhengtang - v1.3.1-2 - fix host upload traceability configuration issue -- Gitee