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

stringify facts, if required, before collecting custom facts #173

Closed
wants to merge 1 commit into from

Conversation

bastelfreak
Copy link
Member

@bastelfreak bastelfreak commented May 24, 2024

@bastelfreak bastelfreak requested a review from ekohl May 24, 2024 20:13
@bastelfreak bastelfreak self-assigned this May 24, 2024
@@ -170,11 +170,10 @@ def on_supported_os_implementation(opts = {})
os = "#{facts[:operatingsystem].downcase}-#{operatingsystemmajrelease}-#{facts[:hardwaremodel]}"
next unless os.start_with? RspecPuppetFacts.spec_facts_os_filter if RspecPuppetFacts.spec_facts_os_filter
facts.merge! RspecPuppetFacts.common_facts
Copy link
Member

Choose a reason for hiding this comment

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

This made me wonder about common_facts and sadly we'll also need to deal with that. The rabbit hole is always deeper than you'd like :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I would like to takle that in another PR.

Copy link
Member Author

@bastelfreak bastelfreak May 24, 2024

Choose a reason for hiding this comment

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

ah wait, that already fixes common_facts as well? self.common_facts always returns symbols but afterwards we call facts = stringify_keys(facts) if RSpec.configuration.facterdb_string_keys so that's fine?

We could call stringify_keys directly in self.common_facts but I think that justs adds one useless iteration on the hash that we can avoid?

Copy link
Member

Choose a reason for hiding this comment

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

We could call stringify_keys directly in self.common_facts but I think that justs adds one useless iteration on the hash that we can avoid?

It's about performance overhead IMHO. It may not matter that much, but we know rspec-puppet-facts has proven slow at times. If you make common_facts return correct values you can then implement it here as:

Suggested change
facts.merge! RspecPuppetFacts.common_facts
facts = stringify_keys(facts) if RSpec.configuration.facterdb_string_keys
facts.merge! RspecPuppetFacts.common_facts

Then longer term we can also push the changes into facterdb itself. There we do this:
https://github.com/voxpupuli/facterdb/blob/9c33730c537b2891aa1db7e26bd0faf3895e8b1a/lib/facterdb.rb#L146

If we drop the to_sym there we can drop stringify_keys here. voxpupuli/facterdb#362 introduces a symbolize_keys parameter.

Does that clarify the long term path I see for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm wondering if we should wait with this until we've a new facterdb version that only returns strings by default. Let's see if we can get voxpupuli/facterdb#364 merged.

@bastelfreak
Copy link
Member Author

this is obsolete now, got implemented in #175

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

Successfully merging this pull request may close these issues.

2 participants