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

repo_config improperly setting as str breaking config.repo #161

Merged
merged 1 commit into from
May 17, 2024

Conversation

chtaylo2
Copy link
Contributor

fixes #153

@chtaylo2
Copy link
Contributor Author

@mdellweg - pinging to review. When is v0.16 expected to be released? Thanks

Comment on lines 142 to 143
if repo_config is not None and isinstance(repo_config, string_types):
desired_attributes["repo_config"] = json.loads(repo_config)
Copy link
Member

Choose a reason for hiding this comment

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

What happens if it's not a string?
I'm unsure how this is supposed to be represented. It looks like we are missing either case in both versions. We should have a test for this.

"A JSON document or data structure describing a config.repo file"

Copy link
Contributor Author

@chtaylo2 chtaylo2 May 2, 2024

Choose a reason for hiding this comment

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

  1. As a string, it's converted to a json blob
    repo_config: '{"gpgcheck": 1}'

  2. As a hash of key:pairs, ansible properly converts this to a json blob and passes to the API.

      repo_config:
        gpgcheck: 1
        anotherkey: value
        anotherkey2: value

In either of these cases, it'll work. The current code test for the (1) string value, should we have a test for (2) format as well?

Copy link
Member

Choose a reason for hiding this comment

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

ATM desired_attributes is only set on one branch of the if.
So yes, I could really be convinced by seeing both versions in a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdellweg - These tests are already in place, just the fixtures were not proper. (I'm now remembering)
See: https://github.com/pulp/squeezer/blob/develop/tests/playbooks/rpm_repository.yaml#L115-L161

desired_attributes is only set on one branch of the if

desired_attributes is initially set with this code:
https://github.com/pulp/squeezer/blob/develop/plugins/modules/rpm_repository.py#L127-L129

The IF statement is modifying the desired_attributes["repo_config"] to correctly format the JSON blob when a string vs dict is provided.

Copy link
Member

Choose a reason for hiding this comment

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

I see.
Then let's make this more obvious and fix desired_attributes["repo_config"] in place without reading from module.params again.

Copy link
Member

Choose a reason for hiding this comment

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

It would also be ok to just require it to be parsed from json already. I think there is a "from_json" filter in ansible to bridge the gap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the rewriting from module.params and in place fix for desired_attributes.

Copy link
Member

Choose a reason for hiding this comment

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

Can you change the test in a way, that the module is faced with both versions once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the check to test the json version and then the string version, validating no changes to the repo are detected. This confirms different endpoints produce the same output.

@chtaylo2 chtaylo2 force-pushed the develop branch 2 times, most recently from ff4e1ab to f8672e6 Compare May 9, 2024 18:01
Comment on lines 141 to 143
if module.params["repo_config"] is not None and isinstance(
module.params["repo_config"], string_types
):
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to stay in the domain of the problem here too (We should be done with module.params at this point):

Suggested change
if module.params["repo_config"] is not None and isinstance(
module.params["repo_config"], string_types
):
if "repo_config" in desired_attributes and isinstance(
desired_attributes["repo_config"], string_types
):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I've made this change as requested

@mdellweg mdellweg merged commit f161120 into pulp:develop May 17, 2024
12 checks passed
@chtaylo2
Copy link
Contributor Author

@mdellweg - What is the release cadence for Squeezer? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repo_config of rpm_repository - broken config.repo
2 participants