puppet 3.0.1 → 3.0.2.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (97) hide show
  1. data/Gemfile +17 -3
  2. data/Rakefile +7 -5
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/debian/puppet.init +33 -34
  5. data/ext/debian/puppet.logrotate +2 -1
  6. data/ext/debian/puppetmaster.init +1 -2
  7. data/ext/suse/client.init +1 -1
  8. data/ext/suse/puppet.spec +3 -0
  9. data/ext/suse/server.init +1 -1
  10. data/ext/windows/service/daemon.rb +1 -1
  11. data/install.rb +32 -53
  12. data/lib/hiera/backend/puppet_backend.rb +6 -5
  13. data/lib/puppet/agent.rb +3 -3
  14. data/lib/puppet/application/agent.rb +1 -2
  15. data/lib/puppet/application/cert.rb +4 -5
  16. data/lib/puppet/application/kick.rb +3 -0
  17. data/lib/puppet/defaults.rb +15 -2
  18. data/lib/puppet/indirector/exec.rb +1 -1
  19. data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +1 -1
  20. data/lib/puppet/parser/functions/hiera_include.rb +6 -4
  21. data/lib/puppet/parser/lexer.rb +38 -1
  22. data/lib/puppet/parser/relationship.rb +3 -1
  23. data/lib/puppet/provider.rb +1 -1
  24. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  25. data/lib/puppet/provider/file/windows.rb +10 -29
  26. data/lib/puppet/provider/group/ldap.rb +1 -1
  27. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  28. data/lib/puppet/provider/ldap.rb +5 -1
  29. data/lib/puppet/provider/macauthorization/macauthorization.rb +2 -6
  30. data/lib/puppet/provider/package/dpkg.rb +8 -12
  31. data/lib/puppet/provider/package/macports.rb +2 -2
  32. data/lib/puppet/provider/package/msi.rb +2 -2
  33. data/lib/puppet/provider/package/sun.rb +1 -1
  34. data/lib/puppet/provider/package/windows.rb +2 -2
  35. data/lib/puppet/provider/package/yum.rb +5 -1
  36. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  37. data/lib/puppet/provider/service/freebsd.rb +1 -1
  38. data/lib/puppet/provider/user/directoryservice.rb +603 -65
  39. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  40. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  41. data/lib/puppet/run.rb +2 -1
  42. data/lib/puppet/settings.rb +9 -5
  43. data/lib/puppet/ssl/certificate_authority.rb +2 -0
  44. data/lib/puppet/transaction.rb +1 -1
  45. data/lib/puppet/type/cron.rb +4 -4
  46. data/lib/puppet/type/exec.rb +10 -5
  47. data/lib/puppet/type/file.rb +1 -1
  48. data/lib/puppet/type/service.rb +3 -2
  49. data/lib/puppet/type/user.rb +24 -2
  50. data/lib/puppet/util.rb +3 -6
  51. data/lib/puppet/util/adsi.rb +3 -9
  52. data/lib/puppet/util/diff.rb +1 -1
  53. data/lib/puppet/util/execution.rb +13 -6
  54. data/lib/puppet/util/feature.rb +3 -1
  55. data/lib/puppet/util/log/destinations.rb +12 -16
  56. data/lib/puppet/util/selinux.rb +18 -2
  57. data/lib/puppet/util/windows.rb +1 -0
  58. data/lib/puppet/util/windows/security.rb +2 -39
  59. data/lib/puppet/util/windows/sid.rb +96 -0
  60. data/lib/puppet/version.rb +1 -1
  61. data/spec/integration/util/windows/security_spec.rb +3 -23
  62. data/spec/unit/agent_spec.rb +7 -3
  63. data/spec/unit/application/agent_spec.rb +13 -5
  64. data/spec/unit/daemon_spec.rb +2 -1
  65. data/spec/unit/hiera/backend/puppet_backend_spec.rb +49 -42
  66. data/spec/unit/indirector/exec_spec.rb +8 -6
  67. data/spec/unit/parser/functions/hiera_include_spec.rb +11 -4
  68. data/spec/unit/parser/lexer_spec.rb +120 -8
  69. data/spec/unit/parser/relationship_spec.rb +24 -0
  70. data/spec/unit/provider/file/windows_spec.rb +29 -29
  71. data/spec/unit/provider/group/windows_adsi_spec.rb +2 -2
  72. data/spec/unit/provider/nameservice/directoryservice_spec.rb +1 -1
  73. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  74. data/spec/unit/provider/package/macports_spec.rb +6 -5
  75. data/spec/unit/provider/package/msi_spec.rb +1 -1
  76. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  77. data/spec/unit/provider/package/rpm_spec.rb +1 -1
  78. data/spec/unit/provider/package/sun_spec.rb +4 -4
  79. data/spec/unit/provider/package/windows_spec.rb +1 -1
  80. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +14 -11
  81. data/spec/unit/provider/user/directoryservice_spec.rb +943 -0
  82. data/spec/unit/provider/user/ldap_spec.rb +22 -8
  83. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  84. data/spec/unit/provider_spec.rb +1 -1
  85. data/spec/unit/run_spec.rb +1 -1
  86. data/spec/unit/settings_spec.rb +16 -0
  87. data/spec/unit/ssl/certificate_authority_spec.rb +24 -0
  88. data/spec/unit/util/adsi_spec.rb +4 -8
  89. data/spec/unit/util/diff_spec.rb +2 -2
  90. data/spec/unit/util/execution_spec.rb +78 -20
  91. data/spec/unit/util/feature_spec.rb +12 -1
  92. data/spec/unit/util/selinux_spec.rb +20 -0
  93. data/spec/unit/util/windows/sid_spec.rb +100 -0
  94. data/spec/unit/util_spec.rb +17 -0
  95. metadata +71 -48
  96. data/Gemfile.lock +0 -44
  97. data/lib/puppet/provider/interface/base.rb +0 -0
