puppet 2.7.9 → 2.7.11

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 (187) hide show
  1. data/CHANGELOG +413 -0
  2. data/README_DEVELOPER.md +28 -0
  3. data/conf/redhat/puppet.spec +10 -1
  4. data/conf/solaris/pkginfo +1 -1
  5. data/conf/suse/puppet.spec +7 -4
  6. data/ext/envpuppet.bat +13 -0
  7. data/ext/rack/files/apache2.conf +4 -0
  8. data/install.rb +4 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/agent.rb +7 -0
  11. data/lib/puppet/agent/disabler.rb +27 -0
  12. data/lib/puppet/agent/locker.rb +0 -10
  13. data/lib/puppet/application.rb +3 -0
  14. data/lib/puppet/application/agent.rb +13 -3
  15. data/lib/puppet/application/apply.rb +6 -6
  16. data/lib/puppet/application/cert.rb +5 -5
  17. data/lib/puppet/application/instrumentation_data.rb +4 -0
  18. data/lib/puppet/application/instrumentation_listener.rb +4 -0
  19. data/lib/puppet/application/instrumentation_probe.rb +4 -0
  20. data/lib/puppet/configurer.rb +3 -1
  21. data/lib/puppet/configurer/downloader.rb +4 -2
  22. data/lib/puppet/configurer/fact_handler.rb +0 -21
  23. data/lib/puppet/daemon.rb +3 -4
  24. data/lib/puppet/defaults.rb +2 -2
  25. data/lib/puppet/face/instrumentation_data.rb +28 -0
  26. data/lib/puppet/face/instrumentation_listener.rb +96 -0
  27. data/lib/puppet/face/instrumentation_probe.rb +77 -0
  28. data/lib/puppet/face/module/list.rb +64 -0
  29. data/lib/puppet/face/module/uninstall.rb +50 -0
  30. data/lib/puppet/face/node/clean.rb +1 -4
  31. data/lib/puppet/feature/base.rb +1 -0
  32. data/lib/puppet/file_serving/content.rb +1 -1
  33. data/lib/puppet/indirector/facts/facter.rb +20 -7
  34. data/lib/puppet/indirector/facts/inventory_active_record.rb +14 -11
  35. data/lib/puppet/indirector/indirection.rb +7 -0
  36. data/lib/puppet/indirector/instrumentation_data.rb +3 -0
  37. data/lib/puppet/indirector/instrumentation_data/local.rb +19 -0
  38. data/lib/puppet/indirector/instrumentation_data/rest.rb +5 -0
  39. data/lib/puppet/indirector/instrumentation_listener.rb +3 -0
  40. data/lib/puppet/indirector/instrumentation_listener/local.rb +23 -0
  41. data/lib/puppet/indirector/instrumentation_listener/rest.rb +5 -0
  42. data/lib/puppet/indirector/instrumentation_probe.rb +3 -0
  43. data/lib/puppet/indirector/instrumentation_probe/local.rb +24 -0
  44. data/lib/puppet/indirector/instrumentation_probe/rest.rb +5 -0
  45. data/lib/puppet/indirector/rest.rb +1 -1
  46. data/lib/puppet/module.rb +13 -17
  47. data/lib/puppet/module_tool/applications.rb +1 -0
  48. data/lib/puppet/module_tool/applications/uninstaller.rb +33 -0
  49. data/lib/puppet/module_tool/contents_description.rb +1 -1
  50. data/lib/puppet/network/server.rb +2 -3
  51. data/lib/puppet/node/environment.rb +16 -3
  52. data/lib/puppet/parser/ast/leaf.rb +1 -1
  53. data/lib/puppet/parser/functions/create_resources.rb +1 -1
  54. data/lib/puppet/parser/type_loader.rb +1 -1
  55. data/lib/puppet/property.rb +46 -14
  56. data/lib/puppet/provider.rb +13 -4
  57. data/lib/puppet/provider/augeas/augeas.rb +6 -4
  58. data/lib/puppet/provider/group/pw.rb +24 -10
  59. data/lib/puppet/provider/nameservice/directoryservice.rb +146 -37
  60. data/lib/puppet/provider/package/pip.rb +1 -1
  61. data/lib/puppet/provider/package/yum.rb +1 -2
  62. data/lib/puppet/provider/service/debian.rb +14 -0
  63. data/lib/puppet/provider/service/launchd.rb +1 -1
  64. data/lib/puppet/provider/service/smf.rb +2 -2
  65. data/lib/puppet/provider/user/pw.rb +56 -2
  66. data/lib/puppet/provider/user/user_role_add.rb +32 -22
  67. data/lib/puppet/provider/user/windows_adsi.rb +1 -0
  68. data/lib/puppet/rails/benchmark.rb +1 -1
  69. data/lib/puppet/reports/store.rb +8 -1
  70. data/lib/puppet/resource/catalog.rb +5 -1
  71. data/lib/puppet/simple_graph.rb +11 -14
  72. data/lib/puppet/transaction.rb +10 -4
  73. data/lib/puppet/transaction/report.rb +9 -3
  74. data/lib/puppet/type.rb +19 -7
  75. data/lib/puppet/type/exec.rb +1 -1
  76. data/lib/puppet/type/file.rb +4 -1
  77. data/lib/puppet/type/file/ensure.rb +5 -1
  78. data/lib/puppet/type/file/mode.rb +45 -10
  79. data/lib/puppet/type/file/source.rb +4 -0
  80. data/lib/puppet/type/host.rb +17 -3
  81. data/lib/puppet/type/k5login.rb +3 -2
  82. data/lib/puppet/type/schedule.rb +3 -2
  83. data/lib/puppet/util.rb +83 -27
  84. data/lib/puppet/util/anonymous_filelock.rb +36 -0
  85. data/lib/puppet/util/docs.rb +18 -2
  86. data/lib/puppet/util/instrumentation.rb +173 -0
  87. data/lib/puppet/util/instrumentation/data.rb +34 -0
  88. data/lib/puppet/util/instrumentation/indirection_probe.rb +29 -0
  89. data/lib/puppet/util/instrumentation/instrumentable.rb +143 -0
  90. data/lib/puppet/util/instrumentation/listener.rb +60 -0
  91. data/lib/puppet/util/instrumentation/listeners/log.rb +29 -0
  92. data/lib/puppet/util/instrumentation/listeners/performance.rb +30 -0
  93. data/lib/puppet/util/monkey_patches.rb +8 -0
  94. data/lib/puppet/util/pidlock.rb +21 -25
  95. data/lib/puppet/util/rdoc/parser.rb +2 -2
  96. data/lib/puppet/util/reference.rb +8 -23
  97. data/lib/puppet/util/retryaction.rb +48 -0
  98. data/lib/puppet/util/suidmanager.rb +70 -39
  99. data/lib/puppet/util/symbolic_file_mode.rb +140 -0
  100. data/spec/integration/configurer_spec.rb +5 -0
  101. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  102. data/spec/integration/indirector/file_content/file_server_spec.rb +7 -7
  103. data/spec/integration/provider/package_spec.rb +7 -0
  104. data/spec/unit/agent/disabler_spec.rb +60 -0
  105. data/spec/unit/agent/locker_spec.rb +0 -12
  106. data/spec/unit/agent_spec.rb +8 -0
  107. data/spec/unit/application/agent_spec.rb +38 -1
  108. data/spec/unit/application/apply_spec.rb +34 -40
  109. data/spec/unit/application/cert_spec.rb +1 -1
  110. data/spec/unit/application_spec.rb +6 -0
  111. data/spec/unit/configurer/downloader_spec.rb +29 -10
  112. data/spec/unit/configurer/fact_handler_spec.rb +5 -29
  113. data/spec/unit/configurer_spec.rb +8 -8
  114. data/spec/unit/daemon_spec.rb +12 -26
  115. data/spec/unit/face/instrumentation_data.rb +7 -0
  116. data/spec/unit/face/instrumentation_listener.rb +38 -0
  117. data/spec/unit/face/instrumentation_probe.rb +21 -0
  118. data/spec/unit/face/node_spec.rb +111 -111
  119. data/spec/unit/file_serving/content_spec.rb +2 -2
  120. data/spec/unit/indirector/facts/facter_spec.rb +25 -3
  121. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +14 -4
  122. data/spec/unit/indirector/instrumentation_data/local_spec.rb +52 -0
  123. data/spec/unit/indirector/instrumentation_data/rest_spec.rb +11 -0
  124. data/spec/unit/indirector/instrumentation_listener/local_spec.rb +65 -0
  125. data/spec/unit/indirector/instrumentation_listener/rest_spec.rb +11 -0
  126. data/spec/unit/indirector/instrumentation_probe/local_spec.rb +65 -0
  127. data/spec/unit/indirector/instrumentation_probe/rest_spec.rb +11 -0
  128. data/spec/unit/module_spec.rb +39 -125
  129. data/spec/unit/module_tool/uninstaller_spec.rb +44 -0
  130. data/spec/unit/network/server_spec.rb +2 -20
  131. data/spec/unit/node/environment_spec.rb +76 -58
  132. data/spec/unit/parser/ast/asthash_spec.rb +1 -2
  133. data/spec/unit/parser/ast/leaf_spec.rb +16 -0
  134. data/spec/unit/property/keyvalue_spec.rb +5 -2
  135. data/spec/unit/property_spec.rb +260 -159
  136. data/spec/unit/provider/augeas/augeas_spec.rb +2 -2
  137. data/spec/unit/provider/group/pw_spec.rb +81 -0
  138. data/spec/unit/provider/nameservice/directoryservice_spec.rb +102 -0
  139. data/spec/unit/provider/package/pip_spec.rb +7 -0
  140. data/spec/unit/provider/package/yum_spec.rb +45 -1
  141. data/spec/unit/provider/service/debian_spec.rb +15 -0
  142. data/spec/unit/provider/service/launchd_spec.rb +48 -43
  143. data/spec/unit/provider/service/smf_spec.rb +3 -3
  144. data/spec/unit/provider/user/pw_spec.rb +183 -0
  145. data/spec/unit/provider/user/user_role_add_spec.rb +46 -39
  146. data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
  147. data/spec/unit/provider_spec.rb +32 -0
  148. data/spec/unit/reports/store_spec.rb +19 -1
  149. data/spec/unit/simple_graph_spec.rb +34 -19
  150. data/spec/unit/ssl/certificate_factory_spec.rb +3 -3
  151. data/spec/unit/transaction/report_spec.rb +29 -1
  152. data/spec/unit/transaction_spec.rb +32 -46
  153. data/spec/unit/type/file/mode_spec.rb +1 -1
  154. data/spec/unit/type/file/source_spec.rb +28 -3
  155. data/spec/unit/type/file_spec.rb +17 -16
  156. data/spec/unit/type/host_spec.rb +527 -0
  157. data/spec/unit/type/k5login_spec.rb +115 -0
  158. data/spec/unit/type/schedule_spec.rb +6 -6
  159. data/spec/unit/type_spec.rb +51 -0
  160. data/spec/unit/util/anonymous_filelock_spec.rb +78 -0
  161. data/spec/unit/util/execution_stub_spec.rb +2 -1
  162. data/spec/unit/util/instrumentation/data_spec.rb +44 -0
  163. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +19 -0
  164. data/spec/unit/util/instrumentation/instrumentable_spec.rb +186 -0
  165. data/spec/unit/util/instrumentation/listener_spec.rb +100 -0
  166. data/spec/unit/util/instrumentation/listeners/log_spec.rb +34 -0
  167. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +36 -0
  168. data/spec/unit/util/instrumentation_spec.rb +181 -0
  169. data/spec/unit/util/pidlock_spec.rb +208 -0
  170. data/spec/unit/util/rdoc/parser_spec.rb +1 -1
  171. data/spec/unit/util/reference_spec.rb +16 -6
  172. data/spec/unit/util/retryaction_spec.rb +62 -0
  173. data/spec/unit/util/suidmanager_spec.rb +101 -83
  174. data/spec/unit/util/symbolic_file_mode_spec.rb +182 -0
  175. data/spec/unit/util_spec.rb +126 -0
  176. data/tasks/rake/apple.rake +176 -0
  177. data/tasks/rake/templates/prototype.plist.erb +38 -0
  178. metadata +61 -13
  179. data/lib/puppet/application/module.rb +0 -3
  180. data/lib/puppet/face/module.rb +0 -12
  181. data/spec/unit/face/module/build_spec.rb +0 -30
  182. data/spec/unit/face/module/changes_spec.rb +0 -30
  183. data/spec/unit/face/module/clean_spec.rb +0 -30
  184. data/spec/unit/face/module/generate_spec.rb +0 -30
  185. data/spec/unit/face/module/install_spec.rb +0 -75
  186. data/spec/unit/face/module/search_spec.rb +0 -40
  187. data/test/util/pidlock.rb +0 -126
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'fileutils'
4
+ require 'puppet/type'
5
+
6
+ describe Puppet::Type.type(:k5login), :unless => Puppet.features.microsoft_windows? do
7
+ include PuppetSpec::Files
8
+
9
+ context "the type class" do
10
+ subject { described_class }
11
+ it { should be_validattr :ensure }
12
+ it { should be_validattr :path }
13
+ it { should be_validattr :principals }
14
+ it { should be_validattr :mode }
15
+ # We have one, inline provider implemented.
16
+ it { should be_validattr :provider }
17
+ end
18
+
19
+ let(:path) { tmpfile('k5login') }
20
+
21
+ def resource(attrs = {})
22
+ attrs = {
23
+ :ensure => 'present',
24
+ :path => path,
25
+ :principals => 'fred@EXAMPLE.COM'
26
+ }.merge(attrs)
27
+
28
+ if content = attrs.delete(:content)
29
+ File.open(path, 'w') { |f| f.print(content) }
30
+ end
31
+
32
+ resource = described_class.new(attrs)
33
+ resource
34
+ end
35
+
36
+ before :each do
37
+ FileUtils.touch(path)
38
+ end
39
+
40
+ context "the provider" do
41
+ context "when the file is missing" do
42
+ it "should initially be absent" do
43
+ File.delete(path)
44
+ resource.retrieve[:ensure].must == :absent
45
+ end
46
+
47
+ it "should create the file when synced" do
48
+ resource(:ensure => 'present').parameter(:ensure).sync
49
+ File.should be_exist path
50
+ end
51
+ end
52
+
53
+ context "when the file is present" do
54
+ context "retrieved initial state" do
55
+ subject { resource.retrieve }
56
+
57
+ it "should retrieve its properties correctly with zero principals" do
58
+ subject[:ensure].should == :present
59
+ subject[:principals].should == []
60
+ # We don't really care what the mode is, just that it got it
61
+ subject[:mode].should_not be_nil
62
+ end
63
+
64
+ context "with one principal" do
65
+ subject { resource(:content => "daniel@EXAMPLE.COM\n").retrieve }
66
+
67
+ it "should retrieve its principals correctly" do
68
+ subject[:principals].should == ["daniel@EXAMPLE.COM"]
69
+ end
70
+ end
71
+
72
+ context "with two principals" do
73
+ subject do
74
+ content = ["daniel@EXAMPLE.COM", "george@EXAMPLE.COM"].join("\n")
75
+ resource(:content => content).retrieve
76
+ end
77
+
78
+ it "should retrieve its principals correctly" do
79
+ subject[:principals].should == ["daniel@EXAMPLE.COM", "george@EXAMPLE.COM"]
80
+ end
81
+ end
82
+ end
83
+
84
+ it "should remove the file ensure is absent" do
85
+ resource(:ensure => 'absent').property(:ensure).sync
86
+ File.should_not be_exist path
87
+ end
88
+
89
+ it "should write one principal to the file" do
90
+ File.read(path).should == ""
91
+ resource(:principals => ["daniel@EXAMPLE.COM"]).property(:principals).sync
92
+ File.read(path).should == "daniel@EXAMPLE.COM\n"
93
+ end
94
+
95
+ it "should write multiple principals to the file" do
96
+ content = ["daniel@EXAMPLE.COM", "george@EXAMPLE.COM"]
97
+
98
+ File.read(path).should == ""
99
+ resource(:principals => content).property(:principals).sync
100
+ File.read(path).should == content.join("\n") + "\n"
101
+ end
102
+
103
+ describe "when setting the mode" do
104
+ # The defined input type is "mode, as an octal string"
105
+ ["400", "600", "700", "644", "664"].each do |mode|
106
+ it "should update the mode to #{mode}" do
107
+ resource(:mode => mode).property(:mode).sync
108
+
109
+ (File.stat(path).mode & 07777).to_s(8).should == mode
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -82,17 +82,17 @@ describe Puppet::Type.type(:schedule) do
82
82
 
