Skip to content

Commit 641c688

Browse files
committed
1395080 - exit gracefully on missing report
if report doesn't exist exit gracefully. If it is pack-scan, the default report, the user didn't run initconfig. Instead of exiting we simply add it to the in-memory config before running the scan. While it seems like a good idea to write the report to the config, we modify the config with other temporary runtime options which would pollute the config if written. For now, we are opting to simply add the report in-memory.
1 parent cf7ff7b commit 641c688

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/rho/clicommands.py

+45
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,51 @@ def _do_command(self):
583583

584584
if self.options.report:
585585
reportobj = self.config.get_report(self.options.report)
586+
587+
# if report doesn't exist exit gracefully. If it is pack-scan, the
588+
# default report, the user didn't run initconfig. Instead of
589+
# exiting we simply add it to the in-memory config before running
590+
# the scan. While it seems like a good idea to write the report to
591+
# the config, we modify the config with other temporary runtime
592+
# options which would pollute the config if written. For now, we
593+
# are opting to simply add the report in-memory.
594+
if reportobj is None:
595+
if self.options.report == 'pack-scan':
596+
# automatically add pack-scan to the config
597+
reportobj = config.Report(
598+
name="pack-scan",
599+
report_format=['date.date',
600+
'uname.hostname',
601+
'redhat-release.release',
602+
'redhat-packages.is_redhat',
603+
'redhat-packages.num_rh_packages',
604+
'redhat-packages.num_installed_packages',
605+
'redhat-packages.last_installed',
606+
'redhat-packages.last_built',
607+
'date.anaconda_log', 'date.machine_id',
608+
'date.filesystem_create',
609+
'date.yum_history', 'virt-what.type',
610+
'virt.virt', 'virt.num_guests',
611+
'virt.num_running_guests', 'cpu.count',
612+
'cpu.socket_count', 'ip', 'port',
613+
'auth.name', 'auth.type',
614+
'auth.username', 'error',
615+
'dmi.system-manufacturer',
616+
'etc-release.etc-release',
617+
'instnum.instnum',
618+
'redhat-release.version',
619+
'subman.virt.host_type',
620+
'systemid.system_id',
621+
'subman.virt.is_guest',
622+
'uname.hardware_platform'],
623+
output_filename="pack-scan.csv")
624+
625+
self.config.add_report(reportobj)
626+
else:
627+
print(_("ERROR: Report %s was not found.") %
628+
self.options.report)
629+
sys.exit(1)
630+
586631
fileobj = open(os.path.expanduser(os.path.expandvars(
587632
reportobj.output_filename)), "w")
588633
fields = reportobj.report_format

0 commit comments

Comments
 (0)