@@ -0,0 +1,96 @@
1
+ require 'puppet/util/windows'
2
+
3
+ module Puppet::Util::Windows
4
+ module SID
5
+ require 'windows/security'
6
+ include ::Windows::Security
7
+
8
+ require 'windows/memory'
9
+ include ::Windows::Memory
10
+
11
+ require 'windows/msvcrt/string'
12
+ include ::Windows::MSVCRT::String
13
+
14
+ # missing from Windows::Error
15
+ ERROR_NONE_MAPPED = 1332
16
+ ERROR_INVALID_SID_STRUCTURE = 1337
17
+
18
+ # Convert an account name, e.g. 'Administrators' into a SID string,
19
+ # e.g. 'S-1-5-32-544'. The name can be specified as 'Administrators',
20
+ # 'BUILTIN\Administrators', or 'S-1-5-32-544', and will return the
21
+ # SID. Returns nil if the account doesn't exist.
22
+ def name_to_sid(name)
23
+ # Apparently, we accept a symbol..
24
+ name = name.to_s if name
25
+
26
+ # if it's in SID string form, return it, otherwise, lookup sid
27
+ is_sid = Win32::Security::SID.string_to_sid(name) rescue nil
28
+
29
+ is_sid ? name : Win32::Security::SID.new(name).to_s
30
+ rescue
31
+ nil
32
+ end
33
+
34
+ # Convert a SID string, e.g. "S-1-5-32-544" to a name,
35
+ # e.g. 'BUILTIN\Administrators'. Returns nil if an account
36
+ # for that SID does not exist.
37
+ def sid_to_name(value)
38
+ sid = Win32::Security::SID.new(Win32::Security::SID.string_to_sid(value))
39
+
40
+ if sid.domain and sid.domain.length > 0
41
+ "#{sid.domain}\\#{sid.account}"
42
+ else
43
+ sid.account
44
+ end
45
+ rescue
46
+ nil
47
+ end
48
+
49
+ # Convert a SID pointer to a SID string, e.g. "S-1-5-32-544".
50
+ def sid_ptr_to_string(psid)
51
+ sid_buf = 0.chr * 256
52
+ str_ptr = 0.chr * 4
53
+
54
+ raise Puppet::Util::Windows::Error.new("Invalid SID") unless IsValidSid(psid)
55
+
56
+ raise Puppet::Util::Windows::Error.new("Failed to convert binary SID") unless ConvertSidToStringSid(psid, str_ptr)
57
+
58
+ begin
59
+ strncpy(sid_buf, str_ptr.unpack('L')[0], sid_buf.size - 1)
60
+ sid_buf[sid_buf.size - 1] = 0.chr
61
+ return sid_buf.strip
62
+ ensure
63
+ LocalFree(str_ptr.unpack('L')[0])
64
+ end
65
+ end
66
+
67
+ # Convert a SID string, e.g. "S-1-5-32-544" to a pointer (containing the
68
+ # address of the binary SID structure). The returned value can be used in
69
+ # Win32 APIs that expect a PSID, e.g. IsValidSid. The account for this
70
+ # SID may or may not exist.
71
+ def string_to_sid_ptr(string, &block)
72
+ sid_buf = 0.chr * 80
73
+ string_addr = [string].pack('p*').unpack('L')[0]
74
+
75
+ raise Puppet::Util::Windows::Error.new("Failed to convert string SID: #{string}") unless ConvertStringSidToSid(string_addr, sid_buf)
76
+
77
+ sid_ptr = sid_buf.unpack('L')[0]
78
+ begin
79
+ yield sid_ptr
80
+ ensure
81
+ LocalFree(sid_ptr)
82
+ end
83
+ end
84
+
85
+ # Return true if the string is a valid SID, e.g. "S-1-5-32-544", false otherwise.
86
+ def valid_sid?(string)
87
+ string_to_sid_ptr(string) { |ptr| true }
88
+ rescue Puppet::Util::Windows::Error => e
89
+ if e.code == ERROR_INVALID_SID_STRUCTURE
90
+ false
91
+ else
92
+ raise
93
+ end
94
+ end
95
+ end
96
+ end
@@ -6,7 +6,7 @@
6
6
  # Raketasks and such to set the version based on the output of `git describe`
