update to version 1.3.1-1
This commit is contained in:
parent
2868001f19
commit
60f35e6163
@ -1,49 +0,0 @@
|
||||
From 83752eec95b4aff92786d09b6291700ed0c405a1 Mon Sep 17 00:00:00 2001
|
||||
From: rabbitali <shusheng.wen@outlook.com>
|
||||
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
|
||||
|
||||
@ -1,279 +0,0 @@
|
||||
From 01c845220663a2572b6559bc25b52da1b2863256 Mon Sep 17 00:00:00 2001
|
||||
From: rabbitali <shusheng.wen@outlook.com>
|
||||
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 = """<?xml version="1.0" standalone="yes" ?>
|
||||
+<!-- generated by lshw-B.012.18 -->
|
||||
+<!-- GCC 7.3.0 -->
|
||||
+<!-- Linux 4.19.90-2003.4.0.0036.oe1.x86_64 #1 SMP Mon Mar 23 19:10:41 UTC 2020 x86_64 -->
|
||||
+<!-- GNU libc 2 (glibc 2.28) -->
|
||||
+<list>
|
||||
+ <node id="virtio3" claimed="true" class="disk">
|
||||
+ <description>Virtual I/O device</description>
|
||||
+ <physid>0</physid>
|
||||
+ <businfo>virtio@3</businfo>
|
||||
+ <logicalname>/dev/vda</logicalname>
|
||||
+ <size units="bytes">42949672960</size>
|
||||
+ <configuration>
|
||||
+ <setting id="driver" value="virtio_blk" />
|
||||
+ <setting id="logicalsectorsize" value="512" />
|
||||
+ <setting id="sectorsize" value="512" />
|
||||
+ <setting id="signature" value="64860148" />
|
||||
+ </configuration>
|
||||
+ <capabilities>
|
||||
+ <capability id="partitioned" >Partitioned disk</capability>
|
||||
+ <capability id="partitioned:dos" >MS-DOS partition table</capability>
|
||||
+ </capabilities>
|
||||
+ <hints>
|
||||
+ <hint name="icon" value="disc" />
|
||||
+ </hints>
|
||||
+ </node>
|
||||
+</list>
|
||||
+"""
|
||||
+ 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 = """<?xml version="1.0" standalone="yes" ?>
|
||||
+<!-- generated by lshw-B.012.18 -->
|
||||
+<!-- GCC 7.3.0 -->
|
||||
+<!-- Linux 4.19.90-2003.4.0.0036.oe1.x86_64 #1 SMP Mon Mar 23 19:10:41 UTC 2020 x86_64 -->
|
||||
+<!-- GNU libc 2 (glibc 2.28) -->
|
||||
+<list>
|
||||
+ <node id="virtio3" claimed="true" class="disk">
|
||||
+ <physid>0</physid>
|
||||
+ <businfo>virtio@3</businfo>
|
||||
+ <logicalname>/dev/vda</logicalname>
|
||||
+ <size units="bytes">42949672960</size>
|
||||
+ <configuration>
|
||||
+ <setting id="driver" value="virtio_blk" />
|
||||
+ <setting id="logicalsectorsize" value="512" />
|
||||
+ <setting id="sectorsize" value="512" />
|
||||
+ <setting id="signature" value="64860148" />
|
||||
+ </configuration>
|
||||
+ <capabilities>
|
||||
+ <capability id="partitioned" >Partitioned disk</capability>
|
||||
+ <capability id="partitioned:dos" >MS-DOS partition table</capability>
|
||||
+ </capabilities>
|
||||
+ <hints>
|
||||
+ <hint name="icon" value="disc" />
|
||||
+ </hints>
|
||||
+ </node>
|
||||
+</list>
|
||||
+"""
|
||||
+ 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 = """<?xml version="1.0" standalone="yes" ?>
|
||||
+<!-- generated by lshw-B.012.18 -->
|
||||
+<!-- GCC 7.3.0 -->
|
||||
+<!-- Linux 4.19.90-2003.4.0.0036.oe1.x86_64 #1 SMP Mon Mar 23 19:10:41 UTC 2020 x86_64 -->
|
||||
+<!-- GNU libc 2 (glibc 2.28) -->
|
||||
+<list>
|
||||
+ <node id="virtio3" claimed="true" class="disk">
|
||||
+ <description>Virtual I/O device</description>
|
||||
+ <product>ATA Disk</product>
|
||||
+ <physid>0</physid>
|
||||
+ <businfo>virtio@3</businfo>
|
||||
+ <logicalname>/dev/vda</logicalname>
|
||||
+ <size units="bytes">42949672960</size>
|
||||
+ <configuration>
|
||||
+ <setting id="driver" value="virtio_blk" />
|
||||
+ <setting id="logicalsectorsize" value="512" />
|
||||
+ <setting id="sectorsize" value="512" />
|
||||
+ <setting id="signature" value="64860148" />
|
||||
+ </configuration>
|
||||
+ <capabilities>
|
||||
+ <capability id="partitioned" >Partitioned disk</capability>
|
||||
+ <capability id="partitioned:dos" >MS-DOS partition table</capability>
|
||||
+ </capabilities>
|
||||
+ <hints>
|
||||
+ <hint name="icon" value="disc" />
|
||||
+ </hints>
|
||||
+ </node>
|
||||
+</list>
|
||||
+"""
|
||||
+ 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 = """<?xml version="1.0" standalone="yes" ?>
|
||||
+<!-- generated by lshw-B.012.18 -->
|
||||
+<!-- GCC 7.3.0 -->
|
||||
+<!-- Linux 4.19.90-2003.4.0.0036.oe1.x86_64 #1 SMP Mon Mar 23 19:10:41 UTC 2020 x86_64 -->
|
||||
+<!-- GNU libc 2 (glibc 2.28) -->
|
||||
+<list>
|
||||
+ <node id="virtio3" claimed="true" class="disk">
|
||||
+ <product>MOCK PRODUCT</product>
|
||||
+ <physid>0</physid>
|
||||
+ <businfo>virtio@3</businfo>
|
||||
+ <logicalname>/dev/vda</logicalname>
|
||||
+ <size units="bytes">42949672960</size>
|
||||
+ <configuration>
|
||||
+ <setting id="driver" value="virtio_blk" />
|
||||
+ <setting id="logicalsectorsize" value="512" />
|
||||
+ <setting id="sectorsize" value="512" />
|
||||
+ <setting id="signature" value="64860148" />
|
||||
+ </configuration>
|
||||
+ <capabilities>
|
||||
+ <capability id="partitioned" >Partitioned disk</capability>
|
||||
+ <capability id="partitioned:dos" >MS-DOS partition table</capability>
|
||||
+ </capabilities>
|
||||
+ <hints>
|
||||
+ <hint name="icon" value="disc" />
|
||||
+ </hints>
|
||||
+ </node>
|
||||
+</list>
|
||||
+"""
|
||||
+ 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 = """<?xml version="1.0" standalone="yes" ?>
|
||||
+<!-- generated by lshw-B.012.18 -->
|
||||
+<!-- GCC 7.3.0 -->
|
||||
+<!-- Linux 4.19.90-2003.4.0.0036.oe1.x86_64 #1 SMP Mon Mar 23 19:10:41 UTC 2020 x86_64 -->
|
||||
+<!-- GNU libc 2 (glibc 2.28) -->
|
||||
+"""
|
||||
+ 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
|
||||
|
||||
Binary file not shown.
BIN
aops-ceres-v1.3.1.tar.gz
Normal file
BIN
aops-ceres-v1.3.1.tar.gz
Normal file
Binary file not shown.
@ -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<zhu-yuncheng@huawei.com> - 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<shusheng.wen@outlook.com> - v1.3.0-3
|
||||
- update query disk info func
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user