Skip to content

Commit

Permalink
feat: New spec and parser for host facts count of Satellite (#4206)
Browse files Browse the repository at this point in the history
Signed-off-by: Huanhuan Li <huali@redhat.com>
  • Loading branch information
xiangce committed Sep 5, 2024
1 parent 3f4151b commit c7ff320
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions insights/parsers/satellite_postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-----------------------------------------------------------------------------------------------------------
SatelliteCoreTaskReservedResourceCount - command ``psql -d pulpcore -c 'select count(*) from core_taskreservedresource' --csv``
-------------------------------------------------------------------------------------------------------------------------------
SatelliteHostFactsCount - command ``psql -d foreman -c 'select count(*) from fact_names' --csv``
------------------------------------------------------------------------------------------------
SatelliteIgnoreSourceRpmsRepos - command ``psql -d foreman -c "select id, name from katello_root_repositories where ignorable_content like '%srpm%' and mirroring_policy='mirror_complete'" --csv``
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SatelliteKatellloReposWithMultipleRef - command ``psql -d foreman -c "select repository_href, count(*) from katello_repository_references group by repository_href having count(*) > 1;" --csv``
Expand Down Expand Up @@ -219,6 +221,25 @@ class SatelliteCoreTaskReservedResourceCount(SatellitePostgreSQLQuery):
columns = ['count']


@parser(Specs.satellite_host_facts_count)
class SatelliteHostFactsCount(SatellitePostgreSQLQuery):
"""
Parse the output of the command ``psql -d foreman -c 'select count(*) from fact_names' --csv``.
Sample output::
count
12121
Examples:
>>> type(host_facts_obj)
<class 'insights.parsers.satellite_postgresql_query.SatelliteHostFactsCount'>
>>> host_facts_obj[0]['count']
'12121'
"""
columns = ['count']


@parser(Specs.satellite_ignore_source_rpms_repos)
class SatelliteIgnoreSourceRpmsRepos(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 @@ -677,6 +677,7 @@ class Specs(SpecSet):
satellite_custom_hiera = RegistryPoint()
satellite_enabled_features = RegistryPoint()
satellite_ignore_source_rpms_repos = RegistryPoint()
satellite_host_facts_count = RegistryPoint(no_obfuscate=['hostname', 'ip'])
satellite_katello_repos_with_muliple_ref = RegistryPoint()
satellite_logs_table_size = RegistryPoint(no_obfuscate=['hostname', 'ip'])
satellite_missed_pulp_agent_queues = 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 @@ -569,6 +569,10 @@ class DefaultSpecs(Specs):
)
satellite_custom_hiera = simple_file("/etc/foreman-installer/custom-hiera.yaml")
satellite_enabled_features = simple_command("/usr/bin/curl -sk https://localhost:9090/features --connect-timeout 5", deps=[IsSatellite])
satellite_host_facts_count = simple_command(
"/usr/bin/sudo -iu postgres /usr/bin/psql -d foreman -c 'select count(*) from fact_names' --csv",
deps=[IsSatellite]
)
satellite_ignore_source_rpms_repos = simple_command(
"/usr/bin/sudo -iu postgres /usr/bin/psql -d foreman -c \"select id, name from katello_root_repositories where ignorable_content like '%srpm%' and mirroring_policy='mirror_complete'\" --csv",
deps=[IsSatellite]
Expand Down
15 changes: 14 additions & 1 deletion insights/tests/parsers/test_satellite_postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
7,Red Hat Enterprise Linux 8 for x86_64 - BaseOS RPMs 8
""".strip()

SATELLITE_HOST_FACTS_CONTENT = """
count
12121
""".strip()


def test_HTL_doc_examples():
settings = satellite_postgresql_query.SatelliteAdminSettings(context_wrap(SATELLITE_SETTINGS_1))
Expand All @@ -243,6 +248,7 @@ def test_HTL_doc_examples():
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))
host_facts = satellite_postgresql_query.SatelliteHostFactsCount(context_wrap(SATELLITE_HOST_FACTS_CONTENT))
globs = {
'table': settings,
'resources_table': resources_table,
Expand All @@ -255,7 +261,8 @@ def test_HTL_doc_examples():
'logs_table': logs_table,
'rhv_hosts': rhv_hosts,
'revoked_certs': revoked_certs,
'i_srpm_repos': ignore_srpm_repos
'i_srpm_repos': ignore_srpm_repos,
'host_facts_obj': host_facts
}
failed, _ = doctest.testmod(satellite_postgresql_query, globs=globs)
assert failed == 0
Expand Down Expand Up @@ -407,3 +414,9 @@ def test_satellite_ignore_srpm_repos():
assert i_srpms_repos[0]['name'] == 'Red Hat Enterprise Linux 8 for x86_64 - AppStream RPMs 8'
assert i_srpms_repos[1]['id'] == '7'
assert i_srpms_repos[1]['name'] == 'Red Hat Enterprise Linux 8 for x86_64 - BaseOS RPMs 8'


def test_satellite_host_facts():
host_facts = satellite_postgresql_query.SatelliteHostFactsCount(context_wrap(SATELLITE_HOST_FACTS_CONTENT))
assert len(host_facts) == 1
assert int(host_facts[0]['count']) == 12121

0 comments on commit c7ff320

Please sign in to comment.