7
7
  #
8
8
  module Puppet
9
- PUPPETVERSION = '3.0.1'
9
+ PUPPETVERSION = '3.0.2-rc1'
10
10
 
11
11
  def self.version
12
12
  @puppet_version || PUPPETVERSION
@@ -15,9 +15,9 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
15
15
 
16
16
  before :all do
17
17
  @sids = {
18
- :current_user => Puppet::Util::ADSI.sid_for_account(Sys::Admin.get_login),
19
- :admin => Puppet::Util::ADSI.sid_for_account("Administrator"),
20
- :guest => Puppet::Util::ADSI.sid_for_account("Guest"),
18
+ :current_user => Puppet::Util::Windows::Security.name_to_sid(Sys::Admin.get_login),
19
+ :admin => Puppet::Util::Windows::Security.name_to_sid("Administrator"),
20
+ :guest => Puppet::Util::Windows::Security.name_to_sid("Guest"),
21
21
  :users => Win32::Security::SID::BuiltinUsers,
22
22
  :power_users => Win32::Security::SID::PowerUsers,
23
23
  }
@@ -371,26 +371,6 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
371
371
  # end
372
372
  end
373
373
 
374
- describe "#string_to_sid_ptr" do
375
- it "should raise an error if an invalid SID is specified" do
376
- expect do
377
- winsec.string_to_sid_ptr('foobar')
378
- end.to raise_error(Puppet::Util::Windows::Error) { |error| error.code.should == 1337 }
379
- end
380
-
381
- it "should yield if a block is given" do
382
- yielded = nil
383
- winsec.string_to_sid_ptr('S-1-1-0') do |sid|
384
- yielded = sid
385
- end
386
- yielded.should_not be_nil
387
- end
388
-
389
- it "should allow no block to be specified" do
390
- winsec.string_to_sid_ptr('S-1-1-0').should be_true
391
- end
392
- end
393
-
394
374
  describe "when the parent directory" do
