Skip to content

Commit c7ff320

Browse files
committed
feat: New spec and parser for host facts count of Satellite (#4206)
Signed-off-by: Huanhuan Li <[email protected]>
1 parent 3f4151b commit c7ff320

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

insights/parsers/satellite_postgresql_query.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-----------------------------------------------------------------------------------------------------------
1111
SatelliteCoreTaskReservedResourceCount - command ``psql -d pulpcore -c 'select count(*) from core_taskreservedresource' --csv``
1212
-------------------------------------------------------------------------------------------------------------------------------
13+
SatelliteHostFactsCount - command ``psql -d foreman -c 'select count(*) from fact_names' --csv``
14+
------------------------------------------------------------------------------------------------
1315
SatelliteIgnoreSourceRpmsRepos - command ``psql -d foreman -c "select id, name from katello_root_repositories where ignorable_content like '%srpm%' and mirroring_policy='mirror_complete'" --csv``
1416
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1517
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):
219221
columns = ['count']
220222

221223

224+
@parser(Specs.satellite_host_facts_count)
225+
class SatelliteHostFactsCount(SatellitePostgreSQLQuery):
226+
"""
227+
Parse the output of the command ``psql -d foreman -c 'select count(*) from fact_names' --csv``.
228+
229+
Sample output::
230+
231+
count
232+
12121
233+
234+
Examples:
235+
>>> type(host_facts_obj)
236+
<class 'insights.parsers.satellite_postgresql_query.SatelliteHostFactsCount'>
237+
>>> host_facts_obj[0]['count']
238+
'12121'
239+
"""
240+
columns = ['count']
241+
242+
222243
@parser(Specs.satellite_ignore_source_rpms_repos)
223244
class SatelliteIgnoreSourceRpmsRepos(SatellitePostgreSQLQuery):
224245
"""

insights/specs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ class Specs(SpecSet):
677677
satellite_custom_hiera = RegistryPoint()
678678
satellite_enabled_features = RegistryPoint()
679679
satellite_ignore_source_rpms_repos = RegistryPoint()
680+
satellite_host_facts_count = RegistryPoint(no_obfuscate=['hostname', 'ip'])
680681
satellite_katello_repos_with_muliple_ref = RegistryPoint()
681682
satellite_logs_table_size = RegistryPoint(no_obfuscate=['hostname', 'ip'])
682683
satellite_missed_pulp_agent_queues = RegistryPoint()

insights/specs/default.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ class DefaultSpecs(Specs):
569569
)
570570
satellite_custom_hiera = simple_file("/etc/foreman-installer/custom-hiera.yaml")
571571
satellite_enabled_features = simple_command("/usr/bin/curl -sk https://localhost:9090/features --connect-timeout 5", deps=[IsSatellite])
572+
satellite_host_facts_count = simple_command(
573+
"/usr/bin/sudo -iu postgres /usr/bin/psql -d foreman -c 'select count(*) from fact_names' --csv",
574+
deps=[IsSatellite]
575+
)
572576
satellite_ignore_source_rpms_repos = simple_command(
573577
"/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",
574578
deps=[IsSatellite]

insights/tests/parsers/test_satellite_postgresql_query.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@
229229
7,Red Hat Enterprise Linux 8 for x86_64 - BaseOS RPMs 8
230230
""".strip()
231231

232+
SATELLITE_HOST_FACTS_CONTENT = """
233+
count
234+
12121
235+
""".strip()
236+
232237

233238
def test_HTL_doc_examples():
234239
settings = satellite_postgresql_query.SatelliteAdminSettings(context_wrap(SATELLITE_SETTINGS_1))
@@ -243,6 +248,7 @@ def test_HTL_doc_examples():
243248
rhv_hosts = satellite_postgresql_query.SatelliteRHVHostsCount(context_wrap(SATELLITE_RHV_HOSTS_COUNT))
244249
revoked_certs = satellite_postgresql_query.SatelliteRevokedCertCount(context_wrap(SATELLITE_REVOKED_CERT_COUNT))
245250
ignore_srpm_repos = satellite_postgresql_query.SatelliteIgnoreSourceRpmsRepos(context_wrap(SATELLITE_IGNORE_SOURCE_RPMS_REPOS))
251+
host_facts = satellite_postgresql_query.SatelliteHostFactsCount(context_wrap(SATELLITE_HOST_FACTS_CONTENT))
246252
globs = {
247253
'table': settings,
248254
'resources_table': resources_table,
@@ -255,7 +261,8 @@ def test_HTL_doc_examples():
255261
'logs_table': logs_table,
256262
'rhv_hosts': rhv_hosts,
257263
'revoked_certs': revoked_certs,
258-
'i_srpm_repos': ignore_srpm_repos
264+
'i_srpm_repos': ignore_srpm_repos,
265+
'host_facts_obj': host_facts
259266
}
260267
failed, _ = doctest.testmod(satellite_postgresql_query, globs=globs)
261268
assert failed == 0
@@ -407,3 +414,9 @@ def test_satellite_ignore_srpm_repos():
407414
assert i_srpms_repos[0]['name'] == 'Red Hat Enterprise Linux 8 for x86_64 - AppStream RPMs 8'
408415
assert i_srpms_repos[1]['id'] == '7'
409416
assert i_srpms_repos[1]['name'] == 'Red Hat Enterprise Linux 8 for x86_64 - BaseOS RPMs 8'
417+
418+
419+
def test_satellite_host_facts():
420+
host_facts = satellite_postgresql_query.SatelliteHostFactsCount(context_wrap(SATELLITE_HOST_FACTS_CONTENT))
421+
assert len(host_facts) == 1
422+
assert int(host_facts[0]['count']) == 12121

0 commit comments

Comments
 (0)