Skip to content

Commit 46b806a

Browse files
[6.14.z] Non tabular output denied for CSV conversion (#13745)
Non tabular output denied for CSV conversion (cherry picked from commit 39be0d7) Co-authored-by: jyejare <[email protected]>
1 parent 190c46f commit 46b806a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

robottelo/cli/hammer.py

+13
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,23 @@ def _normalize_obj(obj):
3434
return obj
3535

3636

37+
def is_csv(output):
38+
"""Verifies if the output string is eligible for converting into CSV"""
39+
sniffer = csv.Sniffer()
40+
try:
41+
sniffer.sniff(output)
42+
return True
43+
except csv.Error:
44+
return False
45+
46+
3747
def parse_csv(output):
3848
"""Parse CSV output from Hammer CLI and convert it to python dictionary."""
3949
# ignore warning about puppet and ostree deprecation
4050
output.replace('Puppet and OSTree will no longer be supported in Katello 3.16\n', '')
51+
# Validate if the output is eligible for CSV conversions else return as it is
52+
if not is_csv(output):
53+
return output
4154
reader = csv.reader(output.splitlines())
4255
# Generate the key names, spaces will be converted to dashes "-"
4356
keys = [_normalize(header) for header in next(reader)]

0 commit comments

Comments
 (0)