Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,15 @@ When no facts are available for the specific facter/operating system combination
## Maintenance

This gem uses information about puppet AIO component versions to build/test.
They are stored at `ext/puppet_agent_facter_versions.json`. If they are outdated,
the `puppet_versions:test` rake task will fail and they need to be updated.
This is as easy as running: `bundle exec rake puppet_versions:update`
They are stored at `ext/puppet_agent_facter_versions.json`.

In the past we used `bundle exec rake puppet_versions:update` to update the file and `puppet_versions:test` to validate it.
This relied on information from the puppet forge.
With the 6.0.0 release we're switching to openvox.
The file is currently maintained by hand, because openvox doesn't offer an API yet to map agent releases to openfact releases.
It got also renamed from `ext/puppet_agent_facter_versions.json` -> `ext/openvox_agent_facter_versions.json`.

**`ext/openvox_agent_facter_versions.json`now lists a mapping of openvox releases to openfact releases**

## License

Expand Down
33 changes: 4 additions & 29 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,14 @@ end
namespace :puppet_versions do
desc 'updates the vendored list of puppet versions & components'
task :update do
require 'net/http'
require 'net/https'
require 'uri'
require 'json'

uri = URI.parse('https://forgeapi.puppet.com/private/versions/puppet-agent')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'

request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
raise unless response.is_a?(Net::HTTPSuccess)

data = JSON.parse(response.body).filter_map do |_, versions|
if !versions['puppet'].nil? && !versions['facter'].nil?
[versions['puppet'], versions['facter']]
end
end
data.sort_by! { |puppet, _facter| Gem::Version.new(puppet) }.reverse!

File.write(PUPPET_VERSIONS_PATH, "#{JSON.pretty_generate(data.to_h)}\n")
warn 'The rake task is disabled since the 6.0.0 Release. Please see the README.md'
exit 1
end

desc 'runs all tests and verifies vendored component list'
task :test do
Rake::Task['puppet_versions:update'].invoke

output = `git status --porcelain #{PUPPET_VERSIONS_PATH}`
unless output.strip.empty?
warn "#{PUPPET_VERSIONS_PATH} is out of date."
warn 'Run the puppet_versions:update task to update it and commit the changes.'
raise
end
warn 'The rake task is disabled since the 6.0.0 Release. Please see the README.md'
exit 1
end
end

Expand Down
17 changes: 17 additions & 0 deletions ext/openvox_agent_facter_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"8.23.1": "5.1.0",
"8.23.0": "5.1.0",
"8.22.1": "5.0.0",
"8.19.2": "4.11.0",
"8.19.1": "4.11.0",
"8.19.0": "4.11.0",
"8.18.1": "4.11.0",
"8.17.0": "4.11.0",
"8.16.0": "4.11.0",
"8.15.0": "4.11.0",
"8.14.0": "4.11.0",
"8.13.0": "4.11.0",
"8.12.1": "4.11.0",
"8.12.0": "4.11.0",
"8.11.0": "4.11.0"
}
133 changes: 0 additions & 133 deletions ext/puppet_agent_facter_versions.json

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def self.facter_version_to_loose_requirement_string(version)
def self.facter_version_for_puppet_version(puppet_version)
Copy link
Member

Choose a reason for hiding this comment

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

I don't mean to add on all the time, but I'd like to make this consistent and mention OpenVox. How about

Suggested change
def self.facter_version_for_puppet_version(puppet_version)
def self.openfact_version_for_openvox_version(openvox_version)

And design wise: I really would appreciate a non-breaking release first (if possible). Then you may want to split out some version finding logic to a helper method.

return Facter.version if puppet_version.nil?

json_path = File.expand_path(File.join(__dir__, '..', 'ext', 'puppet_agent_facter_versions.json'))
json_path = File.expand_path(File.join(__dir__, '..', 'ext', 'openvox_agent_facter_versions.json'))
unless File.file?(json_path) && File.readable?(json_path)
warning "#{json_path} does not exist or is not readable, defaulting to Facter #{Facter.version}"
return Facter.version
Expand Down
13 changes: 8 additions & 5 deletions spec/rspec_puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

let(:component_json_path) do
File.expand_path(File.join(__dir__, '..', 'ext', 'puppet_agent_facter_versions.json'))
File.expand_path(File.join(__dir__, '..', 'ext', 'openvox_agent_facter_versions.json'))
end

let(:puppet_version) { Puppet.version }
Expand Down Expand Up @@ -98,18 +98,21 @@
end

context 'when passed a known Puppet version' do
let(:puppet_version) { '5.2.0' }
let(:puppet_version) { '8.11.0' }

it 'returns the Facter version for that Puppet version' do
expect(facter_version).to eq('3.9.0')
expect(facter_version).to eq('4.11.0')
end
end

context 'when passed a Puppet version between two known versions' do
let(:puppet_version) { '5.2.5' }
# openvox 8.19.0 has facter 4.11.0
# openvox 8.22.1 has openfact 5.0.0
# openvox 9.18.5 doesn't exist
let(:puppet_version) { '8.19.5' }

it 'returns the Facter version for the lower Puppet version' do
expect(facter_version).to eq('3.9.0')
expect(facter_version).to eq('4.11.0')
end
end

Expand Down