Skip to content

Commit

Permalink
feat(webapp): return and display latest change of repo in vmaas
Browse files Browse the repository at this point in the history
RHINENG-2608
  • Loading branch information
Tomáš Sasák committed Oct 18, 2023
1 parent 6cad19b commit 5c63420
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
7 changes: 4 additions & 3 deletions vmaas/webapp/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions vmaas/webapp/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
REPO_RELEASEVER,
REPO_PRODUCT,
REPO_REVISION,
REPO_LAST_CHANGE,
REPO_THIRD_PARTY
)
from vmaas.common.date_utils import format_datetime
Expand All @@ -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

Expand Down Expand Up @@ -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 = parse_datetime(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, []):
Expand All @@ -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'])
}

Expand Down
5 changes: 3 additions & 2 deletions vmaas/webapp/test/data/cache-dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions vmaas/webapp/test/data/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ cve_detail:
- AV:N/AC:H/Au:N/C:P/I:P/A:P
- Red Hat (CVE source)
dbchange:
cve_changes: 2019-03-07 09:17:23.799995+00:00
errata_changes: 2019-03-07 09:16:34.790980+00:00
cve_changes: '2019-03-07 09:17:23.799995+00:00'
errata_changes: '2019-03-07 09:16:34.790980+00:00'
exported: '2019-03-07T09:17:53.114083+00:00'
last_change: 2019-03-07 09:17:23.799995+00:00
repository_changes: 2019-03-07 09:16:34.689923+00:00
last_change: '2019-03-07 09:17:23.799995+00:00'
repository_changes: '2019-03-07 09:16:34.689923+00:00'
errata_detail:
RHBA-2015:0364: !!python/tuple
- Errata synopsis...
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions vmaas/webapp/test/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"url": str,
"basearch": Or(str, None),
"revision": str,
"last_change": str,
"label": str,
"cpes": [str],
"third_party": bool
Expand All @@ -91,6 +92,7 @@
"page_size": int,
"pages": int,
"last_change": str,
"latest_repo_change": str,
}

_errata = {
Expand Down
3 changes: 2 additions & 1 deletion vmaas/webapp/test/test_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5c63420

Please sign in to comment.