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

Consul Version Fact #209

Merged
merged 13 commits into from
Feb 2, 2016
Merged

Consul Version Fact #209

merged 13 commits into from
Feb 2, 2016

Conversation

robrankin
Copy link
Contributor

Bit rough and ready, improvements welcome. Useful to see if all your servers have moved versions when performing an upgrade.

Facter.add(:consul_version) do
confine :kernel => 'Linux'
setcode do
Facter::Core::Execution.exec('consul --version | head -1 | cut -f2 -d\ | cut -c2-')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do the raw exec and do the string manipulation in ruby? Same with powershell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a very good idea, can't believe I didn't think of it rather! Will get back to this.

@solarkennedy
Copy link
Contributor

Add a test please for both linux and windows. Here is a similar example if you have not done so before:
https://github.com/puppetlabs/puppetlabs-mysql/blob/master/spec/unit/facter/mysql_version_spec.rb

@robrankin
Copy link
Contributor Author

Okay, test written, let me know if there's any improvements to be had?

version = Facter::Util::Resolution.exec('consul --version')
version = version.lines.first.split[1].tr('v','')
elsif Facter.value(:kernel) == 'windows'
version = Facter::Util::Resolution.exec('"C:\\Program Files\\Consul\\consul.exe" --version')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there anyway to make this configurable as we can't be certain that this is actually where consul is installed on Windows. For instance we install to C:\Consul not Program Files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, not optimal. Since this module doesn't yet support Windows, maybe best to remove Windows support in the fact? Only reason it's there currently is because I/we use Consul on Windows but use a separate module to install/manage it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no easy way to parameterize it then yea might want to remove it. My company is working on the Windows support for this module and are baking it in our preprod environments currently so hopefully we'll have that merged in soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think it would be possible to parameterize it, as facts run on the agent prior to catalogue compilation, so don't think they have access to any of the puppet parameters. Would probably have to ensure consul was on the Windows path once support is added.

Also, I wrote the windows puppet module for my companies use of Consul on Windows, depends on NSSM. Happy to contribute to the work you're doing if you're willing to put it in an open repo somewhere?

@robrankin
Copy link
Contributor Author

Removed Windows for now, will retain that on my own branch for our use.

allow(Facter.fact(:kernel)).to receive(:value).and_return("Linux")
allow(Facter::Util::Resolution).to receive(:exec).with('consul --version').
and_return(consul_version_output)
expect(Facter.fact(:consul_version).value).to match(/\d+\.\d+\.\d+/)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but can you add a really strong expect fact to eql '0.6.0' so I don't have to trust the regex logic? With such a controlled input, we should be able to say exactly what the output was, and not worry about spaces or anything extra.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bump on this one request, the only blocker to a merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Been hectic, apologies for the delay.

@solarkennedy
Copy link
Contributor

What is the expected output of this fact when consul isn't installed?
I would like the fact to not exist if consul is not installed. (behavior of most puppet facts)

@solarkennedy
Copy link
Contributor

Looks great! Thanks.

solarkennedy added a commit that referenced this pull request Feb 2, 2016
@solarkennedy solarkennedy merged commit c004df7 into voxpupuli:master Feb 2, 2016
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.

3 participants