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
Add pe facts to stdlib #99
Conversation
# | ||
Facter.add("pe_version") do | ||
setcode do | ||
pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d\.\d\.\d)/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean \d+
in this regexp, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that is more correct and future proof.
Edit: Updated in b26d0f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffmccune Anything else jump out at you?
Looking now. |
Some additional comments: b26d0f6 should be squashed into df46f0e. There should be test coverage for the multi-digit scenario like version 2.10.1. Finally, why the call to |
Some final comments on this one. In the future, please use the branch naming convention of Second, the example descriptions for the negative case don't match the examples themselves. I've fixed this up in e4087d6 which should be squashed into e0349f0 as well. Finally, an example of how to add coverage for multi-digit version numbers without duplicating a bunch of code is available at c834a59 in my topic branch. The improved descriptions are also nice to have, generic descriptions make it more difficult to understand the specification and the intended behavior. Hope this helps. Once the topic branch is cleaned up I'm happy to merge this in. My patches are published at: https://github.com/jeffmccune/puppetlabs-stdlib/tree/haus-add_pe_facts_to_stdlib -Jeff |
the Facter.clear cleans up the Facts from the previous test so they don't pollute the current one. If you remove the after block, the second set of tests fail. |
It's not duplicating the path, it's just duplicating the behavior, right? (I wrote the test without looking at the implementation, so I didn't realize I was duplicating the call to See what I mean by the difference between duplicating code and duplicating a code path? |
Ah, cool. That smells to me; I expect the spec helper or something else to automatically handle cleaning up state between example groups. I'm going to dive in a bit to try and figure out why calling clear is necessary. |
Rebased and squashed back into 2 commits, including your fixes. I removed Facter.clear_messages as it wasn't essential as far as i could tell. |
Yea, I think spec_helper in Facter does exactly that and is probably where I got the code from. |
Ah, so thinking about this a bit more... The litmus test I use when thinking about these sorts of problems is, "If the implementation changes, will this example notify me?" I think in this situation See what I'm driving at? |
For sure, it will definitely catch those problems. |
I figured it out. The patches that remove the need to call Facter.clear in all of the example groups are avialable in my branch. Please consider rebasing these patches into this topic branch. I think we should be good to go once that's done.
|
As many PE modules have PE specific functionality, but are deployed to all nodes, including FOSS nodes, it is valuable to be able to selectively enable those PE specific functions. These facts allow modules to use the is_pe fact to determine whether the module should be used or not. The facts include is_pe, pe_version, pe_major_version, pe_minor_version, and pe_patch_version. For PE 2.6.0 those facts would have values true, 2.6.0, 2, 6, and 0, respectively.
This commit adds some basic spec tests for the pe_version facts. There are basic postitive and negative cases.
Without this patch example groups must explicitly call `Facter.clear` to clear any cached values between examples. This is a problem because this behavior is not the concern of the example groups, the behavior is the concern of the spec_helper or whatever facility we have in place to initialize the system for testing. This patch fixes the problem by duplicating the logic in the Facter spec_helper to ensure facts are cleared out before each example. This patch requires the example groups to explicitly load the facts they require if the fact name does not match the filename.
@jeffmccune looks sane, rebased (thanks for figuring the spec helper thing out). I tend to think |
I merged this into 2.4.x and master:
The last note I have is that I added e686779 on top of this change set. Thanks for the contribution and thanks for taking the time and effort to organize the commits and provide a clear commit message. It really helped me work through this quickly. -Jeff |
Actually... I just screwed this up. I merged this new fact into 2.4.x but it's not fixing any bug. It's adding a new fact, so this should go into master and we should release 2.5 since this is new, backwards-compatbile functionality. I'm going to revert this out of 2.4.x and merge it into master, then establish 2.5.x to cut the 2.5.0 release to the forge. -Jeff |
@jeffmccune sounds great. thanks for working through it with me! |
These commits add is_pe, pe_version, pe_major_version, pe_minor_version, and pe_patch_version to stdlib as well as some basic spec tests.