From 051cab22e7772b70a1239a96930bb1daefd23738 Mon Sep 17 00:00:00 2001 From: smjiao Date: Tue, 19 Sep 2023 14:15:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbash=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=90=8C=E6=AD=A5=E4=BA=86=E4=BD=86?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=AA=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0006-fix-bash-config-sync-status-bug.patch | 160 +++++++++++++++++++++ A-Ops.spec | 6 +- 2 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 0006-fix-bash-config-sync-status-bug.patch diff --git a/0006-fix-bash-config-sync-status-bug.patch b/0006-fix-bash-config-sync-status-bug.patch new file mode 100644 index 0000000..b4f4e6d --- /dev/null +++ b/0006-fix-bash-config-sync-status-bug.patch @@ -0,0 +1,160 @@ +From 01601ae72fa02f10e178ecc787c12262cf811302 Mon Sep 17 00:00:00 2001 +From: smjiao +Date: Tue, 19 Sep 2023 14:00:04 +0800 +Subject: [PATCH] fix bash config sync status bug +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + .../ragdoll/config_model/bash_config.py | 18 +++++++++++++ + .../ragdoll/controllers/confs_controller.py | 25 +++++++------------ + 2 files changed, 27 insertions(+), 16 deletions(-) + +diff --git a/gala-ragdoll/ragdoll/config_model/bash_config.py b/gala-ragdoll/ragdoll/config_model/bash_config.py +index 608cd58..36016a9 100644 +--- a/gala-ragdoll/ragdoll/config_model/bash_config.py ++++ b/gala-ragdoll/ragdoll/config_model/bash_config.py +@@ -14,8 +14,10 @@ Time: 2023-08-30 14:05:00 + Author: jiaosimao + Description: bash type config analyze + """ ++import json + + from ragdoll.config_model.base_handler_config import BaseHandlerConfig ++from ragdoll.const.conf_handler_const import SYNCHRONIZED, NOT_SYNCHRONIZE + + + class BashConfig(BaseHandlerConfig): +@@ -45,3 +47,19 @@ class BashConfig(BaseHandlerConfig): + content = content + value + "\n" + content = content + '\n' + return content ++ ++ @staticmethod ++ def conf_compare(src_conf, dst_conf): ++ """ ++ desc: 比较dst_conf和src_conf是否相同,dst_conf和src_conf均为序列化后的配置信息。 ++ return:dst_conf和src_conf相同返回SYNCHRONIZED ++ dst_conf和src_conf不同返回NOT_SYNCHRONIZE ++ """ ++ res = SYNCHRONIZED ++ dst_conf_dict = json.loads(dst_conf) ++ src_conf_dict = json.loads(src_conf) ++ for src_conf in src_conf_dict: ++ if src_conf not in dst_conf_dict: ++ res = NOT_SYNCHRONIZE ++ break ++ return res +diff --git a/gala-ragdoll/ragdoll/controllers/confs_controller.py b/gala-ragdoll/ragdoll/controllers/confs_controller.py +index 071e8c5..c598bf1 100644 +--- a/gala-ragdoll/ragdoll/controllers/confs_controller.py ++++ b/gala-ragdoll/ragdoll/controllers/confs_controller.py +@@ -29,7 +29,6 @@ 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 +-from ragdoll.log.log import LOGGER + + TARGETDIR = GitTools().target_dir + +@@ -39,7 +38,7 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + get the status of the domain + get the status of whether the domain has been synchronized # noqa: E501 + +- :param body: ++ :param body: + :type body: dict | bytes + + :rtype: SyncStatus +@@ -132,7 +131,7 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + code_num = real_conf_res_code + base_rsp = BaseResponse(code_num, "Failed to get the real config of the all hosts in domain.") + return base_rsp, code_num +- # Match the actual configuration with the expected configuration, and output the ++ # Match the actual configuration with the expected configuration, and output the + # configuration in the same format that can be compared with the expected result. + sync_status = SyncStatus(domain_name=domain, + host_status=[]) +@@ -151,10 +150,10 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + + comp_res = "" + for d_man_conf in manage_confs: +- if d_man_conf.get("filePath").split(":")[-1] == d_conf_path: +- # comp_res = conf_tools.compareManAndReal(d_conf.get("confContents"), d_man_conf.get("contents")) +- comp_res = conf_model.conf_compare(d_man_conf.get("contents"), d_conf.get("confContents")) +- break ++ if d_man_conf.get("filePath").split(":")[-1] != d_conf_path: ++ continue ++ # comp_res = conf_tools.compareManAndReal(d_conf.get("confContents"), d_man_conf.get("contents")) ++ comp_res = conf_model.conf_compare(d_man_conf.get("contents"), d_conf.get("confContents")) + conf_is_synced = ConfIsSynced(file_path=d_conf_path, + is_synced=comp_res) + host_sync_status.sync_status.append(conf_is_synced) +@@ -165,11 +164,9 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 + man_conf_list = [] + for d_man_conf in manage_confs: + man_conf_list.append(d_man_conf.get("filePath").split(":")[-1]) +- LOGGER.info("manage_confs is {}".format(manage_confs)) + for d_host in sync_status.host_status: + d_sync_status = d_host.sync_status + file_list = [] +- LOGGER.info("d_sync_status is {}".format(d_sync_status)) + for d_file in d_sync_status: + file_path = d_file.file_path + file_list.append(file_path) +@@ -251,7 +248,7 @@ def query_real_confs(body=None): # noqa: E501 + + query the real configuration value in the current hostId node # noqa: E501 + +- :param body: ++ :param body: + :type body: dict | bytes + + :rtype: List[RealConfInfo] +@@ -284,7 +281,7 @@ def query_real_confs(body=None): # noqa: E501 + "Please add the host information first") + return base_rsp, code_num + +- # get all hosts managed by the current domain. ++ # get all hosts managed by the current domain. + # If host_list is empty, query all hosts in the current domain. + # If host_list is not empty, the actual contents of the currently given host are queried. + conf_tools = ConfTools() +@@ -424,7 +421,7 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + """ + synchronize the configuration information of the configuration domain to the host # noqa: E501 + +- :param body: ++ :param body: + :type body: dict | bytes + + :rtype: List[HostSyncResult] +@@ -434,7 +431,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + + domain = body.domain_name + sync_list = body.sync_list +- LOGGER.info("sync_list is {}".format(sync_list)) + + host_sync_confs = dict() + +@@ -511,7 +507,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + contents = d_man_conf.get("contents") + object_parse = ObjectParse() + content = object_parse.parse_json_to_conf(file_path, contents) +- LOGGER.info("content IS {}".format(content)) + # Configuration to the host + sync_conf_url = conf_tools.load_url_by_conf().get("sync_url") + headers = {"Content-Type": "application/json"} +@@ -520,8 +515,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 + + resp_code = json.loads(sync_response.text).get('code') + resp = json.loads(sync_response.text).get('data').get('resp') +- LOGGER.info("resp_code IS {}".format(resp_code)) +- LOGGER.info("resp IS {}".format(resp)) + conf_sync_res = ConfSyncedRes(file_path=file_path, + result="") + if resp_code == "200" and resp.get('sync_result') is True: +-- +2.38.1.windows.1 + diff --git a/A-Ops.spec b/A-Ops.spec index dbac7ee..a936521 100644 --- a/A-Ops.spec +++ b/A-Ops.spec @@ -1,6 +1,6 @@ Name: A-Ops Version: v1.3.1 -Release: 4 +Release: 5 Summary: The intelligent ops toolkit for openEuler License: MulanPSL2 URL: https://gitee.com/openeuler/A-Ops @@ -10,6 +10,7 @@ Patch0002: 0002-fix-kv-bug.patch Patch0003: 0003-fix-server-startup-error.patch Patch0004: 0004-codecheck.patch Patch0005: 0005-fixe-traceability-configuration-bugs.patch +Patch0006: 0006-fix-bash-config-sync-status-bug.patch %global debug_package %{nil} @@ -97,6 +98,9 @@ fi %changelog +* Tue Sep 19 2023 smjiao - v1.3.1-5 +- fix bash config sync status bug + * Tue Sep 19 2023 smjiao - v1.3.1-4 - fix traceability configuration bugs -- Gitee From 5db8a211fc670febf09312c18ac1b2268322b4ae Mon Sep 17 00:00:00 2001 From: smjiao Date: Tue, 19 Sep 2023 15:13:08 +0800 Subject: [PATCH 2/2] fix bash config sync status bug --- 0006-fix-bash-config-sync-status-bug.patch | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/0006-fix-bash-config-sync-status-bug.patch b/0006-fix-bash-config-sync-status-bug.patch index b4f4e6d..8e7f37d 100644 --- a/0006-fix-bash-config-sync-status-bug.patch +++ b/0006-fix-bash-config-sync-status-bug.patch @@ -20,11 +20,11 @@ index 608cd58..36016a9 100644 Description: bash type config analyze """ +import json - + from ragdoll.config_model.base_handler_config import BaseHandlerConfig +from ragdoll.const.conf_handler_const import SYNCHRONIZED, NOT_SYNCHRONIZE - - + + class BashConfig(BaseHandlerConfig): @@ -45,3 +47,19 @@ class BashConfig(BaseHandlerConfig): content = content + value + "\n" @@ -55,29 +55,29 @@ index 071e8c5..c598bf1 100644 from ragdoll import util from ragdoll.const.conf_files import yang_conf_list -from ragdoll.log.log import LOGGER - + TARGETDIR = GitTools().target_dir - + @@ -39,7 +38,7 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 get the status of the domain get the status of whether the domain has been synchronized # noqa: E501 - -- :param body: + +- :param body: + :param body: :type body: dict | bytes - + :rtype: SyncStatus @@ -132,7 +131,7 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 code_num = real_conf_res_code base_rsp = BaseResponse(code_num, "Failed to get the real config of the all hosts in domain.") return base_rsp, code_num -- # Match the actual configuration with the expected configuration, and output the +- # Match the actual configuration with the expected configuration, and output the + # Match the actual configuration with the expected configuration, and output the # configuration in the same format that can be compared with the expected result. sync_status = SyncStatus(domain_name=domain, host_status=[]) @@ -151,10 +150,10 @@ def get_the_sync_status_of_domain(body=None): # noqa: E501 - + comp_res = "" for d_man_conf in manage_confs: - if d_man_conf.get("filePath").split(":")[-1] == d_conf_path: @@ -104,19 +104,19 @@ index 071e8c5..c598bf1 100644 file_path = d_file.file_path file_list.append(file_path) @@ -251,7 +248,7 @@ def query_real_confs(body=None): # noqa: E501 - + query the real configuration value in the current hostId node # noqa: E501 - -- :param body: + +- :param body: + :param body: :type body: dict | bytes - + :rtype: List[RealConfInfo] @@ -284,7 +281,7 @@ def query_real_confs(body=None): # noqa: E501 "Please add the host information first") return base_rsp, code_num - -- # get all hosts managed by the current domain. + +- # get all hosts managed by the current domain. + # get all hosts managed by the current domain. # If host_list is empty, query all hosts in the current domain. # If host_list is not empty, the actual contents of the currently given host are queried. @@ -124,20 +124,20 @@ index 071e8c5..c598bf1 100644 @@ -424,7 +421,7 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 """ synchronize the configuration information of the configuration domain to the host # noqa: E501 - -- :param body: + +- :param body: + :param body: :type body: dict | bytes - + :rtype: List[HostSyncResult] @@ -434,7 +431,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 - + domain = body.domain_name sync_list = body.sync_list - LOGGER.info("sync_list is {}".format(sync_list)) - + host_sync_confs = dict() - + @@ -511,7 +507,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 contents = d_man_conf.get("contents") object_parse = ObjectParse() @@ -147,7 +147,7 @@ index 071e8c5..c598bf1 100644 sync_conf_url = conf_tools.load_url_by_conf().get("sync_url") headers = {"Content-Type": "application/json"} @@ -520,8 +515,6 @@ def sync_conf_to_host_from_domain(body=None): # noqa: E501 - + resp_code = json.loads(sync_response.text).get('code') resp = json.loads(sync_response.text).get('data').get('resp') - LOGGER.info("resp_code IS {}".format(resp_code)) @@ -155,6 +155,6 @@ index 071e8c5..c598bf1 100644 conf_sync_res = ConfSyncedRes(file_path=file_path, result="") if resp_code == "200" and resp.get('sync_result') is True: --- +-- 2.38.1.windows.1 -- Gitee