fix: Do not hard code package name in puppet_agent_end_run.rb
When using this module to install puppet-agent compatible packages with a different name (such as openvox-agent) calling puppet_agent_end_run with latest will fail, as the package name is hard coded.
This patch replaces the hard coded puppet-agent with a dynamic lookup for the package name. It also considers that (during migration) the latest_version lookup will not work.
How to reproduce the error:
class { '::puppet_agent':
package_version => 'latest',
package_name => 'openvox-agent',
manage_repo => false,
require => [
Apt::Source['openvox']
],
}
Results in:
Error: undefined method `parameters' for nil:NilClass
Info: Unknown failure using insync_values? on type: Puppet_agent_end_run[latest] / property: end_run to compare values [true] and false
Error: /Stage[main]/Puppet_agent::Install/Puppet_agent_end_run[latest]/end_run: change from false to true failed: undefined method `parameters' for nil:NilClass
Not sure how to handle the tests, as they do not seem to ensure that the puppet_agent class is in the catalog. Most likely adding to catalog in puppet_agent_end_run_spec? And also adding other "bogus" packages to ensure it works properly?
The tests are failing because they "manually" create a catalog and add the agent_latest_package to it. You could add the class too, it's a little gross. Note the differences with dashes and underscores.
Puppet::Type.type(:package).new(name: 'puppet-agent', ensure: 'latest', provider: :yum)
end
+ let(:puppet_agent_class) do
+ Puppet::Type.type(:component).new(name: 'puppet_agent', package_name: 'puppet-agent')
+ end
+
before(:each) do
+ catalog.add_resource(puppet_agent_class)
catalog.add_resource(agent_latest_package)
resource.catalog = catalog
end
The tests are failing because they "manually" create a catalog and add the
agent_latest_packageto it. You could add the class too, it's a little gross. Note the differences with dashes and underscores.Puppet::Type.type(:package).new(name: 'puppet-agent', ensure: 'latest', provider: :yum) end + let(:puppet_agent_class) do + Puppet::Type.type(:component).new(name: 'puppet_agent', package_name: 'puppet-agent') + end + before(:each) do + catalog.add_resource(puppet_agent_class) catalog.add_resource(agent_latest_package) resource.catalog = catalog end
Thanks a lot! I'll enhance/fix the tests and will include your previous review comments early next week.