Skip to content

Commit

Permalink
Added verification to the collect_early_data()
Browse files Browse the repository at this point in the history
* in the _set_activity(), _set_pkg_object(), _set_executed(),
  _set_nevra(), _set_signature() in all of these functions there is
  now some extra verification to make sure that the data that needs to
  be set is actully set
  • Loading branch information
Andrew-ang9 committed Nov 19, 2024
1 parent 5be973f commit 3270170
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions convert2rhel/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,52 @@ def finish_collection(self, success=False):

def _set_activity(self):
"""Set the activity that convert2rhel is going to perform"""
self.activity = tool_opts.activity
try:
self.activity = tool_opts.activity
if not self.activity:
raise ValueError("Activity is not set in tool_opts")
except Exception as e:
print(f"Error setting activity: {e}")

Check warning on line 116 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L114-L116

Added lines #L114 - L116 were not covered by tests

def _set_pkg_object(self):
"""Set pkg_object which is used to get information about installed Convert2RHEL"""
# the index position is there because get_installed_pkg_objects return list, which is filtered and
# should contain just one item
self._pkg_object = pkghandler.get_installed_pkg_objects(name="convert2rhel")[0]
try:
pkg_objects = pkghandler.get_installed_pkg_objects(name="convert2rhel")
if not pkg_objects:
raise ValueError("No installed package objects found for convert2rhel")

Check warning on line 123 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L123

Added line #L123 was not covered by tests
self._pkg_object = pkg_objects[0]
except Exception as e:
print(f"Error setting pkg_object: {e}")

Check warning on line 126 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L125-L126

Added lines #L125 - L126 were not covered by tests

def _set_executed(self):
"""Set how was Convert2RHEL executed"""
self.executed = " ".join(utils.hide_secrets(args=sys.argv))
try:
self.executed = " ".join(utils.hide_secrets(args=sys.argv))
if not self.executed:
raise ValueError("Executed command is not set")
except Exception as e:
print(f"Error setting executed: {e}")

Check warning on line 135 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L133-L135

Added lines #L133 - L135 were not covered by tests

def _set_nevra(self):
"""Set NEVRA of installed Convert2RHEL"""
self.nevra = pkghandler.get_pkg_nevra(self._pkg_object, include_zero_epoch=True)
try:
self.nevra = pkghandler.get_pkg_nevra(self._pkg_object, include_zero_epoch=True)
if not self.nevra:
raise ValueError("NEVRA is not set")
except Exception as e:
print(f"Error setting nevra: {e}")

Check warning on line 144 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L142-L144

Added lines #L142 - L144 were not covered by tests

def _set_signature(self):
"""Set signature of installed Convert2RHEL"""
package = pkghandler.get_installed_pkg_information(str(self._pkg_object))[0]
self.signature = package.signature
try:
package_info = pkghandler.get_installed_pkg_information(str(self._pkg_object))
if not package_info:
raise ValueError("No package information found for convert2rhel")

Check warning on line 151 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L151

Added line #L151 was not covered by tests
self.signature = package_info[0].signature
if not self.signature:
raise ValueError("Signature is not set")
except Exception as e:
print(f"Error setting signature: {e}")

Check warning on line 156 in convert2rhel/breadcrumbs.py

View check run for this annotation

Codecov / codecov/patch

convert2rhel/breadcrumbs.py#L154-L156

Added lines #L154 - L156 were not covered by tests

def _set_started(self):
"""Set start time of activity"""
Expand Down

0 comments on commit 3270170

Please sign in to comment.