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

Test and use rules to components mapping #10638

Closed
wants to merge 15 commits into from

Conversation

jan-cerny
Copy link
Collaborator

@jan-cerny jan-cerny commented May 26, 2023

Description:

This PR is a follow up on PR #10609 and has been initially created by extracting some commits from there.

The PR introduces a new module ssg.components which is a basis for future use of the component data in our project. A simple unit test for this module is added as well.

The PR introduces the test that performs some basic checks that will help keep the component data consistent. This test tests the following facts:

  • presence of rule in a group that is known to map to a component
  • usage of templates in the rule that allow us to easily infer the component, eg. package_installed, package_removed, service_enabled
  • usage of platforms in the given rule that allow us to easily infer the component, eg. package platform.

The PR enforces component assignment for all rules in the linux_os/guide benchmark. That will prevent people from introducing a new rule without mapping it to a component.

For more details, please read the commit messages of every commit.

Rationale:

These changes will ensure the component data consistency. Mandatory component assignment will help content authors think about component outreach of new rules. The tests will help people assign the new rules to correct components.

Review Hints:

Remove some rules from some component, eg. remove the rule package_fapolicyd_installed from components/fapolicyd.yml and run ctest --verbose -R components to see how the test reacts. Also, try to build the content to see an error.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label May 26, 2023
@openshift-ci
Copy link

openshift-ci bot commented May 26, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@github-actions
Copy link

Start a new ephemeral environment with changes proposed in this pull request:

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@jan-cerny jan-cerny added enhancement General enhancements to the project. Highlight This PR/Issue should make it to the featured changelog. Infrastructure Our content build system labels May 26, 2023
@jan-cerny
Copy link
Collaborator Author

I have rebased this PR on the top of the latest upstream master branch.

@jan-cerny jan-cerny marked this pull request as ready for review May 31, 2023 08:09
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label May 31, 2023
@jan-cerny jan-cerny added this to the 0.1.69 milestone May 31, 2023
@codeclimate
Copy link

codeclimate bot commented May 31, 2023

Code Climate has analyzed commit f2c8236 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 3

The test coverage on the diff in this pull request is 66.6% (50% is the threshold).

This pull request will bring the total coverage in the repository to 53.0% (0.2% change).

View more on Code Climate.

@Mab879 Mab879 self-assigned this May 31, 2023
Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have couple of questions. please see my comments. I have reviewed the CodeClimate findings and I think they are fine to ignore.

self.rule_to_component = self._load_components(components_dir)

def benchmark_has_component_mapping(self):
return ("linux_os/guide" in self.env_yaml["benchmark_root"])
Copy link
Member

@Mab879 Mab879 Jun 1, 2023

Choose a reason for hiding this comment

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

How would applications like OpenShift use components?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! We have components only for the Linux products so far. I will investigate how I can extend them to other products as well.

@jan-cerny jan-cerny requested review from a team as code owners June 7, 2023 09:28
@openshift-merge-robot openshift-merge-robot added the needs-rebase Used by openshift-ci bot. label Jun 7, 2023
jan-cerny added 4 commits June 7, 2023 11:37
If a rule isn't part of any component, the build will fail.
The enforcement will be efficient for the `linux_os` benchmark.
Also introduces a `ssg.components` module to the project which
can be used later in other tools and build system to work with
component files data.

This commit adds a simple test case `test_components.py` which
tests that
- components don't map to rules that don't exist
- all rules are mapped to at least 1 component
- the rule is assigned to component according to templates or
  template parameters
This test checks if a rule is mapped to component if it uses
a package platform or other platforms that can be easily used
to determine to which component the rule should belong to.
@openshift-ci
Copy link

openshift-ci bot commented Jun 7, 2023

@jan-cerny: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/images 1c0cf69 link true /test images

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

jan-cerny added 5 commits June 7, 2023 11:38
This commit extracts method `__process_rule` to reduce the code
complexity of the original method, as suggested by CodeClimate.
jan-cerny added 6 commits June 7, 2023 11:38
This aims to address the CodeClimate code complexity problem
in the `main()`.
CodeClimate emits a warning if there is too many return
statements in a single function.
This change reduces code duplication.
Products can decide to use components or they can define their own set
of components. Products specify a path to the directory with component
files by the `components_root` key in the `product.yml`.
This allows products like OCP to use components.
Extract function get_rule_to_components_mapping and move it to
the ssg.components module in order to simplify the BuildLoader
class.
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Used by openshift-ci bot. label Jun 7, 2023
@jan-cerny
Copy link
Collaborator Author

This PR has been replaced by #10693 because of the inability of canceling the automatically requested reviews.

@jan-cerny jan-cerny closed this Jun 7, 2023
@jan-cerny jan-cerny deleted the components2 branch June 7, 2023 09:44
@Mab879 Mab879 removed the Highlight This PR/Issue should make it to the featured changelog. label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement General enhancements to the project. Infrastructure Our content build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants