Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Bringer better testable #240

Merged
merged 4 commits into from
May 4, 2023

Conversation

matejak
Copy link
Contributor

@matejak matejak commented Apr 14, 2023

Description:

This PR moves functionality formerly located in the data_fetch module to the Bringer, so one can use polymorphism to create great mocks by just subclassing.
Now, it is possible to test handling of threads and fetch methods separately, because Bringer just calls a method to fetch a URI, and then wraps the process in a thread.

Rationale:

  • The PR decomposes and concentrates the existing functionality, making it easier to test.

Review Hints:

  • Business as usual, tests pass, bringer still able to copy things, touched functions were not used by other parts of the addon.

matejak added 2 commits April 14, 2023 13:38
- Extract wait for network to a separate utility function
- Delegate wrapping of a fetch by thread to a method of Bringer
- Remove the now-empty intermediate fetching helper functions from data_fetch
@matejak matejak requested a review from jan-cerny April 14, 2023 11:55
@matejak matejak added port-RHEL8 Port this PR to the rhel8-branch port-rawhide Port this PR to the master labels Apr 14, 2023
Copy link
Member

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far it works great for me because I tried to build the update image and run the Anaconda installation and changed various SCAP content in the Security Policy Scope.

However, I have found an issue, which isn't caused by the contents of this PR: #244

fetch_data_thread = AnacondaThread(
name=fetching_thread_name,
target=self.fetch_operation,
args=(self.content_uri, self.dest_file_name, ca_certs_path),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed a weird thing that was there before but I think we can talk about it nevertheless. The URI is a property of the class (self.content_uri) but the certificate path isn't a property of the class but a variable (ca_certs_path) and is passed down. But, both are arguments of the fetch_content content method. So the arguments of fetch_content are each handled differently at this moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the common argument to a generl fetch operation would be the URI that we store in the class anyway, and then other arguments depend on how we fetch, certs being needed only if we fetch from network using an "s" protocol.
Therefore, it is cleaner to store those variable arguments in the instance as well.

return fetching_thread_name

def finish_content_fetch(self, fetching_thread_name, fingerprint):
def fetch_operation(self, uri, out_file, ca_certs_path=None):
return data_fetch.fetch_data(uri, out_file, ca_certs_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for having this wrapper function? Can we simply move code from the data_fetch.fetch_data to fetch_operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other function is somewhat coupled with the data_fetch module - the way it is unit-tested as well as the way exceptions it can raise are defined.
The whole data_fetch module could be merged into the bringer in the future, but I think that it is OK to have such thin wrapper.
The fetch operation as a separate method is convenient to be able to override it in child classes e.g. for testing purposes.

@jan-cerny jan-cerny self-assigned this Apr 25, 2023
matejak added 2 commits April 28, 2023 13:20
- Make ca_certs a class attribute
- Don't pass those items as method arguments all the time,
  simply reference them from the instance.
@scrutinizer-notifier
Copy link

The inspection completed: 5 updated code elements

Copy link
Member

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to download various content usign the GUI and I have performed a RHEL9.1 installation from GUI and also an unattended installation with a kickstart.

@jan-cerny jan-cerny added this to the 2.1.0 milestone May 4, 2023
@jan-cerny jan-cerny merged commit e54f0be into OpenSCAP:rhel9-branch May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
port-rawhide Port this PR to the master port-RHEL8 Port this PR to the rhel8-branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants