diff --git a/insights/parsers/satellite_postgresql_query.py b/insights/parsers/satellite_postgresql_query.py index 718a2d3ad..daedaa1d0 100644 --- a/insights/parsers/satellite_postgresql_query.py +++ b/insights/parsers/satellite_postgresql_query.py @@ -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`` @@ -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) + + >>> host_facts_obj[0]['count'] + '12121' + """ + columns = ['count'] + + @parser(Specs.satellite_ignore_source_rpms_repos) class SatelliteIgnoreSourceRpmsRepos(SatellitePostgreSQLQuery): """ diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index 68eb9d420..eed4aadf5 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -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() diff --git a/insights/specs/default.py b/insights/specs/default.py index c5a9cb30c..bcf926212 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -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] diff --git a/insights/tests/parsers/test_satellite_postgresql_query.py b/insights/tests/parsers/test_satellite_postgresql_query.py index b0cfc83a5..cbaf60276 100644 --- a/insights/tests/parsers/test_satellite_postgresql_query.py +++ b/insights/tests/parsers/test_satellite_postgresql_query.py @@ -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)) @@ -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, @@ -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 @@ -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