From 4848a4f5e9244fe7e7dfc7958982857cf3dfeb44 Mon Sep 17 00:00:00 2001
From: young <954906362@qq.com>
Date: Tue, 9 May 2023 09:31:04 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=89=E4=B8=AAissue?=
 =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 aops-apollo.spec                   |  2 +-
 apollo/cron/download_sa_manager.py | 22 ++++++++++------------
 conf/apollo.ini                    |  4 ++--
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/aops-apollo.spec b/aops-apollo.spec
index 2d3a771..1e15294 100644
--- a/aops-apollo.spec
+++ b/aops-apollo.spec
@@ -20,7 +20,7 @@ Cve management service, monitor machine vulnerabilities and provide fix function
 
 %package -n dnf-hotpatch-plugin
 Summary: dnf hotpatch plugin
-Requires: python3-hawkey python3-dnf syscare
+Requires: python3-hawkey python3-dnf syscare >= 1.0.1
 
 %description -n dnf-hotpatch-plugin
 dnf hotpatch plugin, it's about hotpatch query and fix
diff --git a/apollo/cron/download_sa_manager.py b/apollo/cron/download_sa_manager.py
index 6ce97bb..a46ad5a 100644
--- a/apollo/cron/download_sa_manager.py
+++ b/apollo/cron/download_sa_manager.py
@@ -10,16 +10,17 @@
 # PURPOSE.
 # See the Mulan PSL v2 for more details.
 # ******************************************************************************/
+from gevent import monkey; monkey.patch_all(thread=False)
+import gevent
 import datetime
 import os
 import re
 import shutil
 import sqlalchemy
-import requests
+import urllib.request
+import urllib.error
 import retrying
 from retrying import retry
-from gevent import monkey; monkey.patch_all(ssl=False)
-import gevent
 
 from apollo.conf import configuration
 from apollo.conf.constant import ADVISORY_SAVED_PATH, TIMED_TASK_CONFIG_PATH
@@ -64,7 +65,6 @@ class TimedDownloadSATask(TimedTaskBase):
                 ElasticsearchProxy.connect(proxy)
 
                 download_record, download_failed_advisory = proxy.get_advisory_download_record()
-
                 sa_name_list = TimedDownloadSATask.get_incremental_sa_name_list(
                     download_record)
 
@@ -134,11 +134,10 @@ class TimedDownloadSATask(TimedTaskBase):
             response body or "", "" means request failed
         """
         try:
-            response = requests.get(url, timeout=10)
-            if response.status_code != requests.codes["ok"]:
-                return None
-            return response
-        except requests.exceptions.RequestException:
+            response = urllib.request.urlopen(url, timeout=10)
+            return response.read()
+        except urllib.error.HTTPError:
+            LOGGER.info("Exception %s")
             return ""
 
     @staticmethod
@@ -155,7 +154,7 @@ class TimedDownloadSATask(TimedTaskBase):
             response = TimedDownloadSATask.get_response(sa_url)
             if response:
                 with open(os.path.join(ADVISORY_SAVED_PATH, sa_name), "wb")as w:
-                    w.write(response.content)
+                    w.write(response)
             else:
                 LOGGER.error(f"Download failed request timeout: {sa_name}")
                 TimedDownloadSATask.save_sa_record.append({"advisory_year": advisory_year,
@@ -178,8 +177,7 @@ class TimedDownloadSATask(TimedTaskBase):
         try:
             response = TimedDownloadSATask.get_response(TimedDownloadSATask.cvrf_url + "/index.txt")
             if response:
-                html = response.text
-                sa_list = html.replace("\r", "").split("\n")
+                sa_list = response.decode("utf-8").replace("\r", "").split("\n")
                 security_files = [
                     # 2021/cvrf-openEuler-SA-2021-1022.xml, we don't need the first five characters
                     sa_name[5:] for sa_name in sa_list
diff --git a/conf/apollo.ini b/conf/apollo.ini
index 412fff1..f215e63 100644
--- a/conf/apollo.ini
+++ b/conf/apollo.ini
@@ -40,5 +40,5 @@ wsgi-file=manage.py
 daemonize=/var/log/aops/uwsgi/apollo.log
 http-timeout=600
 harakiri=600
-processes=2
-threads=4
+processes=1
+gevent=100
-- 
Gitee