83
83
  it "should match when the start time is before the current time and the end time is after the current time" do
84
84
  @schedule[:range] = "10:59:50 - 11:00:10"
85
- @schedule.should be_match
85
+ @schedule.must be_match
86
86
  end
87
87
 
88
88
  it "should not match when the start time is after the current time" do
89
89
  @schedule[:range] = "11:00:05 - 11:00:10"
90
- @schedule.should_not be_match
90
+ @schedule.must_not be_match
91
91
  end
92
92
 
93
93
  it "should not match when the end time is previous to the current time" do
94
94
  @schedule[:range] = "10:59:50 - 10:59:55"
95
- @schedule.should be_match
95
+ @schedule.must_not be_match
96
96
  end
97
97
 
98
98
  it "should throw an error if the upper limit is less than the lower limit" do
@@ -103,17 +103,17 @@ describe Puppet::Type.type(:schedule) do
103
103
 
104
104
  it "should not match the current time fails between an array of ranges" do
105
105
  @schedule[:range] = ["4-6", "20-23"]
106
- @schedule.should_not be_match
106
+ @schedule.must_not be_match
107
107
  end
108
108
 
109
109
  it "should match the lower array of ranges" do
110
110
  @schedule[:range] = ["9-11", "14-16"]
111
- @schedule.should be_match
111
+ @schedule.must be_match
112
112
  end
