Skip to content

Commit

Permalink
feat: New spec to get the count of revoked certificates on satellite (#…
Browse files Browse the repository at this point in the history
…3988)

Signed-off-by: Huanhuan Li <[email protected]>
  • Loading branch information
huali027 authored Jan 11, 2024
1 parent d89dfb0 commit 7b63a13
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions insights/parsers/satellite_postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
---------------------------------------------------------------------------------------------------------------------------------------
SatelliteQualifiedKatelloRepos - command ``psql -d foreman -c "select id, name, url, download_policy from katello_root_repositories where download_policy = 'background' or url is NULL" --csv``
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SatelliteRevokedCertCount - command ``psql -d candlepin -c \"select count(cp_certificate.id) from cp_cert_serial inner join cp_certificate on cp_certificate.serial_id = cp_cert_serial.id where cp_cert_serial.revoked = 't'\" --csv``
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SatelliteRHVHostsCount - command ``psql -d foreman -c "select count(*) from hosts where \"compute_resource_id\" in (select id from compute_resources where type='Foreman::Model::Ovirt')" --csv``
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SatelliteSCAStatus - command ``psql -d candlepin -c "select displayname, content_access_mode from cp_owner" --csv``
Expand Down Expand Up @@ -378,6 +380,25 @@ class SatelliteRHVHostsCount(SatellitePostgreSQLQuery):
columns = ['count']


@parser(Specs.satellite_revoked_cert_count)
class SatelliteRevokedCertCount(SatellitePostgreSQLQuery):
"""
Parse the output of the command ``psql -d candlepin -c "select count(cp_certificate.id) from cp_cert_serial inner join cp_certificate on cp_certificate.serial_id = cp_cert_serial.id where cp_cert_serial.revoked = 't'\" --csv``.
Sample output::
count
0
Examples:
>>> type(revoked_certs)
<class 'insights.parsers.satellite_postgresql_query.SatelliteRevokedCertCount'>
>>> revoked_certs[0]['count']
'0'
"""
columns = ['count']


@parser(Specs.satellite_sca_status)
class SatelliteSCAStatus(SatellitePostgreSQLQuery):
"""
Expand Down
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ class Specs(SpecSet):
satellite_provision_param_settings = RegistryPoint()
satellite_qualified_capsules = RegistryPoint()
satellite_qualified_katello_repos = RegistryPoint()
satellite_revoked_cert_count = RegistryPoint()
satellite_rhv_hosts_count = RegistryPoint()
satellite_sca_status = RegistryPoint()
satellite_settings = RegistryPoint()
Expand Down
4 changes: 4 additions & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ class DefaultSpecs(Specs):
"/usr/bin/sudo -iu postgres /usr/bin/psql -d foreman -c \"select id, name, url, download_policy from katello_root_repositories where download_policy = 'background' or url is NULL\" --csv",
deps=[IsSatellite]
)
satellite_revoked_cert_count = simple_command(
"/usr/bin/sudo -iu postgres /usr/bin/psql -d candlepin -c \"select count(cp_certificate.id) from cp_cert_serial inner join cp_certificate on cp_certificate.serial_id = cp_cert_serial.id where cp_cert_serial.revoked = 't'\" --csv",
deps=[IsSatellite]
)
satellite_rhv_hosts_count = simple_command(
"/usr/bin/sudo -iu postgres /usr/bin/psql -d foreman -c \"select count(*) from hosts where \"compute_resource_id\" in (select id from compute_resources where type='Foreman::Model::Ovirt')\" --csv",
deps=[IsSatellite]
Expand Down
13 changes: 13 additions & 0 deletions insights/tests/parsers/test_satellite_postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
2
""".strip()

SATELLITE_REVOKED_CERT_COUNT = """
count
0
""".strip()

SATELLITE_IGNORE_SOURCE_RPMS_REPOS = """
id,name
4,Red Hat Enterprise Linux 8 for x86_64 - AppStream RPMs 8
Expand All @@ -236,6 +241,7 @@ def test_HTL_doc_examples():
param_settings = satellite_postgresql_query.SatelliteProvisionParamSettings(context_wrap(SATELLITE_PROVISION_PARAMETERS_HIT_1))
logs_table = satellite_postgresql_query.SatelliteLogsTableSize(context_wrap(SATELLITE_LOGS_TABLE_SIZE1))
rhv_hosts = satellite_postgresql_query.SatelliteRHVHostsCount(context_wrap(SATELLITE_RHV_HOSTS_COUNT))
revoked_certs = satellite_postgresql_query.SatelliteRevokedCertCount(context_wrap(SATELLITE_REVOKED_CERT_COUNT))
ignore_srpm_repos = satellite_postgresql_query.SatelliteIgnoreSourceRpmsRepos(context_wrap(SATELLITE_IGNORE_SOURCE_RPMS_REPOS))
globs = {
'table': settings,
Expand All @@ -248,6 +254,7 @@ def test_HTL_doc_examples():
'param_settings': param_settings,
'logs_table': logs_table,
'rhv_hosts': rhv_hosts,
'revoked_certs': revoked_certs,
'i_srpm_repos': ignore_srpm_repos
}
failed, _ = doctest.testmod(satellite_postgresql_query, globs=globs)
Expand Down Expand Up @@ -382,6 +389,12 @@ def test_satelite_rhv_hosts():
assert int(rhv_hosts[0]['count']) == 2


def test_satelite_revoked_certs():
revoked_certs = satellite_postgresql_query.SatelliteRevokedCertCount(context_wrap(SATELLITE_REVOKED_CERT_COUNT))
assert len(revoked_certs) == 1
assert int(revoked_certs[0]['count']) == 0


def test_satellite_logs_table_size_except():
with pytest.raises(ParseException):
satellite_postgresql_query.SatelliteLogsTableSize(context_wrap(SATELLITE_LOGS_TABLE_SIZE3))
Expand Down

0 comments on commit 7b63a13

Please sign in to comment.