Skip to content

Commit

Permalink
Merge branch 'master' into podman-push
Browse files Browse the repository at this point in the history
  • Loading branch information
sambible authored Aug 1, 2024
2 parents 0b85362 + 6bc929b commit e69ebdf
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 342 deletions.
4 changes: 2 additions & 2 deletions pytest_fixtures/component/satellite_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@ def configure_hammer_no_negotiate(parametrized_enrolled_sat):
def hammer_logout(parametrized_enrolled_sat):
"""Logout in Hammer."""
result = parametrized_enrolled_sat.cli.Auth.logout()
assert result.split("\n")[1] == LOGGEDOUT
assert result[0]['message'] == LOGGEDOUT
yield
result = parametrized_enrolled_sat.cli.Auth.logout()
assert result.split("\n")[1] == LOGGEDOUT
assert result[0]['message'] == LOGGEDOUT


@pytest.fixture
Expand Down
36 changes: 12 additions & 24 deletions robottelo/cli/hammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import json
import re

from robottelo.logging import logger


def _normalize(header):
"""Replace empty spaces with '-' and lower all chars"""
Expand Down Expand Up @@ -35,31 +37,17 @@ 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', '')
is_rex = 'Job invocation' in output
is_pkg_list = 'Nvra' in output
# Validate if the output is eligible for CSV conversions else return as it is
if not is_csv(output) and not is_rex and not is_pkg_list:
return output
output = output.splitlines()[0:2] if is_rex else output.splitlines()
reader = csv.reader(output)
# Generate the key names, spaces will be converted to dashes "-"
keys = [_normalize(header) for header in next(reader)]
# For each entry, create a dict mapping each key with each value
return [dict(zip(keys, values, strict=True)) for values in reader if len(values) > 0]
"""Parse CSV output from Hammer CLI and return a Python dictionary."""
output = output.splitlines()

# Normalize the column names to use when generating the dictionary
try:
keys = [_normalize(header) for header in next(csv.reader(output))]
return [value for value in csv.DictReader(output[1:], fieldnames=keys)]
except csv.Error as err:
logger.error(f'Exception while parsing CSV output {output}: {err}')
raise


def parse_help(output):
Expand Down
2 changes: 1 addition & 1 deletion robottelo/cli/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def synchronize(cls, options, return_raw_response=None, timeout=3600000):
cls.command_sub = 'synchronize'
return cls.execute(
cls._construct_command(options),
output_format='base',
output_format='csv',
ignore_stderr=True,
return_raw_response=return_raw_response,
timeout=timeout,
Expand Down
Loading

0 comments on commit e69ebdf

Please sign in to comment.