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

profile_tool.py: Fix traceback in sub command #11637

Merged

Conversation

yuumasato
Copy link
Member

@yuumasato yuumasato commented Mar 1, 2024

Description:

  • Fix traceback when diffing ocp4 profiles.
$ build-scripts/profile_tool.py sub --build-config-yaml ./build/build_config.yml --ssg-root ./ --product ocp4 --profile2 products/ocp4/profiles/high-rev-4.profile --profile1 products/ocp4/profiles/moderate.profile                                                                             
Traceback (most recent call last):
  File "/home/wsato/git/content/ssg/entities/common.py", line 274, in from_yaml
    data_dict = cls.parse_yaml_into_processed_dict(yaml_file, local_env_yaml, product_cpes)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsato/git/content/ssg/entities/common.py", line 244, in parse_yaml_into_processed_dict
    processed_data = cls.process_input_dict(yaml_data, env_yaml, product_cpes)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsato/git/content/ssg/entities/profile_base.py", line 74, in process_input_dict
    new_cpe_name = product_cpes.get_cpe_name(platform)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_cpe_name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wsato/git/content/build-scripts/profile_tool.py", line 331, in <module>
    main()
  File "/home/wsato/git/content/build-scripts/profile_tool.py", line 327, in main
    SUBCMDS[args.subcommand](args)
  File "/home/wsato/git/content/utils/profile_tool/sub.py", line 11, in command_sub
    profile1 = Profile.from_yaml(args.profile1, env_yaml)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsato/git/content/ssg/entities/common.py", line 281, in from_yaml
    raise RuntimeError(msg)
RuntimeError: Error loading a Profile from products/ocp4/profiles/moderate.profile: 'NoneType' object has no attribute 'get_cpe_name'

Rationale:

  • I don't know why the tool doesn't segfault when diffing rhel8 or rhel9 profiles
  • This tool is pretty handy to compare rule selection differences in profiles.
    • It can compare source profile files and compiled(rendered) profile files.

Review Hints:

  • Build the content (./build/build_config.yml needs to be generated)
    • e.g: $ ./build_product ocp4
  • Diff two profiles:
$ build-scripts/profile_tool.py sub --build-config-yaml ./build/build_config.yml --ssg-root ./ --product ocp4 --profile2 products/ocp4/profiles/high-rev-4.profile --profile1 products/ocp4/profiles/moderate.profile
Subtraction would produce an empty profile. No new profile was generated
$ build-scripts/profile_tool.py sub --build-config-yaml ./build/build_config.yml --ssg-root ./ --product ocp4 --profile2 products/ocp4/profiles/high-rev-4.profile --profile1 products/ocp4/profiles/e8.profile
12 rules were left after subtraction.
0 variables were left after subtraction.
Creating a new profile containing the exclusive selections: e8_sub_high-rev-4.profile
Profile e8_sub_high-rev-4.profile was created successfully

When control files are used it makes more sense to compare compiled profile files:

$ build-scripts/profile_tool.py sub --build-config-yaml ./build/build_config.yml --ssg-root ./ --product ocp4 --profile1 build/ocp4/profiles/high-rev-4.profile --profile2 build/ocp4/profiles/e8.profile
122 rules were left after subtraction.
3 variables were left after subtraction.
Creating a new profile containing the exclusive selections: high-rev-4_sub_e8.profile
Profile high-rev-4_sub_e8.profile was created successfully

Fix traceback when diffing profile sources.
Copy link

github-actions bot commented Mar 1, 2024

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

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

github-actions bot commented Mar 1, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:11637

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:11637

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:11637 make deploy-local

Copy link

codeclimate bot commented Mar 1, 2024

Code Climate has analyzed commit d76368a and detected 0 issues on this pull request.

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

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

View more on Code Climate.

@jan-cerny jan-cerny self-assigned this Mar 1, 2024
@jan-cerny jan-cerny added this to the 0.1.73 milestone Mar 1, 2024
@jan-cerny
Copy link
Collaborator

/retest

@jan-cerny
Copy link
Collaborator

/packit build

Copy link
Collaborator

@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 run the review hints and also I have tried to run the tool on RHEL 9 profiles.

@yuumasato yuumasato requested a review from jan-cerny March 5, 2024 09:21
@jan-cerny jan-cerny merged commit 66acced into ComplianceAsCode:master Mar 6, 2024
44 checks passed
@yuumasato yuumasato deleted the fix_profile_tool_sub_command branch March 13, 2024 16:47
@Mab879 Mab879 added the Infrastructure Our content build system label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Our content build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants