summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Parker <andy@puppetlabs.com>2014-10-02 15:11:04 -0700
committerAndrew Parker <andy@puppetlabs.com>2014-10-02 15:11:04 -0700
commit766cce7ff953b63698a7a4c819e6b21b60703c6d (patch)
tree69a983072a46a35e9f3a799f3d198db70a5ba90e
parent8df1aa9914bfd17dc244cc56e28d3976265b3cfb (diff)
parent6887e26a3ef48538777200826d824a7561951211 (diff)
downloadpuppet-766cce7ff953b63698a7a4c819e6b21b60703c6d.tar.gz
Merge branch 'pr/3144' into stable
* pr/3144: (maint) Remove duplicate file handling code (maint) reduce repitition in Application::Apply integration spec (PUP-3258) node exec indirector: default to environment, not its name Closes GH-3144
-rw-r--r--lib/puppet/indirector/node/exec.rb2
-rwxr-xr-xspec/integration/application/apply_spec.rb52
-rwxr-xr-xspec/lib/puppet_spec/files.rb1
3 files changed, 31 insertions, 24 deletions
diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb
index d4faf74f4..2535ffac5 100644
--- a/lib/puppet/indirector/node/exec.rb
+++ b/lib/puppet/indirector/node/exec.rb
@@ -21,7 +21,7 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec
# Set the requested environment if it wasn't overridden
# If we don't do this it gets set to the local default
- result[:environment] ||= request.environment.name
+ result[:environment] ||= request.environment
create_node(request.key, result)
end
diff --git a/spec/integration/application/apply_spec.rb b/spec/integration/application/apply_spec.rb
index e48808120..3ce1277d3 100755
--- a/spec/integration/application/apply_spec.rb
+++ b/spec/integration/application/apply_spec.rb
@@ -1,7 +1,5 @@
-#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet_spec/files'
-require 'puppet/application/apply'
describe "apply" do
include PuppetSpec::Files
@@ -17,9 +15,8 @@ describe "apply" do
resource = Puppet::Resource.new(:file, file_to_create, :parameters => {:content => "my stuff"})
catalog.add_resource resource
- manifest = tmpfile("manifest")
+ manifest = file_containing("manifest", catalog.to_pson)
- File.open(manifest, "w") { |f| f.print catalog.to_pson }
puppet = Puppet::Application[:apply]
puppet.options[:catalog] = manifest
@@ -31,12 +28,7 @@ describe "apply" do
end
it "applies a given file even when a directory environment is specified" do
- manifest = tmpfile("manifest.pp")
- File.open(manifest, "w") do |f|
- f.puts <<-EOF
- notice('it was applied')
- EOF
- end
+ manifest = file_containing("manifest.pp", "notice('it was applied')")
special = Puppet::Node::Environment.create(:special, [])
Puppet.override(:current_environment => special) do
@@ -49,27 +41,41 @@ describe "apply" do
expect(@logs.map(&:to_s)).to include('it was applied')
end
+ it "applies a given file even when an ENC is configured", :if => !Puppet.features.microsoft_windows? do
+ manifest = file_containing("manifest.pp", "notice('specific manifest applied')")
+ site_manifest = file_containing("site_manifest.pp", "notice('the site manifest was applied instead')")
+ enc = file_containing("enc_script", "#!/bin/sh\necho 'classes: []'")
+ File.chmod(0755, enc)
+
+ special = Puppet::Node::Environment.create(:special, [])
+ Puppet.override(:current_environment => special) do
+ Puppet[:environment] = 'special'
+ Puppet[:node_terminus] = 'exec'
+ Puppet[:external_nodes] = enc
+ Puppet[:manifest] = site_manifest
+ puppet = Puppet::Application[:apply]
+ puppet.stubs(:command_line).returns(stub('command_line', :args => [manifest]))
+ expect { puppet.run_command }.to exit_with(0)
+ end
+
+ expect(@logs.map(&:to_s)).to include('specific manifest applied')
+ end
+
context "with a module" do
let(:modulepath) { tmpdir('modulepath') }
let(:execute) { 'include amod' }
let(:args) { ['-e', execute, '--modulepath', modulepath] }
before(:each) do
- Puppet::FileSystem.mkpath("#{modulepath}/amod/manifests")
- File.open("#{modulepath}/amod/manifests/init.pp", "w") do |f|
- f.puts <<-EOF
- class amod{
- notice('amod class included')
+ dir_contained_in(modulepath, {
+ "amod" => {
+ "manifests" => {
+ "init.pp" => "class amod{ notice('amod class included') }"
+ }
}
- EOF
- end
- environmentdir = Dir.mktmpdir('environments')
- Puppet[:environmentpath] = environmentdir
- create_default_directory_environment
- end
+ })
- def create_default_directory_environment
- Puppet::FileSystem.mkpath("#{Puppet[:environmentpath]}/#{Puppet[:environment]}")
+ Puppet[:environmentpath] = dir_containing("environments", { Puppet[:environment] => {} })
end
def init_cli_args_and_apply_app(args, execute)
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 312c4fc95..2d0d95275 100755
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -57,6 +57,7 @@ module PuppetSpec::Files
dir_contained_in(tmpdir(name), contents_hash)
end
+ def dir_contained_in(dir, contents_hash) PuppetSpec::Files.dir_contained_in(dir, contents_hash) end
def self.dir_contained_in(dir, contents_hash)
contents_hash.each do |k,v|
if v.is_a?(Hash)