395
375
  before :each do
396
376
  winsec.set_owner(sids[:current_user], parent)
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  describe Puppet::Agent do
22
22
  before do
23
- @agent = Puppet::Agent.new(AgentTestClient)
23
+ @agent = Puppet::Agent.new(AgentTestClient, false)
24
24
 
25
25
  # So we don't actually try to hit the filesystem.
26
26
  @agent.stubs(:lock).yields
@@ -43,7 +43,7 @@ describe Puppet::Agent do
43
43
  end
44
44
 
45
45
  it "should set its client class at initialization" do
46
- Puppet::Agent.new("foo").client_class.should == "foo"
46
+ Puppet::Agent.new("foo", false).client_class.should == "foo"
47
47
  end
48
48
 
49
49
  it "should include the Locker module" do
@@ -181,7 +181,11 @@ describe Puppet::Agent do
181
181
 
182
182
  describe "when should_fork is true" do
183
183
  before do
184
- @agent.should_fork = true
184
+ @agent = Puppet::Agent.new(AgentTestClient, true)
185
+
186
+ # So we don't actually try to hit the filesystem.
187
+ @agent.stubs(:lock).yields
188
+
185
189
  Kernel.stubs(:fork)
186
190
  Process.stubs(:waitpid2).returns [123, (stub 'process::status', :exitstatus => 0)]
187
191
  @agent.stubs(:exit)
@@ -509,6 +509,19 @@ describe Puppet::Application::Agent do
509
509
  @puppetd.setup
510
510
  end
511
511
  end
512
+
513
+ describe "when configuring agent for catalog run" do
514
+ it "should set should_fork as true when running normally" do
515
+ Puppet::Agent.expects(:new).with(anything, true)
516
+ @puppetd.setup
517
+ end
518
+
519
+ it "should not set should_fork as false for --onetime" do
520
+ Puppet[:onetime] = true
521
+ Puppet::Agent.expects(:new).with(anything, false)
522
+ @puppetd.setup
523
+ end
524
+ end
512
525
  end
513
526
 
514
527
 
@@ -560,11 +573,6 @@ describe Puppet::Application::Agent do
560
573
  expect { @puppetd.onetime }.to exit_with 0
561
574
  end
562
575
 
563
- it "should not let the agent fork" do
564
- @agent.expects(:should_fork=).with(false)
565
- expect { @puppetd.onetime }.to exit_with 0
566
- end
567
-
568
576
  it "should let the agent run" do
569
577
  @agent.expects(:run).returns(:report)
570
578
  expect { @puppetd.onetime }.to exit_with 0
@@ -20,7 +20,8 @@ describe Puppet::Daemon, :unless => Puppet.features.microsoft_windows? do
20
20
  include PuppetSpec::Files
21
21
 
22
22
  before do
23
- @agent = Puppet::Agent.new(TestClient.new)
23
+ # Forking agent not needed here
24
+ @agent = Puppet::Agent.new(TestClient.new, false)
24
25
  @daemon = Puppet::Daemon.new
25
26
  @daemon.stubs(:close_streams).returns nil
26
27
  end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'hiera/backend/puppet_backend'
3
-
3
+ require 'hiera/scope'
4
4
 
5
5
  describe Hiera::Backend::Puppet_backend do
6
+
6
7
  before do
7
8
  Hiera.stubs(:warn)
8
9
  Hiera.stubs(:debug)
@@ -22,33 +23,24 @@ describe Hiera::Backend::Puppet_backend do
22
23
 
23
24
  describe "#hierarchy" do
24
25
  it "should use the configured datasource" do
