diff options
author | Gabriel Nagy <gabriel.nagy@puppet.com> | 2020-09-09 16:20:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 16:20:03 +0300 |
commit | cc841d2bd7e003bf1492374550e1446a5080b15a (patch) | |
tree | 9ece0c496112da6826e135002fa181f4c0f15ef9 | |
parent | e2512df5a3cf3113110f40a826970111097323bb (diff) | |
parent | 897ca7a86b9595761e1492a4ffa36bbdb751a15a (diff) | |
download | puppet-augeas_core-cc841d2bd7e003bf1492374550e1446a5080b15a.tar.gz puppet-augeas_core-cc841d2bd7e003bf1492374550e1446a5080b15a.tar.bz2 |
Merge pull request #27 from luchihoratiu/MODULES-7397
(MODULES-7397) Load Augeas lenses from modules
-rw-r--r-- | lib/puppet/provider/augeas/augeas.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/augeas/augeas_spec.rb | 41 |
2 files changed, 46 insertions, 9 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index bfa3852..c8f9643 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -367,8 +367,18 @@ Puppet::Type.type(:augeas).provide(:augeas) do load_path.flatten! end - if Puppet::FileSystem.exist?("#{Puppet[:libdir]}/augeas/lenses") - load_path << "#{Puppet[:libdir]}/augeas/lenses" + if Puppet::Application.name == :agent + if Puppet::FileSystem.exist?("#{Puppet[:libdir]}/augeas/lenses") + load_path << "#{Puppet[:libdir]}/augeas/lenses" + end + else + env = Puppet.lookup(:current_environment) + env.each_plugin_directory do |dir| + lenses = File.join(dir, 'augeas', 'lenses') + if File.exist?(lenses) + load_path << lenses + end + end end load_path.join(':') diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb index 7c9336a..2d53933 100644 --- a/spec/unit/provider/augeas/augeas_spec.rb +++ b/spec/unit/provider/augeas/augeas_spec.rb @@ -1121,15 +1121,42 @@ describe Puppet::Type.type(:augeas).provider(:augeas) do expect(provider.get_load_path(resource)).to eq('/foo:/bar:/baz') end - it 'offers pluginsync augeas/lenses subdir' do - Puppet[:libdir] = my_fixture_dir - expect(provider.get_load_path(resource)).to eq("#{my_fixture_dir}/augeas/lenses") + context 'when running application is agent' do + before(:each) do + Puppet[:libdir] = my_fixture_dir + Puppet::Application.stubs(:name).returns(:agent) + end + + it 'offers pluginsync augeas/lenses subdir' do + expect(provider.get_load_path(resource)).to eq("#{my_fixture_dir}/augeas/lenses") + end + + it 'offers both pluginsync and load_path paths' do + resource[:load_path] = ['/foo', '/bar', '/baz'] + expect(provider.get_load_path(resource)).to eq("/foo:/bar:/baz:#{my_fixture_dir}/augeas/lenses") + end end - it 'offers both pluginsync and load_path paths' do - Puppet[:libdir] = my_fixture_dir - resource[:load_path] = ['/foo', '/bar', '/baz'] - expect(provider.get_load_path(resource)).to eq("/foo:/bar:/baz:#{my_fixture_dir}/augeas/lenses") + context 'when running application is not agent' do + before(:each) do + Puppet::Application.stubs(:name).returns(:apply) + + env = Puppet::Node::Environment.create('root', ['/modules/foobar']) + Puppet.stubs(:lookup).returns(env) + env.stubs(:each_plugin_directory).yields('/modules/foobar') + + resource[:load_path] = ['/foo', '/bar', '/baz'] + end + + it 'offers both load_path and module lenses path when available' do + File.stubs(:exist?).with('/modules/foobar/augeas/lenses').returns(true) + expect(provider.get_load_path(resource)).to eq('/foo:/bar:/baz:/modules/foobar/augeas/lenses') + end + + it 'offers only load_path if module lenses path is not available' do + File.stubs(:exist?).with('/modules/foobar/augeas/lenses').returns(false) + expect(provider.get_load_path(resource)).to eq('/foo:/bar:/baz') + end end end end |