diff --git a/0001-fix-bug-repeated-display-of-vulnerabilities.patch b/0001-fix-bug-repeated-display-of-vulnerabilities.patch deleted file mode 100644 index 6cf2916..0000000 --- a/0001-fix-bug-repeated-display-of-vulnerabilities.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 83752eec95b4aff92786d09b6291700ed0c405a1 Mon Sep 17 00:00:00 2001 -From: rabbitali -Date: Tue, 29 Aug 2023 21:35:08 +0800 -Subject: [PATCH] the problem of repeated display of vulnerabilities fixed by hot patches -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - ---- - ceres/manages/vulnerability_manage.py | 9 ++++++++- - 1 file changed, 8 insertions(+), 1 deletion(-) - -diff --git a/ceres/manages/vulnerability_manage.py b/ceres/manages/vulnerability_manage.py -index 3f85d3d..747df61 100644 ---- a/ceres/manages/vulnerability_manage.py -+++ b/ceres/manages/vulnerability_manage.py -@@ -435,6 +435,7 @@ class VulnerabilityManage: - if not applied_hotpatch_info_list: - return result - -+ record_key_set = {} - for cve_id, patch_name, hotpatch_status in applied_hotpatch_info_list: - rpm = patch_name.split("-", 1)[0] - # Refer to this example, the CVE can be marked as fixed only if all hotpatch are applied. -@@ -442,7 +443,12 @@ class VulnerabilityManage: - # CVE-2023-1111 redis-6.2.5-1/ACC-1-1/redis-benchmark ACTIVED - # CVE-2023-1111 redis-6.2.5-1/ACC-1-1/redis-cli ACTIVED - # CVE-2023-1111 redis-6.2.5-1/ACC-1-1/redis-server NOT-APPLIED -- if f"{cve_id}-{rpm}" not in self.available_hotpatch_key_set and hotpatch_status in ("ACTIVED", "ACCEPTED"): -+ record_key = f"{cve_id}-{rpm}" -+ if ( -+ (record_key not in self.available_hotpatch_key_set) -+ and (hotpatch_status in ("ACTIVED", "ACCEPTED")) -+ and record_key not in record_key_set -+ ): - result.append( - { - "cve_id": cve_id, -@@ -451,6 +457,7 @@ class VulnerabilityManage: - "hp_status": hotpatch_status, - } - ) -+ record_key_set.add(record_key) - return result - - def cve_fix(self, unfixed_cve_info: dict) -> Tuple[str, dict]: --- -2.33.0 - diff --git a/0002-update-query-disk-info-func.patch b/0002-update-query-disk-info-func.patch deleted file mode 100644 index b246880..0000000 --- a/0002-update-query-disk-info-func.patch +++ /dev/null @@ -1,279 +0,0 @@ -From 01c845220663a2572b6559bc25b52da1b2863256 Mon Sep 17 00:00:00 2001 -From: rabbitali -Date: Wed, 30 Aug 2023 10:59:52 +0800 -Subject: [PATCH 1/1] update query disk info func - ---- - ceres/manages/collect_manage.py | 38 ++--- - ceres/tests/manages/test_collect_manage.py | 163 +++++++++++++++++---- - 2 files changed, 152 insertions(+), 49 deletions(-) - -diff --git a/ceres/manages/collect_manage.py b/ceres/manages/collect_manage.py -index 3472903..145d6dc 100644 ---- a/ceres/manages/collect_manage.py -+++ b/ceres/manages/collect_manage.py -@@ -17,6 +17,7 @@ import pwd - import re - from socket import AF_INET, SOCK_DGRAM, socket - from typing import Any, Dict, List, Union -+import xml.etree.ElementTree as ET - - from ceres.conf.constant import ( - HOST_COLLECT_INFO_SUPPORT, -@@ -305,30 +306,33 @@ class Collect: - } - ] - """ -- code, stdout, _ = execute_shell_command("lshw -json -c disk") -+ code, stdout, _ = execute_shell_command("lshw -xml -c disk") - if code != CommandExitCode.SUCCEED: - LOGGER.error(stdout) - return [] - -- # Convert the command result to a json string -- # lshw_data e.g "{...},{...},{...}" -- lshw_data = f"[{stdout}]" -- - try: -- disk_info_list = json.loads(lshw_data) -- except json.decoder.JSONDecodeError: -- LOGGER.warning("Json conversion error, " "please check command 'lshw -json -c disk'") -- disk_info_list = [] -+ tree = ET.ElementTree(ET.fromstring(stdout)) -+ except ET.ParseError as error: -+ LOGGER.error(error) -+ LOGGER.warning("disk info parse error, please check command 'lshw -xml -c disk'") -+ return [] -+ -+ disk_list = tree.findall("node") -+ -+ if not disk_list: -+ return [] - - res = [] -- if disk_info_list: -- for disk_info in disk_info_list: -- res.append( -- { -- "model": disk_info.get('description') or disk_info.get('product'), -- "capacity": f"{disk_info.get('size', 0) // 10 ** 9}GB", -- } -- ) -+ for node in disk_list: -+ model = node.find("description") if node.find("product") is None else node.find("product") -+ size = node.find("size") -+ res.append( -+ { -+ "model": model.text if model is not None else "unknown", -+ "capacity": f"{int(size.text) / (1024**3)} GB" if size is not None else "unknown", -+ } -+ ) - - return res - -diff --git a/ceres/tests/manages/test_collect_manage.py b/ceres/tests/manages/test_collect_manage.py -index b27af55..243aa4c 100644 ---- a/ceres/tests/manages/test_collect_manage.py -+++ b/ceres/tests/manages/test_collect_manage.py -@@ -17,6 +17,7 @@ import pwd - import unittest - import warnings - from unittest import mock -+import xml.etree.ElementTree as ET - - from ceres.conf.constant import CommandExitCode - from ceres.manages.collect_manage import Collect -@@ -454,60 +455,158 @@ class TestCollectManage(unittest.TestCase): - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_succeed_and_only_contain_description( - self, mock_execute_shell_command - ): -- mock_execute_shell_command.return_value = ( -- CommandExitCode.SUCCEED, -- '{"description": "ATA Disk", "size": 42949672960}', -- "", -- ) -- self.assertEqual([{"model": "ATA Disk", "capacity": "42GB"}], Collect()._get_disk_info()) -+ cmd_output = """ -+ -+ -+ -+ -+ -+ -+ Virtual I/O device -+ 0 -+ virtio@3 -+ /dev/vda -+ 42949672960 -+ -+ -+ -+ -+ -+ -+ -+ Partitioned disk -+ MS-DOS partition table -+ -+ -+ -+ -+ -+ -+""" -+ mock_execute_shell_command.return_value = CommandExitCode.SUCCEED, cmd_output, "" -+ self.assertEqual([{"model": "Virtual I/O device", "capacity": "40.0 GB"}], Collect()._get_disk_info()) - - @mock.patch('ceres.manages.collect_manage.execute_shell_command') - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_succeed_and_has_no_description_or_product( - self, mock_execute_shell_command - ): -- mock_execute_shell_command.return_value = ( -- CommandExitCode.SUCCEED, -- '{"size": 42949672960}', -- "", -- ) -- self.assertEqual([{"model": None, "capacity": "42GB"}], Collect()._get_disk_info()) -+ cmd_output = """ -+ -+ -+ -+ -+ -+ -+ 0 -+ virtio@3 -+ /dev/vda -+ 42949672960 -+ -+ -+ -+ -+ -+ -+ -+ Partitioned disk -+ MS-DOS partition table -+ -+ -+ -+ -+ -+ -+""" -+ mock_execute_shell_command.return_value = CommandExitCode.SUCCEED, cmd_output, "" -+ self.assertEqual([{"model": "unknown", "capacity": "40.0 GB"}], Collect()._get_disk_info()) - - @mock.patch('ceres.manages.collect_manage.execute_shell_command') - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_succeed_and_contain_description_and_product( - self, mock_execute_shell_command - ): -- mock_execute_shell_command.return_value = ( -- CommandExitCode.SUCCEED, -- '{"description": "ATA Disk", "size": 42949672960,"product": "MOCK PRODUCT"}', -- "", -- ) -- self.assertEqual([{"model": "ATA Disk", "capacity": "42GB"}], Collect()._get_disk_info()) -+ cmd_output = """ -+ -+ -+ -+ -+ -+ -+ Virtual I/O device -+ ATA Disk -+ 0 -+ virtio@3 -+ /dev/vda -+ 42949672960 -+ -+ -+ -+ -+ -+ -+ -+ Partitioned disk -+ MS-DOS partition table -+ -+ -+ -+ -+ -+ -+""" -+ mock_execute_shell_command.return_value = CommandExitCode.SUCCEED, cmd_output, "" -+ self.assertEqual([{"model": "ATA Disk", "capacity": "40.0 GB"}], Collect()._get_disk_info()) - - @mock.patch('ceres.manages.collect_manage.execute_shell_command') - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_succeed_and_only_contain_product( - self, mock_execute_shell_command - ): -- mock_execute_shell_command.return_value = ( -- CommandExitCode.SUCCEED, -- '{"product": "MOCK PRODUCT", "size": 42949672960}', -- "", -- ) -- self.assertEqual([{"model": "MOCK PRODUCT", "capacity": "42GB"}], Collect()._get_disk_info()) -+ cmd_output = """ -+ -+ -+ -+ -+ -+ -+ MOCK PRODUCT -+ 0 -+ virtio@3 -+ /dev/vda -+ 42949672960 -+ -+ -+ -+ -+ -+ -+ -+ Partitioned disk -+ MS-DOS partition table -+ -+ -+ -+ -+ -+ -+""" -+ mock_execute_shell_command.return_value = CommandExitCode.SUCCEED, cmd_output, "" -+ self.assertEqual([{"model": "MOCK PRODUCT", "capacity": "40.0 GB"}], Collect()._get_disk_info()) - - @mock.patch('ceres.manages.collect_manage.execute_shell_command') - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_fail(self, mock_execute_shell_command): - mock_execute_shell_command.return_value = CommandExitCode.FAIL, "", "" - self.assertEqual([], Collect()._get_disk_info()) - -- @mock.patch.object(json, "loads") -+ @mock.patch.object(ET, "ElementTree") - @mock.patch('ceres.manages.collect_manage.execute_shell_command') - def test_get_disk_info_should_return_disk_info_when_shell_command_execute_succeed_but_decode_error( -- self, mock_execute_shell_command, mock_json_loads -+ self, mock_execute_shell_command, mock_parse_xml - ): -- mock_execute_shell_command.return_value = ( -- CommandExitCode.SUCCEED, -- '{"product": "MOCK PRODUCT", "size": 42949672960}', -- "", -- ) -- mock_json_loads.side_effect = json.decoder.JSONDecodeError('', '', int()) -+ mock_cmd_output = """ -+ -+ -+ -+ -+""" -+ mock_execute_shell_command.return_value = CommandExitCode.SUCCEED, mock_cmd_output, "" -+ mock_parse_xml.side_effect = ET.ParseError - self.assertEqual([], Collect()._get_disk_info()) --- -2.33.0 - diff --git a/aops-ceres-v1.3.0.tar.gz b/aops-ceres-v1.3.0.tar.gz deleted file mode 100644 index 8aa4781..0000000 Binary files a/aops-ceres-v1.3.0.tar.gz and /dev/null differ diff --git a/aops-ceres-v1.3.1.tar.gz b/aops-ceres-v1.3.1.tar.gz new file mode 100644 index 0000000..5c66c47 Binary files /dev/null and b/aops-ceres-v1.3.1.tar.gz differ diff --git a/aops-ceres.spec b/aops-ceres.spec index 668c6b9..adb87fe 100644 --- a/aops-ceres.spec +++ b/aops-ceres.spec @@ -1,12 +1,10 @@ Name: aops-ceres -Version: v1.3.0 -Release: 3 +Version: v1.3.1 +Release: 1 Summary: An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on. License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} Source0: %{name}-%{version}.tar.gz -Patch0001: 0001-fix-bug-repeated-display-of-vulnerabilities.patch -Patch0002: 0002-update-query-disk-info-func.patch BuildRequires: python3-setuptools Requires: python3-requests python3-jsonschema python3-libconf @@ -20,7 +18,7 @@ An agent which needs to be adopted in client, it managers some plugins, such as %prep -%autosetup -n %{name}-%{version} -p1 +%autosetup -n %{name}-%{version} # build for aops-ceres @@ -41,6 +39,10 @@ An agent which needs to be adopted in client, it managers some plugins, such as %changelog +* Mon Sep 11 2023 zhuyuncheng - v1.3.1-1 +- update rollback task logic, better returned log +- update status code and return None when installed_rpm or available_rpm is empty + * Wed Aug 30 2023 wenxin - v1.3.0-3 - update query disk info func