runpuppet 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -46,7 +46,7 @@ This is the companion for our puppet_controller, a light-weight web-service to c
46
46
 
47
47
  ### Release the gem
48
48
  # on master branch
49
- $ sh/release
49
+ $ sh/release VERSION
50
50
 
51
51
 
52
52
  ## Contributing to runpuppet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -11,9 +11,16 @@ module Runpuppet
11
11
  ##### puppet
12
12
 
13
13
  def check_status
14
- action, branch = get("/puppet/run", @run_options).split('-') rescue []
15
- branch ||= (run_options[:branch] || config.default_branch)
16
- return action, branch
14
+ begin
15
+ r = get("/puppet/run")
16
+ rescue Exception => e
17
+ end
18
+
19
+ if r
20
+ return (action, branch = *r.split('-'))
21
+ else
22
+ return nil
23
+ end
17
24
  end
18
25
 
19
26
  def report_start
@@ -13,8 +13,8 @@ module Runpuppet
13
13
 
14
14
  def run
15
15
  with_lock(config.lock_file) do
16
- action, branch = agent.check_status
17
- if should_run?(action)
16
+ action, branch = calculate_run_params
17
+ if action == 'run'
18
18
  agent.report_start
19
19
  log "run #{branch}"
20
20
 
@@ -30,6 +30,19 @@ module Runpuppet
30
30
  end
31
31
  end
32
32
 
33
+ def calculate_run_params
34
+ (local_run_params || remote_run_params)
35
+ end
36
+
37
+ def local_run_params
38
+ return nil if run_options[:try]
39
+ return 'run', (run_options[:branch] ||config.default_branch)
40
+ end
41
+
42
+ def remote_run_params
43
+ agent.check_status
44
+ end
45
+
33
46
  def run_command(branch)
34
47
  cmd = if run_options[:verbose]
35
48
  config.verbose_command
@@ -39,11 +52,6 @@ module Runpuppet
39
52
  cmd.gsub('@@branch@@', branch)
40
53
  end
41
54
 
42
- def should_run?(action)
43
- ## always run if started without --try
44
- (!run_options[:try] or action == 'run')
45
- end
46
-
47
55
  def with_lock(lock_file)
48
56
  recently_locked = (File.exists?(lock_file) and File.mtime(lock_file) > Time.now - 15*60)
49
57
 
data/runpuppet.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "runpuppet"
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Heinrich"]
data/test/agent_test.rb CHANGED
@@ -2,7 +2,8 @@ require 'test/helper'
2
2
 
3
3
  describe "Runpuppet::Agent" do
4
4
  before do
5
- @agent = TestContext.agent
5
+ @ctx = Dim::Container.new(TestContext)
6
+ @agent = @ctx.agent
6
7
  end
7
8
 
8
9
  describe :check_status do
@@ -10,6 +11,11 @@ describe "Runpuppet::Agent" do
10
11
  @agent.stubs(:get).returns('run-master')
11
12
  @agent.check_status.must_equal ["run", "master"]
12
13
  end
14
+
15
+ it "returns nil for errors" do
16
+ @agent.stubs(:get).raises(RuntimeError)
17
+ @agent.check_status.must_be_nil
18
+ end
13
19
  end
14
20
 
15
21
  describe :base_url do
@@ -20,8 +26,8 @@ describe "Runpuppet::Agent" do
20
26
 
21
27
  describe "URL manipulation" do
22
28
  before do
23
- TestContext.config.stubs(:local_ip).returns('10.10.10.10')
24
- TestContext.config.stubs(:hostname).returns('example-vm')
29
+ @ctx.config.stubs(:local_ip).returns('10.10.10.10')
30
+ @ctx.config.stubs(:hostname).returns('example-vm')
25
31
  end
26
32
 
27
33
 
data/test/client_test.rb CHANGED
@@ -18,20 +18,23 @@ describe "Client" do
18
18
  end
19
19
  end
20
20
 
21
- describe :should_run? do
21
+ describe :local_run_params do
22
22
  it "always runs without --try option" do
23
23
  @ctx.register(:run_options){ {:try => false} }
24
- @ctx.client.should_run?('branch_does_not_matter').must_equal true
24
+ @ctx.client.local_run_params.must_equal ["run", "master"]
25
25
  end
26
26
 
27
- it "runs with --try option only for 'run' action" do
27
+ it "is nil with --try option" do
28
28
  @ctx.register(:run_options){ {:try => true} }
29
- @ctx.client.should_run?('run').must_equal true
29
+ @ctx.client.local_run_params.must_be_nil
30
30
  end
31
+ end
31
32
 
32
- it "does not run with --try option, if not 'run' action" do
33
+ describe :remote_run_params do
34
+ it "always runs without --try option" do
33
35
  @ctx.register(:run_options){ {:try => true} }
34
- @ctx.client.should_run?('some_random_action').must_equal false
36
+ @ctx.client.stubs(:remote_run_params).returns(["run", "master"])
37
+ @ctx.client.calculate_run_params.must_equal ['run', 'master']
35
38
  end
36
39
  end
37
40
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runpuppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roman Heinrich