From e3f4dfc71c00884f7be323dac1c1de613a18ef74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Sas=C3=A1k?= Date: Wed, 18 Oct 2023 10:11:41 +0200 Subject: [PATCH] feat(webapp): return and display latest change of repo in vmaas RHINENG-2608 --- vmaas/webapp/cache.py | 7 ++++--- vmaas/webapp/repos.py | 10 ++++++++-- vmaas/webapp/test/data/cache-dump.sql | 5 +++-- vmaas/webapp/test/data/cache.yml | 8 ++++++++ vmaas/webapp/test/schemas.py | 2 ++ vmaas/webapp/test/test_repos.py | 3 ++- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/vmaas/webapp/cache.py b/vmaas/webapp/cache.py index 00faf4029..faf14698e 100755 --- a/vmaas/webapp/cache.py +++ b/vmaas/webapp/cache.py @@ -26,7 +26,8 @@ REPO_PRODUCT = 5 REPO_PRODUCT_ID = 6 REPO_REVISION = 7 -REPO_THIRD_PARTY = 8 +REPO_LAST_CHANGE = 8 +REPO_THIRD_PARTY = 9 # package detail indexes PKG_NAME_ID = 0 @@ -257,11 +258,11 @@ def _load_sqlite(self, data): self.src_pkg_id2pkg_ids.setdefault(src_pkg_id, array.array('q')).append(id) for row in self._sqlite_execute(data, """select id, label, name, url, basearch, releasever, - product, product_id, revision, third_party from repo_detail"""): + product, product_id, revision, last_change, third_party from repo_detail"""): id = row[0] url = row[3] repo = (row[1], row[2], url, row[4], row[5], row[6], row[7], - parse_datetime(row[8]), bool(row[9])) + parse_datetime(row[8]), parse_datetime(row[9]), bool(row[10])) self.repo_detail[id] = repo self.repolabel2ids.setdefault(repo[0], array.array('q')).append(id) diff --git a/vmaas/webapp/repos.py b/vmaas/webapp/repos.py index cc035b4ee..0c50ad984 100755 --- a/vmaas/webapp/repos.py +++ b/vmaas/webapp/repos.py @@ -11,6 +11,7 @@ REPO_RELEASEVER, REPO_PRODUCT, REPO_REVISION, + REPO_LAST_CHANGE, REPO_THIRD_PARTY ) from vmaas.common.date_utils import format_datetime @@ -28,8 +29,8 @@ def __init__(self, cache): @staticmethod def _modified_since(repo_detail, modified_since_dt): - if not modified_since_dt or (repo_detail[REPO_REVISION] is not None and - repo_detail[REPO_REVISION] > modified_since_dt): + if not modified_since_dt or (repo_detail[REPO_LAST_CHANGE] is not None and + repo_detail[REPO_LAST_CHANGE] > modified_since_dt): return True return False @@ -105,6 +106,7 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument actual_page_size = 0 repo_page_to_process, pagination_response = paginate(repos, page, page_size, filters=filters) + latest_repo_change = self.cache.dbchange['last_change'] for label in repo_page_to_process: cs_id = self.cache.label2content_set_id[label] for repo_id in self.cache.repolabel2ids.get(label, []): @@ -122,13 +124,17 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument "releasever": none2empty(repo_detail[REPO_RELEASEVER]), "product": repo_detail[REPO_PRODUCT], "revision": format_datetime(repo_detail[REPO_REVISION]), + "last_change": format_datetime(repo_detail[REPO_LAST_CHANGE]), "cpes": [self.cache.cpe_id2label[cpe_id] for cpe_id in cpe_ids], "third_party": repo_detail[REPO_THIRD_PARTY] }) + if repo_detail[REPO_LAST_CHANGE] > latest_repo_change: + latest_repo_change = repo_detail[REPO_LAST_CHANGE] actual_page_size += len(repolist[label]) response = { 'repository_list': repolist, + 'latest_repo_change': format_datetime(latest_repo_change), 'last_change': format_datetime(self.cache.dbchange['last_change']) } diff --git a/vmaas/webapp/test/data/cache-dump.sql b/vmaas/webapp/test/data/cache-dump.sql index 97dad5848..18335e29a 100644 --- a/vmaas/webapp/test/data/cache-dump.sql +++ b/vmaas/webapp/test/data/cache-dump.sql @@ -381,10 +381,11 @@ CREATE TABLE repo_detail ( product text, product_id integer, revision text, + last_change text, third_party integer ); -INSERT INTO "repo_detail" VALUES(801,'content set 1','content-set-name-1','https://www.repourl.com/repo1/','noarch','1','product1',501,'2019-08-01T06:00:00+00:00',0); -INSERT INTO "repo_detail" VALUES(802,'content set 2','content-set-name-2','https://www.repourl.com/repo2/','noarch','1','product2',502,'2019-08-02T06:00:00+00:00',0); +INSERT INTO "repo_detail" VALUES(801,'content set 1','content-set-name-1','https://www.repourl.com/repo1/','noarch','1','product1',501,'2019-08-01T06:00:00+00:00','2019-08-01T06:00:00+00:00',0); +INSERT INTO "repo_detail" VALUES(802,'content set 2','content-set-name-2','https://www.repourl.com/repo2/','noarch','1','product2',502,'2019-08-02T06:00:00+00:00','2019-08-02T06:00:00+00:00',0); CREATE TABLE string ( id integer primary key, string text diff --git a/vmaas/webapp/test/data/cache.yml b/vmaas/webapp/test/data/cache.yml index 5a621689b..20843b3ac 100644 --- a/vmaas/webapp/test/data/cache.yml +++ b/vmaas/webapp/test/data/cache.yml @@ -497,6 +497,7 @@ repo_detail: - Red Hat Enterprise Linux Server - 1 - 2018-04-10 09:02:26+00:00 + - 2018-04-10 09:02:26+00:00 - false 2: !!python/tuple - rhel-8-for-x86_64-rt-rpms @@ -507,6 +508,7 @@ repo_detail: - null - null - 2020-01-03 05:24:17+00:00 + - 2020-01-03 05:24:17+00:00 - false 3: !!python/tuple - rhel-8-for-x86_64-nfv-rpms @@ -517,6 +519,7 @@ repo_detail: - null - null - 2019-09-20 06:25:14+00:00 + - 2019-09-20 06:25:14+00:00 - false 4: !!python/tuple - rhel-8-for-x86_64-nfv-rpms @@ -527,6 +530,7 @@ repo_detail: - null - null - 2020-01-03 05:24:24+00:00 + - 2020-01-03 05:24:24+00:00 - false 5: !!python/tuple - rhel-8-for-x86_64-rt-rpms @@ -537,6 +541,7 @@ repo_detail: - null - null - 2019-09-20 06:25:12+00:00 + - 2019-09-20 06:25:12+00:00 - false 6: !!python/tuple - third-party-repo1 @@ -547,6 +552,7 @@ repo_detail: - null - null - 2019-09-20 06:25:12+00:00 + - 2019-09-20 06:25:12+00:00 - true 7: !!python/tuple - rhel-7-server-rhui-rpms @@ -557,6 +563,7 @@ repo_detail: - null - null - 2022-09-20 06:25:12+00:00 + - 2022-09-20 06:25:12+00:00 - false 8: !!python/tuple - rhel-8-for-x86_64-appstream-rhui-rpms @@ -567,6 +574,7 @@ repo_detail: - null - null - 2022-09-20 06:25:12+00:00 + - 2022-09-20 06:25:12+00:00 - false repolabel2ids: rhel-7-server-rpms: diff --git a/vmaas/webapp/test/schemas.py b/vmaas/webapp/test/schemas.py index efe5a98fd..8a6ffe694 100644 --- a/vmaas/webapp/test/schemas.py +++ b/vmaas/webapp/test/schemas.py @@ -80,6 +80,7 @@ "url": str, "basearch": Or(str, None), "revision": str, + "last_change": str, "label": str, "cpes": [str], "third_party": bool @@ -91,6 +92,7 @@ "page_size": int, "pages": int, "last_change": str, + "latest_repo_change": str, } _errata = { diff --git a/vmaas/webapp/test/test_repos.py b/vmaas/webapp/test/test_repos.py index 884eeb552..ef1828e4f 100644 --- a/vmaas/webapp/test/test_repos.py +++ b/vmaas/webapp/test/test_repos.py @@ -19,7 +19,8 @@ REPO_JSON_WITH_PREFIX = {"repository_list": ["rhul-rhel-7-server-rpms"]} EMPTY_RESPONSE = {"repository_list": {}, "page": 1, "page_size": 0, "pages": 0, - "last_change": "2019-03-07T09:17:23.799995+00:00"} + "last_change": "2019-03-07T09:17:23.799995+00:00", + "latest_repo_change": "2019-03-07T09:17:23.799995+00:00"} class TestRepoAPI(TestBase):