No more use loadall() for default_profider_for() function

Change-Id: Id16605cc834e0071328bec667fcc27502a2c0f30
Closes-Bug: #1575269
This commit is contained in:
Dmitry Ilyin 2016-04-26 12:15:37 -05:00 committed by Sergey Vasilenko
parent ad8f079a3f
commit b82c12e9f3
2 changed files with 22 additions and 10 deletions

View File

@ -1,19 +1,17 @@
module Puppet::Parser::Functions
newfunction(:default_provider_for, :type => :rvalue, :doc => <<-EOS
Get the default provider of a type
EOS
) do |argv|
type_name = argv[0]
fail('No type name provided!') if ! type_name
Puppet::Type.loadall()
type_name = type_name.capitalize.to_sym
return 'undef' if ! Puppet::Type.const_defined? type_name
type = Puppet::Type.const_get type_name
fail 'No type name provided!' unless type_name
type_name = type_name.to_s.downcase.to_sym
type = Puppet::Type.type type_name
return nil unless type
provider = type.defaultprovider
return 'undef' if ! provider
rv = provider.name.to_s
debug("Default provider for type '#{type_name}' is a '#{rv}'.")
return rv
return nil unless provider
provider_name = provider.name.to_s
debug "default_provider_for() default provider for type '#{type_name}' is a '#{provider_name}'"
return provider_name
end
end

View File

@ -0,0 +1,14 @@
require 'spec_helper'
describe 'default_provider_for' do
let(:facts) {{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}}
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params('file').and_return('posix') }
end