!66 [sync] PR-65: 修改查询被依赖报数据库连接失败问题

From: @openeuler-sync-bot
Reviewed-by: @solarhu,@ruebb,@solarhu
Signed-off-by: @solarhu
This commit is contained in:
openeuler-ci-bot 2021-09-03 06:27:22 +00:00 committed by Gitee
commit e6db7bc33c
2 changed files with 219 additions and 1 deletions

212
0004-fix-depend-query.patch Normal file
View File

@ -0,0 +1,212 @@
diff --git a/packageship/application/apps/package/view.py b/packageship/application/apps/package/view.py
index 86072fc61f78ddcae87a53728d1490821ccc41a7..3ca7ffa261d93b8868571e9bedf13f1232e4768e 100644
--- a/packageship/application/apps/package/view.py
+++ b/packageship/application/apps/package/view.py
@@ -108,14 +108,16 @@ class SourcePackages(ParsePackageMethod):
page_num = result.get("page_num")
page_size = result.get("page_size")
query_pkg_name = [result.get("query_pkg_name")] if result.get(
- "query_pkg_name") else []
+ "query_pkg_name") else None
find_package = Package()
try:
result_all = find_package.all_src_packages(
result.get("database_name"), page_num=page_num, page_size=page_size, package_list=query_pkg_name,
command_line=result.get("command_line"))
- except (ElasticSearchQueryException, DatabaseConfigException, PackageInfoGettingError) as e:
+ except (ElasticSearchQueryException, DatabaseConfigException):
return jsonify(self.rspmsg.body('connect_db_error'))
+ except PackageInfoGettingError:
+ return jsonify(self.rspmsg.body('pack_name_not_found'))
if result_all:
return jsonify(self.parse_package(result_all, page_size))
return jsonify(self.rspmsg.body("table_name_not_exist"))
@@ -167,14 +169,16 @@ class BinaryPackages(ParsePackageMethod):
page_num = result.get("page_num")
page_size = result.get("page_size")
query_pkg_name = [result.get("query_pkg_name")] if result.get(
- "query_pkg_name") else []
+ "query_pkg_name") else None
find_package = Package()
try:
result_all = find_package.all_bin_packages(
result.get("database_name"), page_num=page_num, page_size=page_size, package_list=query_pkg_name,
command_line=result.get("command_line"))
- except (ElasticSearchQueryException, DatabaseConfigException, PackageInfoGettingError) as e:
+ except (ElasticSearchQueryException, DatabaseConfigException):
return jsonify(self.rspmsg.body('connect_db_error'))
+ except PackageInfoGettingError:
+ return jsonify(self.rspmsg.body('pack_name_not_found'))
if result_all:
return jsonify(self.parse_package(result_all, page_size))
return jsonify(self.rspmsg.body("table_name_not_exist"))
diff --git a/packageship/application/query/pkg.py b/packageship/application/query/pkg.py
index 6c4e1f253ecf0cef68ab6319a9fae1731e826a8b..67e5c2e3a2cab3107c1d1fcb1edc618ed6f2a370 100644
--- a/packageship/application/query/pkg.py
+++ b/packageship/application/query/pkg.py
@@ -82,7 +82,7 @@ class QueryPackage(object):
Raises: DatabaseConfigException ElasticSearchQueryException
"""
self.rpm_type = SOURCE_DB_TYPE
- response = self._get_rpm_info(src_list, database, page_num, page_size, command_line)
+ response = self._get_rpm_info(database, page_num, page_size, command_line, rpm_list=src_list)
return response
def get_bin_info(self, binary_list, database, page_num, page_size, command_line=False):
@@ -98,7 +98,7 @@ class QueryPackage(object):
Raises: DatabaseConfigException ElasticSearchQueryException
"""
self.rpm_type = BINARY_DB_TYPE
- response = self._get_rpm_info(binary_list, database, page_num, page_size, command_line)
+ response = self._get_rpm_info(database, page_num, page_size, command_line, rpm_list=binary_list)
return response
def _query_src_bin_rpm(self, rpm_list, query_db_type, specify_db):
@@ -150,7 +150,7 @@ class QueryPackage(object):
return rpm_info
- def _get_rpm_info(self, rpm_list, database, page_num, page_size, command_line):
+ def _get_rpm_info(self, database, page_num, page_size, command_line, rpm_list=None):
"""
General method for obtaining package details
Args:
@@ -162,10 +162,16 @@ class QueryPackage(object):
Returns: result of query package details
"""
- self.index = UNDERLINE.join((database, self.rpm_type))
response = dict(total=0, data=[])
+ # If the query list is empty, return directly; if the query list is None, it means query all packages.
+ if isinstance(rpm_list, list):
+ rpm_list = [rpm for rpm in rpm_list if rpm]
+ if not rpm_list:
+ return response
+
+ self.index = UNDERLINE.join((database, self.rpm_type))
# Used for Command Line,query all data and no Pagination
- if command_line and not rpm_list:
+ if command_line and rpm_list is None:
query_result = self._db_session.scan(index=self.index, body=QueryBody.QUERY_ALL)
total_num = self._db_session.count(index=self.index, body=QueryBody.QUERY_ALL)
response['total'] = total_num.get('count')
@@ -190,6 +196,7 @@ class QueryPackage(object):
if query_all else query_result['hits']['total']['value']
response['total'] = total_num
except KeyError:
+ response = dict(total=0, data=[])
return response
return response
@@ -211,7 +218,7 @@ class QueryPackage(object):
# Query specify rpm_list of Command line mode
query_body = self._process_query_terms(DEFAULT_PAGE_NUM, MAX_PAGE_SIZE, rpm_list)
else:
- if not rpm_list:
+ if rpm_list is None:
# Query all data and Pagination of UI mode
query_body = self._format_paging_query_all(page_num, page_size)
query_all = True
diff --git a/test/cli/depend_commands/__init__.py b/test/cli/depend_commands/__init__.py
index 1aab4d66def3400065e077e884258ab446e0f2da..13fbaa063d39e3a19c9dec58fc480fe05c35aa3b 100755
--- a/test/cli/depend_commands/__init__.py
+++ b/test/cli/depend_commands/__init__.py
@@ -130,6 +130,7 @@ class DependTestBase(ClientTest):
if not pkg_info:
continue
ret_dict_p["hits"]["hits"].append(pkg_info)
+ ret_dict_p['hits']['total']['value'] = len(pkg_lst)
@staticmethod
def make_newline_split_res(ln, lines, idx):
@@ -244,12 +245,12 @@ class DependTestBase(ClientTest):
if handle_tolong_name_in_newline(ln, source_lines, idx):
continue
source_lines.append(split_ln)
-
+
if not all(normal_query_judgment_lst):
raise ValueError(
"check Your expected str please, must be a normal query result"
)
-
+
return binary_lines, source_lines
def assert_result(self):
@@ -264,12 +265,12 @@ class DependTestBase(ClientTest):
current_bin, current_src = self._process_depend_command_value(self.print_result)
self.assertListEqual(sorted(excepted_bin), sorted(current_bin))
self.assertListEqual(sorted(excepted_src), sorted(current_src))
-
+
def assert_exc_result(self):
"""assert_exc_result
"""
- super(DependTestBase,self).assert_result()
-
+ super(DependTestBase, self).assert_result()
+
def _es_search_result(self, index: str, body: dict):
"""
Get different return values through different call parameters
@@ -281,7 +282,7 @@ class DependTestBase(ClientTest):
ret_dict(dict):Parsable es-like data for the project
"""
- ret_dict = {"hits": {"hits": []}}
+ ret_dict = {"hits": {"hits": [], "total": {"value": 0}}}
if index == "databaseinfo":
return DATA_BASE_INFO
elif "binary" in index:
diff --git a/test/cli/package_command/pkg_list/test_pkg_list.py b/test/cli/package_command/pkg_list/test_pkg_list.py
index 3c7f9930a773c9aea1eafeb6e0739a10d6c5b7db..da5300b1ca5935d116700f0d20ca8352e16bf464 100644
--- a/test/cli/package_command/pkg_list/test_pkg_list.py
+++ b/test/cli/package_command/pkg_list/test_pkg_list.py
@@ -77,8 +77,8 @@ HINT :Make sure the table is valid"""
test pkgInfoGetingError for all bin packages
"""
self.excepted_str = """
-ERROR_CONTENT :Failed to Connect the database
-HINT :Check the connection"""
+ERROR_CONTENT :The querying package does not exist in the databases
+HINT :Use the correct package name and try again"""
self.command_params = ["os-version"]
self.mock_es_search(return_value=DATA_BASE_INFO)
self.mock_es_scan(return_value=[])
diff --git a/test/cli/package_command/pkg_list/test_pkg_list_s.py b/test/cli/package_command/pkg_list/test_pkg_list_s.py
index 3044c93e7ac5b64fa1de8195c766bd10fd554e0b..45c949dcbe007e719a2004b22a83b72aa8c59986 100644
--- a/test/cli/package_command/pkg_list/test_pkg_list_s.py
+++ b/test/cli/package_command/pkg_list/test_pkg_list_s.py
@@ -77,8 +77,8 @@ HINT :Make sure the table is valid"""
test pkgInfoGettingError
"""
self.excepted_str = """
-ERROR_CONTENT :Failed to Connect the database
-HINT :Check the connection"""
+ERROR_CONTENT :The querying package does not exist in the databases
+HINT :Use the correct package name and try again"""
self.command_params = ["os-version", "-s"]
self.mock_es_search(return_value=DATA_BASE_INFO)
self.mock_es_scan(return_value=[])
diff --git a/test/test_module/test_database_query/test_database_query_package/test_query_bin_info.py b/test/test_module/test_database_query/test_database_query_package/test_query_bin_info.py
index e59e82e5768015a328ce2ceecf4d60e5a655b9b8..3254eb8b2089bc8a76ba1844d60d92938ae888d9 100644
--- a/test/test_module/test_database_query/test_database_query_package/test_query_bin_info.py
+++ b/test/test_module/test_database_query/test_database_query_package/test_query_bin_info.py
@@ -41,7 +41,7 @@ class TestQueryBinaryPkgInfo(TestCase):
"""
self.session.scan = MagicMock(return_value=self.ALL_BINARY_RPM_INFO)
self.session.count = MagicMock(return_value={"count": 5})
- query_result = self.query_package.get_bin_info(binary_list=[], database='os_version_1', page_num=1, page_size=20,
+ query_result = self.query_package.get_bin_info(binary_list=None, database='os_version_1', page_num=1, page_size=20,
command_line=True)
self.assertIsNotNone(query_result['data'])
@@ -52,7 +52,7 @@ class TestQueryBinaryPkgInfo(TestCase):
"""
self.session.query = MagicMock(return_value=self.ALL_BINARY_INFO_PAGING)
self.session.count = MagicMock(return_value={"count": 5})
- query_result = self.query_package.get_bin_info(binary_list=[], database='os_version_1', page_num=1, page_size=5,
+ query_result = self.query_package.get_bin_info(binary_list=None, database='os_version_1', page_num=1, page_size=5,
command_line=False)
self.assertEqual(len(query_result['data']), 5)

View File

@ -1,6 +1,6 @@
Name: pkgship
Version: 2.2.0
Release: 4
Release: 5
Summary: Pkgship implements rpm package dependence ,maintainer, patch query and so on.
License: Mulan 2.0
URL: https://gitee.com/openeuler/pkgship
@ -8,6 +8,7 @@ Source0: https://gitee.com/openeuler/pkgship-%{version}.tar.gz
Patch0001: 0001-bugfix-pkginfo.patch
Patch0002: 0002-fix-install-and-start-script-info.patch
Patch0003: 0003-bugfix-binary-name-mapping-source.patch
Patch0004: 0004-fix-depend-query.patch
BuildArch: noarch
@ -113,6 +114,11 @@ create_dir_file /var/log/pkgship-operation 700 d
%attr(0640,pkgshipuser,pkgshipuser) /lib/systemd/system/pkgship.service
%changelog
* Fri Sep 3 2021 Haiwei Li <lihaiwei8@huawei.com> - 2.2.0-5
- When the query is dependent, a list containing only None is entered,
- which causes an error in the es query.
- Modify the es query encapsulation interface to filter the None value.
* Fri Sep 3 2021 Haiwei Li <lihaiwei8@huawei.com> - 2.2.0-4
- Due to the inappropriate mapping rules between the binary package and the source package,
- the source package corresponding to the binary package cannot be found when the query bedepend require,