~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/application/kick_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
require File.dirname(__FILE__) + '/../../spec_helper'
 
1
#!/usr/bin/env rspec
 
2
require 'spec_helper'
4
3
 
5
4
require 'puppet/application/kick'
6
5
 
11
10
    Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything)
12
11
    @kick = Puppet::Application[:kick]
13
12
    Puppet::Util::Log.stubs(:newdestination)
14
 
    Puppet::Util::Log.stubs(:level=)
15
13
  end
16
14
 
17
15
  describe ".new" do
121
119
      @kick.classes = []
122
120
      @kick.tags = []
123
121
      @kick.hosts = []
124
 
      Puppet::Log.stubs(:level=)
125
122
      @kick.stubs(:trap)
126
123
      @kick.stubs(:puts)
127
124
      Puppet.stubs(:parse_config)
131
128
 
132
129
    it "should set log level to debug if --debug was passed" do
133
130
      @kick.options.stubs(:[]).with(:debug).returns(true)
134
 
 
135
 
      Puppet::Log.expects(:level=).with(:debug)
136
 
 
137
131
      @kick.setup
 
132
      Puppet::Log.level.should == :debug
138
133
    end
139
134
 
140
135
    it "should set log level to info if --verbose was passed" do
141
136
      @kick.options.stubs(:[]).with(:verbose).returns(true)
142
 
 
143
 
      Puppet::Log.expects(:level=).with(:info)
144
 
 
145
137
      @kick.setup
 
138
      Puppet::Log.level.should == :info
146
139
    end
147
140
 
148
141
    it "should Parse puppet config" do
161
154
        @kick.options.stubs(:[]).with(:all).returns(true)
162
155
        @kick.stubs(:puts)
163
156
 
164
 
        Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([])
 
157
        Puppet::Node.indirection.expects(:search).with("whatever",:fqdn => :something).returns([])
165
158
 
166
159
        @kick.setup
167
160
      end
170
163
        @kick.options.stubs(:[]).with(:all).returns(true)
171
164
        @kick.stubs(:puts)
172
165
 
173
 
        Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([])
 
166
        Puppet::Node.indirection.expects(:search).with("whatever",:fqdn => nil).returns([])
174
167
 
175
168
        @kick.setup
176
169
      end
180
173
        @kick.stubs(:puts)
181
174
        @kick.classes = ['class']
182
175
 
183
 
        Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
 
176
        Puppet::Node.indirection.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
184
177
 
185
178
        @kick.setup
186
179
      end
191
184
        $stderr.stubs(:puts)
192
185
        @kick.classes = ['class']
193
186
 
194
 
        @kick.expects(:exit).with(24)
195
 
 
196
 
        @kick.setup
 
187
        expect { @kick.setup }.to exit_with 24
197
188
      end
198
189
    end
199
190
  end
219
210
 
220
211
    describe "the test command" do
221
212
      it "should exit with exit code 0 " do
222
 
        @kick.expects(:exit).with(0)
223
 
 
224
 
        @kick.test
 
213
        expect { @kick.test }.to exit_with 0
225
214
      end
226
215
    end
227
216
 
233
222
        @kick.options.stubs(:[]).with(:foreground).returns(false)
234
223
        @kick.options.stubs(:[]).with(:debug).returns(false)
235
224
        @kick.stubs(:print)
236
 
        @kick.stubs(:exit)
237
225
        @kick.preinit
238
226
        @kick.stubs(:parse_options)
239
227
        @kick.setup
243
231
      it "should create as much childs as --parallel" do
244
232
        @kick.options.stubs(:[]).with(:parallel).returns(3)
245
233
        @kick.hosts = ['host1', 'host2', 'host3']
246
 
        @kick.stubs(:exit).raises(SystemExit)
247
234
        Process.stubs(:wait).returns(1).then.returns(2).then.returns(3).then.raises(Errno::ECHILD)
248
235
 
249
236
        @kick.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3)
250
237
 
251
 
        lambda { @kick.main }.should raise_error
 
238
        expect { @kick.main }.to raise_error SystemExit
252
239
      end
253
240
 
254
241
      it "should delegate to run_for_host per host" do
255
242
        @kick.hosts = ['host1', 'host2']
256
 
        @kick.stubs(:exit).raises(SystemExit)
257
243
        @kick.stubs(:fork).returns(1).yields
258
244
        Process.stubs(:wait).returns(1).then.raises(Errno::ECHILD)
259
245
 
277
263
        end
278
264
 
279
265
        it "should call run on a Puppet::Run for the given host" do
280
 
          @agent_run.expects(:save).with('https://host:8139/production/run/host').returns(@agent_run)
 
266
          Puppet::Run.indirection.expects(:save).with(@agent_run, 'https://host:8139/production/run/host').returns(@agent_run)
281
267
 
282
 
          @kick.run_for_host('host')
 
268
          expect { @kick.run_for_host('host') }.to exit_with 0
283
269
        end
284
270
 
285
271
        it "should exit the child with 0 on success" do
286
272
          @agent_run.stubs(:status).returns("success")
287
 
 
288
 
          @kick.expects(:exit).with(0)
289
 
 
290
 
          @kick.run_for_host('host')
 
273
          expect { @kick.run_for_host('host') }.to exit_with 0
291
274
        end
292
275
 
293
276
        it "should exit the child with 3 on running" do
294
277
          @agent_run.stubs(:status).returns("running")
295
 
 
296
 
          @kick.expects(:exit).with(3)
297
 
 
298
 
          @kick.run_for_host('host')
 
278
          expect { @kick.run_for_host('host') }.to exit_with 3
299
279
        end
300
280
 
301
281
        it "should exit the child with 12 on unknown answer" do
302
282
          @agent_run.stubs(:status).returns("whatever")
303
 
 
304
 
          @kick.expects(:exit).with(12)
305
 
 
306
 
          @kick.run_for_host('host')
 
283
          expect { @kick.run_for_host('host') }.to exit_with 12
307
284
        end
308
285
      end
309
286
    end