diff --git a/vmaas-go/go.mod b/vmaas-go/go.mod index 8e7edb76..e828e979 100644 --- a/vmaas-go/go.mod +++ b/vmaas-go/go.mod @@ -11,7 +11,7 @@ require ( github.com/prometheus/client_golang v1.20.5 github.com/redhatinsights/app-common-go v1.6.8 github.com/redhatinsights/platform-go-middlewares v1.0.0 - github.com/redhatinsights/vmaas-lib v1.14.7 + github.com/redhatinsights/vmaas-lib v1.15.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.10.0 github.com/zsais/go-gin-prometheus v0.1.0 diff --git a/vmaas-go/go.sum b/vmaas-go/go.sum index bf422115..d1c18fe2 100644 --- a/vmaas-go/go.sum +++ b/vmaas-go/go.sum @@ -115,10 +115,8 @@ github.com/redhatinsights/app-common-go v1.6.8 h1:hyExMp6WHprlGkHKElQvSFF2ZPX8XT github.com/redhatinsights/app-common-go v1.6.8/go.mod h1:KW0BK+bnhp3kXU8BFwebQXqCqjdkcRewZsDlXCSNMyo= github.com/redhatinsights/platform-go-middlewares v1.0.0 h1:OxyiYt+VmNo+UucK/ey0b6UDFnpCni6JoGPeisGmmNI= github.com/redhatinsights/platform-go-middlewares v1.0.0/go.mod h1:dRH6XOjiZDbw8STvk6NNC7mMwqhTaV7X+1tn1oXOs24= -github.com/redhatinsights/vmaas-lib v1.14.7-0.20250110172305-47fcde3ab5ec h1:zPmL4fay1/v7Vv3BP3r/qmhiMZn+2ThfKDElJ1nQdRY= -github.com/redhatinsights/vmaas-lib v1.14.7-0.20250110172305-47fcde3ab5ec/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk= -github.com/redhatinsights/vmaas-lib v1.14.7 h1:EwFa6M+sNjRQ/SD48wEkvMZnXiMdzvQnIoG8kYo3h9E= -github.com/redhatinsights/vmaas-lib v1.14.7/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk= +github.com/redhatinsights/vmaas-lib v1.15.0 h1:iBqNd/CHBtIre5kjwSHZLcDPG8rgHhlGN5H02tje+ww= +github.com/redhatinsights/vmaas-lib v1.15.0/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= diff --git a/vmaas/reposcan/exporter.py b/vmaas/reposcan/exporter.py index f1c3ea0f..4a898095 100755 --- a/vmaas/reposcan/exporter.py +++ b/vmaas/reposcan/exporter.py @@ -6,6 +6,7 @@ # pylint: disable=too-many-lines import glob +import json import os import sqlite3 @@ -23,6 +24,7 @@ DEFAULT_KEEP_COPIES = "2" DUMP = '/data/vmaas.db' DUMP_COMPRESSED = f"{DUMP}.zstd" +DUMP_SCHEMA_VERSION = 1 LOGGER = get_logger(__name__) CFG = Config() @@ -105,7 +107,9 @@ def dump(self, timestamp): self._dump_cves(dump) self._dump_modules(dump) self._dump_csaf(dump) + self._dump_os_releases(dump) self._dump_dbchange(dump, timestamp) + self._dump_dump_schema_version(dump) except Exception as err: # pylint: disable=broad-except # database exceptions caught here LOGGER.exception("Failed to create dbdump", exc_info=err) @@ -690,6 +694,20 @@ def _dump_csaf(self, dump): for csaf_status_id, name in cursor: dump.execute("INSERT INTO csaf_product_status VALUES (?, ?)", (csaf_status_id, name)) + def _dump_os_releases(self, dump): + """Select all OS releases and put them into dictionary""" + dump.execute("""CREATE TABLE IF NOT EXISTS operating_system ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + major INTEGER NOT NULL, + minor INTEGER NOT NULL, + system_profile JSONB) + """) + with self._named_cursor() as cursor: + cursor.execute("SELECT id, name, major, minor, system_profile FROM operating_system") + for os_id, name, major, minor, system_profile in cursor: + dump.execute("INSERT INTO operating_system VALUES (?, ?, ?, ?, ?)", (os_id, name, major, minor, json.dumps(system_profile))) + def _dump_dbchange(self, dump, timestamp): """Select db change details""" dump.execute("""create table if not exists dbchange ( @@ -714,6 +732,13 @@ def _dump_dbchange(self, dump, timestamp): timestamp )) + def _dump_dump_schema_version(self, dump): + """Put dump schema version number into dump""" + dump.execute("""CREATE TABLE IF NOT EXISTS dump_schema ( + version INTEGER NOT NULL) + """) + dump.execute("INSERT INTO dump_schema VALUES (?)", (DUMP_SCHEMA_VERSION,)) + def main(): """ Main loop."""