113
113
 
114
114
  it "should match the upper array of ranges" do
115
115
  @schedule[:range] = ["4-6", "11-12"]
116
- @schedule.should be_match
116
+ @schedule.must be_match
117
117
  end
118
118
  end
119
119
 
@@ -4,6 +4,28 @@ require 'spec_helper'
4
4
  describe Puppet::Type, :fails_on_windows => true do
5
5
  include PuppetSpec::Files
6
6
 
7
+ it "should be Comparable" do
8
+ a = Puppet::Type.type(:notify).new(:name => "a")
9
+ b = Puppet::Type.type(:notify).new(:name => "b")
10
+ c = Puppet::Type.type(:notify).new(:name => "c")
11
+
12
+ [[a, b, c], [a, c, b], [b, a, c], [b, c, a], [c, a, b], [c, b, a]].each do |this|
13
+ this.sort.should == [a, b, c]
14
+ end
15
+
16
+ a.should be < b
17
+ a.should be < c
18
+ b.should be > a
19
+ b.should be < c
20
+ c.should be > a
21
+ c.should be > b
22
+
23
+ [a, b, c].each {|x| a.should be <= x }
24
+ [a, b, c].each {|x| c.should be >= x }
25
+
26
+ b.should be_between(a, c)
27
+ end
28
+
7
29
  it "should consider a parameter to be valid if it is a valid parameter" do