25
- Hiera::Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
26
- Hiera::Config.expects("[]").with(:hierarchy)
27
-
28
- ["ntp", "ntp::config"].each do |klass|
29
- Hiera::Backend.expects(:parse_string).with(klass, @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns(klass)
30
- end
26
+ with_config(:puppet => {:datasource => "rspec"},
27
+ :hierarchy => nil)
31
28
 
32
29
  @backend.hierarchy(@scope, nil).should == ["rspec::ntp::config", "rspec::ntp", "ntp::config::rspec", "ntp::rspec"]
33
30
  end
34
31
 
35
32
  it "should not include empty class names" do
36
- Hiera::Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
37
- Hiera::Config.expects("[]").with(:hierarchy).returns(["%{foo}", "common"])
33
+ with_config(:puppet => {:datasource => "rspec"},
34
+ :hierarchy => ["%{foo}", "common"])
38
35
 
39
- Hiera::Backend.expects(:parse_string).with("common", @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns("common")
40
- Hiera::Backend.expects(:parse_string).with("%{foo}", @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns("")
36
+ @mockscope.expects(:lookupvar).with("foo").returns(nil)
41
37
 
42
38
  @backend.hierarchy(@scope, nil).should == ["rspec::common", "ntp::config::rspec", "ntp::rspec"]
43
39
  end
44
40
 
45
41
  it "should allow for an override data source" do
46
- Hiera::Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
47
- Hiera::Config.expects("[]").with(:hierarchy)
48
-
49
- ["ntp", "ntp::config"].each do |klass|
50
- Hiera::Backend.expects(:parse_string).with(klass, @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns(klass)
51
- end
42
+ with_config(:puppet => {:datasource => "rspec"},
43
+ :hierarchy => nil)
52
44
 
53
45
  @backend.hierarchy(@scope, "override").should == ["rspec::override", "rspec::ntp::config", "rspec::ntp", "ntp::config::rspec", "ntp::rspec"]
54
46
  end
@@ -56,47 +48,61 @@ describe Hiera::Backend::Puppet_backend do
56
48
 
57
49
  describe "#lookup" do
58
50
  it "should attempt to load data from unincluded classes" do
59
- Hiera::Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
51
+ with_config(:puppet => {:datasource => "rspec"},
52
+ :hierarchy => ["rspec"])
60
53
 
61
54
  catalog = mock
62
55
  catalog.expects(:classes).returns([])
63
56
 
64
- @scope.expects(:catalog).returns(catalog)
65
- @scope.expects(:function_include).with(["rspec"])
66
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec")
57
+ @mockscope.expects(:catalog).returns(catalog)
58
+ @mockscope.expects(:function_include).with(["rspec::rspec"])
59
+ @mockscope.expects(:lookupvar).with("rspec::rspec::key").returns("rspec")
67
60
 
68
- @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec"])
69
61
  @backend.lookup("key", @scope, nil, nil).should == "rspec"
70
62
  end
71
63
 
72
64
  it "should not load loaded classes" do
73
- Hiera::Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
65
+ with_config(:puppet => {:datasource => "rspec"},
66
+ :hierarchy => ["rspec"])
67
+
74
68
  catalog = mock
75
- catalog.expects(:classes).returns(["rspec"])
69
+ catalog.expects(:classes).returns(["rspec::rspec"])
76
70
  @mockscope.expects(:catalog).returns(catalog)
77
71
  @mockscope.expects(:function_include).never
78
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec")
72
+ @mockscope.expects(:lookupvar).with("rspec::rspec::key").returns("rspec")
79
73
 
80
- @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec"])
81
74
  @backend.lookup("key", @scope, nil, nil).should == "rspec"
82
75
  end
83
76
 
84
77
  it "should return the first found data" do
85
- Hiera::Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
78
+ with_config(:puppet => {:datasource => "rspec"},
79
+ :hierarchy => ["override", "rspec"])
80
+
86
81
  catalog = mock
87
- catalog.expects(:classes).returns(["rspec", "override"])
82
+ catalog.expects(:classes).returns(["rspec::override", "override::override"])
88
83
  @mockscope.expects(:catalog).returns(catalog)
89
84
  @mockscope.expects(:function_include).never
90
- @mockscope.expects(:lookupvar).with("override::key").returns("rspec")
91
- @mockscope.expects(:lookupvar).with("rspec::key").never
85
+ @mockscope.expects(:lookupvar).with("rspec::override::key").returns("rspec")
86
+ @mockscope.expects(:lookupvar).with("rspec::rspec::key").never
92
87
 
93
- @backend.expects(:hierarchy).with(@scope, "override").returns(["override", "rspec"])
94
88
  @backend.lookup("key", @scope, "override", nil).should == "rspec"
95
89
  end
96
90
 
91
+ it "should consider a value of false to be a real value" do
92
+ with_config(:puppet => {:datasource => "rspec"},
93
+ :hierarchy => ["override", "rspec"])
94
+ expected_answer = false
95
+
96
+ catalog = mock
97
+ catalog.expects(:classes).returns(["rspec::override", "override::override"])
98
+ @mockscope.expects(:catalog).returns(catalog)
99
+ @mockscope.expects(:lookupvar).with("rspec::override::key").returns(expected_answer)
100
+ @mockscope.expects(:lookupvar).with("rspec::rspec::key").never
101
+
102
+ @backend.lookup("key", @scope, "override", nil).should == expected_answer
103
+ end
104
+
97
105
  it "should return an array of found data for array searches" do
98
- Hiera::Backend.expects(:parse_answer).with("rspec::key", @scope).returns("rspec::key")
99
- Hiera::Backend.expects(:parse_answer).with("test::key", @scope).returns("test::key")
100
106
  catalog = mock
101
107
  catalog.expects(:classes).returns(["rspec", "test"])
102
108
  @mockscope.expects(:catalog).returns(catalog)
@@ -108,33 +114,34 @@ describe Hiera::Backend::Puppet_backend do
108
114
  @backend.lookup("key", @scope, nil, :array).should == ["rspec::key", "test::key"]
109
115
  end
110
116
 
111
-
112
117
  it "should return a hash of found data for hash searches" do
113
- Hiera::Backend.expects(:parse_answer).with("rspec::key", @scope).returns({'rspec'=>'key'})
114
- Hiera::Backend.expects(:parse_answer).with("test::key", @scope).returns({'test'=>'key'})
115
118
  catalog = mock
116
119
  catalog.expects(:classes).returns(["rspec", "test"])
117
120
  @mockscope.expects(:catalog).returns(catalog)
118
121
  @mockscope.expects(:function_include).never
119
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec::key")
120
- @mockscope.expects(:lookupvar).with("test::key").returns("test::key")
122
+ @mockscope.expects(:lookupvar).with("rspec::key").returns({'rspec'=>'key'})
123
+ @mockscope.expects(:lookupvar).with("test::key").returns({'test'=>'key'})
121
124
 
122
125
  @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
123
126
  @backend.lookup("key", @scope, nil, :hash).should == {'rspec'=>'key', 'test'=>'key'}
124
127
  end
125
128
 
126
129
  it "should return a merged hash of found data for hash searches" do
127
- Hiera::Backend.expects(:parse_answer).with("rspec::key", @scope).returns({'rspec'=>'key', 'common'=>'rspec'})
128
- Hiera::Backend.expects(:parse_answer).with("test::key", @scope).returns({'test'=>'key', 'common'=>'rspec'})
129
130
  catalog = mock
130
131
  catalog.expects(:classes).returns(["rspec", "test"])
131
132
  @mockscope.expects(:catalog).returns(catalog)
132
133
  @mockscope.expects(:function_include).never
133
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec::key")
134
- @mockscope.expects(:lookupvar).with("test::key").returns("test::key")
134
+ @mockscope.expects(:lookupvar).with("rspec::key").returns({'rspec'=>'key', 'common'=>'rspec'})
135
+ @mockscope.expects(:lookupvar).with("test::key").returns({'test'=>'key', 'common'=>'rspec'})
135
136
 
136
137
  @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
137
138
  @backend.lookup("key", @scope, nil, :hash).should == {'rspec'=>'key', 'common'=>'rspec', 'test'=>'key'}
138
139
  end
139
140
  end
141
+
142
+ def with_config(config)
143
+ config.each do |key, value|
144
+ Hiera::Config.expects("[]").with(key).returns(value)
145
+ end
146
+ end
140
147
  end
@@ -15,6 +15,7 @@ describe Puppet::Indirector::Exec do
15
15
  end
16
16
 
17
17
  let(:path) { File.expand_path('/echo') }
18
+ let(:arguments) { {:failonfail => true, :combine => false } }
18
19
 
19
20
  before :each do
20
21
  @searcher = @exec_class.new
@@ -34,23 +35,24 @@ describe Puppet::Indirector::Exec do
34
35
  end
35
36
 
36
37
  it "should execute the command with the object name as the only argument" do
37
- @searcher.expects(:execute).with([path, 'foo'], :combine => false)
38
+ @searcher.expects(:execute).with([path, 'foo'], arguments)
38
39
  @searcher.find(@request)
39
40
  end
40
41
 
41
42
  it "should return the output of the script" do
42
- @searcher.expects(:execute).with([path, 'foo'], :combine => false).returns("whatever")
43
+ @searcher.expects(:execute).with([path, 'foo'], arguments).returns("whatever")
43
44
  @searcher.find(@request).should == "whatever"
44
45
  end
45
46
 
46
47
  it "should return nil when the command produces no output" do
47
- @searcher.expects(:execute).with([path, 'foo'], :combine => false).returns(nil)
48
+ @searcher.expects(:execute).with([path, 'foo'], arguments).returns(nil)
48
49
  @searcher.find(@request).should be_nil
49
50
  end
50
51
 
51
52
  it "should raise an exception if there's an execution failure" do
52
- @searcher.expects(:execute).with([path, 'foo'], :combine => false).raises(Puppet::ExecutionFailure.new("message"))
53
-
54
- lambda {@searcher.find(@request)}.should raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
53
+ @searcher.expects(:execute).with([path, 'foo'], arguments).raises(Puppet::ExecutionFailure.new("message"))
54
+ expect {
55
+ @searcher.find(@request)
56
+ }.to raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
55
57
  end
56
58
  end
@@ -1,19 +1,26 @@
1
1
  require 'spec_helper'
2
+ require 'hiera_puppet'
3
+ require 'puppet/parser/functions/hiera_include'
2
4
 
3
5
  describe 'Puppet::Parser::Functions#hiera_include' do
4
6
  let :scope do Puppet::Parser::Scope.new_for_test_harness('foo') end
5
7
 
8
+ before :each do
9
+ Puppet[:hiera_config] = PuppetSpec::Files.tmpfile('hiera_config')
10
+ end
11
+
6
12
  it 'should require a key argument' do
7
13
  expect { scope.function_hiera_include([]) }.to raise_error(Puppet::ParseError)
8
14
  end
9
15
 
10
16
  it 'should raise a useful error when nil is returned' do
11
- Hiera.any_instance.expects(:lookup).returns(nil)
12
- expect { scope.function_hiera_include(["badkey"]) }.to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
17
+ HieraPuppet.expects(:lookup).returns(nil)
18
+ expect { scope.function_hiera_include(["badkey"]) }.
19
+ to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
13
20
  end
14
21
 
15
22
  it 'should use the array resolution_type' do
16
- Hiera.any_instance.expects(:lookup).with() { |*args| args[4].should be :array }.returns([])
17
- scope.function_hiera_include(['key'])
23
+ HieraPuppet.expects(:lookup).with() { |*args| args[4].should be :array }.returns(['someclass'])
24
+ expect { scope.function_hiera_include(['key']) }.to raise_error Puppet::Error, /Could not find class someclass/
18
25
  end
19
26
  end