Skip to content

Commit

Permalink
Fix ModelViolationError while parsing repo files
Browse files Browse the repository at this point in the history
This error occurs when repo file has invalid definition, specifically
the 'name' entry of the config file.

Jira: RHEL-19249
  • Loading branch information
tomasfratrik committed Jul 17, 2024
1 parent f822cb8 commit 2a79e8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,22 @@ def get_sysctls_status():

def get_repositories_status():
""" Get a basic information about YUM repositories installed in the system """
return RepositoriesFacts(repositories=repofileutils.get_parsed_repofiles())
try:
return RepositoriesFacts(repositories=repofileutils.get_parsed_repofiles())
except repofileutils.InvalidRepoDefinition as e:
raise StopActorExecutionError(
message='Invalid repository definition',
details={
'details': str(e),
'file': e.repofile,
'repoid': e.repoid,
'hint': 'To resolve this issue, please visit: {url}'
.format(
url='https://access.redhat.com/solutions/3185891'
)
}
)



def get_selinux_status():
Expand Down
12 changes: 11 additions & 1 deletion repos/system_upgrade/common/libraries/repofileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
api.current_logger().warning('repofileutils.py: failed to import dnf')


class InvalidRepoDefinition(Exception):
def __init__(self, message, repofile=None, repoid=None):
super().__init__(message)
self.repofile = repofile
self.repoid = repoid


def _parse_repository(repoid, repo_data):
def asbool(x):
return x == '1'
Expand Down Expand Up @@ -38,7 +45,10 @@ def parse_repofile(repofile):
with open(repofile, mode='r') as fp:
cp = utils.parse_config(fp, strict=False)
for repoid in cp.sections():
data.append(_parse_repository(repoid, dict(cp.items(repoid))))
try:
data.append(_parse_repository(repoid, dict(cp.items(repoid))))
except Exception as e:
raise InvalidRepoDefinition(e, repofile=repofile, repoid=repoid)
return RepositoryFile(file=repofile, data=data)


Expand Down

0 comments on commit 2a79e8c

Please sign in to comment.