8
30
  Puppet::Type.type(:mount).should be_valid_parameter(:path)
9
31
  end
@@ -588,6 +610,35 @@ describe Puppet::Type, :fails_on_windows => true do
588
610
  resource.should_not be_suitable
589
611
  end
590
612
  end
613
+
614
+ describe "::ensurable?" do
615
+ before :each do
616
+ class TestEnsurableType < Puppet::Type
617
+ def exists?; end
618
+ def create; end
619
+ def destroy; end
620
+ end
621
+ end
622
+
623
+ it "is true if the class has exists?, create, and destroy methods defined" do
624
+ TestEnsurableType.should be_ensurable
625
+ end
626
+
627
+ it "is false if exists? is not defined" do
628
+ TestEnsurableType.class_eval { remove_method(:exists?) }
629
+ TestEnsurableType.should_not be_ensurable
630
+ end
631
+
632
+ it "is false if create is not defined" do
633
+ TestEnsurableType.class_eval { remove_method(:create) }
634
+ TestEnsurableType.should_not be_ensurable
635
+ end
636
+
637
+ it "is false if destroy is not defined" do
638
+ TestEnsurableType.class_eval { remove_method(:destroy) }
639
+ TestEnsurableType.should_not be_ensurable
640
+ end
641
+ end
591
642
  end
