Skip to content

Commit

Permalink
feat(reposcan): export OS release system profiles to dump
Browse files Browse the repository at this point in the history
RHINENG-15338
  • Loading branch information
jdobes committed Jan 23, 2025
1 parent 5ee85ee commit da43765
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vmaas-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions vmaas-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 25 additions & 0 deletions vmaas/reposcan/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint: disable=too-many-lines

import glob
import json
import os
import sqlite3

Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
Expand All @@ -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."""
Expand Down

0 comments on commit da43765

Please sign in to comment.