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)]