592
643
 
593
644
  describe Puppet::Type::RelationshipMetaparam do
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ require 'puppet/util/anonymous_filelock'
5
+
6
+ describe Puppet::Util::AnonymousFilelock do
7
+ require 'puppet_spec/files'
8
+ include PuppetSpec::Files
9
+
10
+ before(:each) do
11
+ @lockfile = tmpfile("lock")
12
+ @lock = Puppet::Util::AnonymousFilelock.new(@lockfile)
13
+ end
14
+
15
+ it "should be anonymous" do
16
+ @lock.should be_anonymous
17
+ end
18
+
19
+ describe "#lock" do
20
+ it "should return false if already locked" do
21
+ @lock.stubs(:locked?).returns(true)
22
+ @lock.lock.should be_false
23
+ end
24
+
25
+ it "should return true if it successfully locked" do
26
+ @lock.lock.should be_true
27
+ end
28
+
29
+ it "should create a lock file" do
30
+ @lock.lock
31
+
32
+ File.should be_exists(@lockfile)
33
+ end
34
+
35
+ it "should create a lock file containing a message" do
36
+ @lock.lock("message")
37
+
38
+ File.read(@lockfile).should == "message"
39
+ end
40
+ end
41
+
42
+ describe "#unlock" do
43
+ it "should return true when unlocking" do
44
+ @lock.lock
45
+ @lock.unlock.should be_true
46
+ end
47
+
48
+ it "should return false when not locked" do
49
+ @lock.unlock.should be_false
50
+ end
51
+
52
+ it "should clear the lock file" do
53
+ File.open(@lockfile, 'w') { |fd| fd.print("locked") }
54
+ @lock.unlock
55
+ File.should_not be_exists(@lockfile)
56
+ end
57
+ end
58
+
59
+ it "should be locked when locked" do
60
+ @lock.lock
61
+ @lock.should be_locked
62
+ end
63
+
64
+ it "should not be locked when not locked" do
65
+ @lock.should_not be_locked
66
+ end
67
+
68
+ it "should not be locked when unlocked" do
69
+ @lock.lock
70
+ @lock.unlock
71
+ @lock.should_not be_locked
72
+ end
73
+
74
+ it "should return the lock message" do
75
+ @lock.lock("lock message")
76
+ @lock.message.should == "lock message"
77
+ end
78
+ end
@@ -16,7 +16,8 @@ describe Puppet::Util::ExecutionStub do
16
16
  Puppet::Util::ExecutionStub.current_value.should == nil
