From f195764fdb4ba48571cb5e4b8598cc87e8ce3749 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Thu, 11 Jan 2024 08:36:56 -0500 Subject: [PATCH] [6.12.z] Non tabular output denied for CSV conversion (#13742) Non tabular output denied for CSV conversion (cherry picked from commit 39be0d7f962dc5bb55946a5034d239709e799592) Co-authored-by: jyejare --- robottelo/cli/hammer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/robottelo/cli/hammer.py b/robottelo/cli/hammer.py index 661042050e6..cf14cd2f0d7 100644 --- a/robottelo/cli/hammer.py +++ b/robottelo/cli/hammer.py @@ -34,10 +34,23 @@ def _normalize_obj(obj): return obj +def is_csv(output): + """Verifies if the output string is eligible for converting into CSV""" + sniffer = csv.Sniffer() + try: + sniffer.sniff(output) + return True + except csv.Error: + return False + + def parse_csv(output): """Parse CSV output from Hammer CLI and convert it to python dictionary.""" # ignore warning about puppet and ostree deprecation output.replace('Puppet and OSTree will no longer be supported in Katello 3.16\n', '') + # Validate if the output is eligible for CSV conversions else return as it is + if not is_csv(output): + return output reader = csv.reader(output.splitlines()) # Generate the key names, spaces will be converted to dashes "-" keys = [_normalize(header) for header in next(reader)]