17
17
  end
18
18
 
19
- it "should restore normal execution after 'reset' is called" do
19
+ # fails on windows, see #11740
20
+ it "should restore normal execution after 'reset' is called", :fails_on_windows => true do
20
21
  # Note: "true" exists at different paths in different OSes
21
22
  if Puppet.features.microsoft_windows?
22
23
  true_command = [Puppet::Util.which('cmd.exe').tr('/', '\\'), '/c', 'exit 0']
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/json'
5
+ require 'puppet/util/instrumentation'
6
+ require 'puppet/util/instrumentation/data'
7
+
8
+ describe Puppet::Util::Instrumentation::Data do
9
+ Puppet::Util::Instrumentation::Data
10
+
11
+ before(:each) do
12
+ @listener = stub 'listener', :name => "name"
13
+ Puppet::Util::Instrumentation.stubs(:[]).with("name").returns(@listener)
14
+ end
15
+
16
+ it "should indirect instrumentation_data" do
17
+ Puppet::Util::Instrumentation::Data.indirection.name.should == :instrumentation_data
18
+ end
19
+
20
+ it "should lookup the corresponding listener" do
21
+ Puppet::Util::Instrumentation.expects(:[]).with("name").returns(@listener)
22
+ Puppet::Util::Instrumentation::Data.new("name")
23
+ end
24
+
25
+ it "should error if the listener can not be found" do
26
+ Puppet::Util::Instrumentation.expects(:[]).with("name").returns(nil)
27
+ expect { Puppet::Util::Instrumentation::Data.new("name") }.to raise_error
28
+ end
29
+
30
+ it "should return pson data" do
31
+ data = Puppet::Util::Instrumentation::Data.new("name")
32
+ @listener.stubs(:data).returns({ :this_is_data => "here also" })
33
+ data.should set_json_attribute('name').to("name")
34
+ data.should set_json_attribute('this_is_data').to("here also")
35
+ end
36
+
37
+ it "should not error if the underlying listener doesn't have data" do
38
+ lambda { Puppet::Util::Instrumentation::Data.new("name").to_pson }.should_not raise_error
39
+ end
40
+
41
+ it "should return a hash containing data when unserializing from pson" do
42
+ Puppet::Util::Instrumentation::Data.from_pson({:name => "name"}).should == {:name => "name"}
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/json'
5
+ require 'puppet/util/instrumentation'
6
+ require 'puppet/util/instrumentation/indirection_probe'
7
+
8
+ describe Puppet::Util::Instrumentation::IndirectionProbe do
9
+ Puppet::Util::Instrumentation::IndirectionProbe
10
+
11
+ it "should indirect instrumentation_probe" do
12
+ Puppet::Util::Instrumentation::IndirectionProbe.indirection.name.should == :instrumentation_probe
13
+ end
14
+
15
+ it "should return pson data" do
16
+ probe = Puppet::Util::Instrumentation::IndirectionProbe.new("probe")
17
+ probe.should set_json_attribute('name').to("probe")
18
+ end
19
+ end
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'puppet/util/instrumentation'
6
+ require 'puppet/util/instrumentation/instrumentable'
7
+
8
+ describe Puppet::Util::Instrumentation::Instrumentable::Probe do
9
+
10
+ before(:each) do
11
+ Puppet::Util::Instrumentation.stubs(:start)
12
+ Puppet::Util::Instrumentation.stubs(:stop)
13
+
14
+ class ProbeTest
15
+ def mymethod(arg1, arg2, arg3)
16
+ :it_worked
17
+ end
18
+ end
19
+ end
20
+
21
+ after(:each) do
22
+ if ProbeTest.method_defined?(:instrumented_mymethod)
23
+ ProbeTest.class_eval {
24
+ remove_method(:mymethod)
25
+ alias_method(:mymethod, :instrumented_mymethod)
26
+ }
27
+ end
28
+ Puppet::Util::Instrumentation::Instrumentable.clear_probes
29
+ end
30
+
31
+ describe "when enabling a probe" do
32
+ it "should raise an error if the probe is already enabled" do
33
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
34
+ probe.enable
35
+ lambda { probe.enable }.should raise_error
36
+ end
37
+
38
+ it "should rename the original method name" do
39
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
40
+ probe.enable
41
+ ProbeTest.new.should respond_to(:instrumented_mymethod)
42
+ end
43
+
44
+ it "should create a new method of the original name" do
45
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
46
+ probe.enable
47
+ ProbeTest.new.should respond_to(:mymethod)
48
+ end
49
+ end
50
+
51
+ describe "when disabling a probe" do
52
+ it "should raise an error if the probe is already enabled" do
53
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
54
+ lambda { probe.disable }.should raise_error
55
+ end
56
+
57
+ it "should rename the original method name" do
58
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
59
+ probe.enable
60
+ probe.disable
61
+
62
+ Puppet::Util::Instrumentation.expects(:start).never
63
+ Puppet::Util::Instrumentation.expects(:stop).never
64
+ ProbeTest.new.mymethod(1,2,3).should == :it_worked
65
+ end
66
+
67
+ it "should remove the created method" do
68
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
69
+ probe.enable
70
+ probe.disable
71
+ ProbeTest.new.should_not respond_to(:instrumented_mymethod)
72
+ end
73
+ end
74
+
75
+ describe "when a probe is called" do
76
+ it "should call the original method" do
77
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
78
+ probe.enable
79
+ test = ProbeTest.new
80
+ test.expects(:instrumented_mymethod).with(1,2,3)
81
+ test.mymethod(1,2,3)
82
+ end
83
+
84
+ it "should start the instrumentation" do
85
+ Puppet::Util::Instrumentation.expects(:start)
86
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
87
+ probe.enable
88
+ test = ProbeTest.new
89
+ test.mymethod(1,2,3)
90
+ end
91
+
92
+ it "should stop the instrumentation" do
93
+ Puppet::Util::Instrumentation.expects(:stop)
94
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
95
+ probe.enable
96
+ test = ProbeTest.new
97
+ test.mymethod(1,2,3)
98
+ end
99
+
100
+ describe "and the original method raises an exception" do
101
+ it "should propagate the exception" do
102
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
103
+ probe.enable
104
+ test = ProbeTest.new
105
+ test.expects(:instrumented_mymethod).with(1,2,3).raises
106
+ lambda { test.mymethod(1,2,3) }.should raise_error
107
+ end
108
+
109
+ it "should stop the instrumentation" do
110
+ Puppet::Util::Instrumentation.expects(:stop)
111
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest)
112
+ probe.enable
113
+ test = ProbeTest.new
114
+ test.expects(:instrumented_mymethod).with(1,2,3).raises
115
+ lambda { test.mymethod(1,2,3) }.should raise_error
116
+ end
117
+ end
118
+
119
+ describe "with a static label" do
120
+ it "should send the label to the instrumentation layer" do
121
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest, :label => :mylabel)
122
+ probe.enable
123
+ test = ProbeTest.new
124
+ Puppet::Util::Instrumentation.expects(:start).with { |label,data| label == :mylabel }.returns(42)
125
+ Puppet::Util::Instrumentation.expects(:stop).with(:mylabel, 42, {})
126
+ test.mymethod(1,2,3)
127
+ end
128
+ end
129
+
130
+ describe "with a dynamic label" do
131
+ it "should send the evaluated label to the instrumentation layer" do
132
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest, :label => Proc.new { |parent,args| "dynamic#{args[0]}" } )
133
+ probe.enable
134
+ test = ProbeTest.new
135
+ Puppet::Util::Instrumentation.expects(:start).with { |label,data| label == "dynamic1" }.returns(42)
136
+ Puppet::Util::Instrumentation.expects(:stop).with("dynamic1",42,{})
137
+ test.mymethod(1,2,3)
138
+ end
139
+ end
140
+
141
+ describe "with static data" do
142
+ it "should send the data to the instrumentation layer" do
143
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest, :data => { :static_data => "nothing" })
144
+ probe.enable
145
+ test = ProbeTest.new
146
+ Puppet::Util::Instrumentation.expects(:start).with { |label,data| data == { :static_data => "nothing" }}
147
+ test.mymethod(1,2,3)
148
+ end
149
+ end
150
+
151
+ describe "with dynamic data" do
152
+ it "should send the evaluated label to the instrumentation layer" do
153
+ probe = Puppet::Util::Instrumentation::Instrumentable::Probe.new(:mymethod, ProbeTest, :data => Proc.new { |parent, args| { :key => args[0] } } )
154
+ probe.enable
155
+ test = ProbeTest.new
156
+ Puppet::Util::Instrumentation.expects(:start).with { |label,data| data == { :key => 1 } }
157
+ Puppet::Util::Instrumentation.expects(:stop)
158
+ test.mymethod(1,2,3)
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ describe Puppet::Util::Instrumentation::Instrumentable do
165
+ before(:each) do
166
+ class ProbeTest2
167
+ extend Puppet::Util::Instrumentation::Instrumentable
168
+ probe :mymethod
169
+ def mymethod(arg1,arg2,arg3)
170
+ end
171
+ end
172
+ end
173
+
174
+ after do
175
+ Puppet::Util::Instrumentation::Instrumentable.clear_probes
176
+ end
177
+
178
+ it "should allow probe definition" do
179
+ Puppet::Util::Instrumentation::Instrumentable.probe_names.should be_include("ProbeTest2.mymethod")
180
+ end
181
+
182
+ it "should be able to enable all probes" do
183
+ Puppet::Util::Instrumentation::Instrumentable.enable_probes
184
+ ProbeTest2.new.should respond_to(:instrumented_mymethod)
185
+ end
186
+ end