kumo_dockercloud 3.1.1 → 3.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad2671be63f6abc977f2bf30685ced335589bb12
4
- data.tar.gz: 635f266c6dd92c1efc4c3c42a0c21277cf066463
3
+ metadata.gz: d56a26a559069438a8dffe96f6197a43ff784a88
4
+ data.tar.gz: b8b55150263ca7259d21524b8bd759c412561122
5
5
  SHA512:
6
- metadata.gz: 890aefc823c9e726e6a17358fc191d4f37cf8d9dd78ed5505eb4f78edea10522fde7140731d299258cf866941a8434217b4ee198d5275d41a35b6074bda7d2d0
7
- data.tar.gz: 85f752619dd42387da47cba37d53e0fdb7a4198499b32a0e98f17c4680a55359ecb4f04fbca08e9828d0c3b5778aaf47b59f16bbfbc228a6c12d85b6237375f1
6
+ metadata.gz: 36456d19ed2a73171023e65d5ed7e09de4a71d4c23d1e305a4c57c73dd488c5f43963289550f88648657dd0354e0c6184d725ed55df064694927f349e30073a7
7
+ data.tar.gz: 65858ebe4cabbd00d82b18e281c978cc1e2e5016925f4056a610a703844fc94b36669615bff7a8e1fe7edcc0448d9ef6945314c60a0bdbb042ac4af5ba4bbd2d
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in kumo_dockercloud.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ end
@@ -19,6 +19,12 @@ module KumoDockerCloud
19
19
  $stdout.flush
20
20
  end
21
21
 
22
+ def self.write_char(char)
23
+ print char
24
+
25
+ $stdout.flush
26
+ end
27
+
22
28
  def self.get_confirmation(timeout=30)
23
29
  begin
24
30
  status = Timeout::timeout(timeout) {
@@ -0,0 +1,14 @@
1
+ module KumoDockerCloud
2
+ class ServiceCheck
3
+ attr_reader :error_message
4
+
5
+ def initialize(lambda, error_message)
6
+ @error_message = error_message
7
+ @lambda = lambda
8
+ end
9
+
10
+ def call(container)
11
+ @lambda.call(container)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,5 @@
1
+ require_relative 'console_jockey'
2
+
1
3
  module KumoDockerCloud
2
4
  class ServiceChecker
3
5
  attr_reader :checks, :timeout, :quiet_time
@@ -12,24 +14,35 @@ module KumoDockerCloud
12
14
  Timeout::timeout(timeout) do
13
15
 
14
16
  while any_check_failing?(service)
15
- print '.'
17
+ ConsoleJockey.write_char '.'
16
18
  sleep(quiet_time)
17
19
  end
18
20
 
19
21
  end
20
22
  rescue Timeout::Error
21
- raise KumoDockerCloud::ServiceDeployError.new("One or more checks failed to pass within the timeout")
23
+ if @error_messages.length > 0
24
+ raise KumoDockerCloud::ServiceDeployError.new("One or more checks failed to pass within the timeout.#{@error_messages.join}")
25
+ else
26
+ raise KumoDockerCloud::ServiceDeployError.new("One or more checks failed to pass within the timeout. I'd show you what went wrong but the checks were lambdas so I can't. Maybe you should update your usage to the new ServiceCheck object instead of lambdas?")
27
+ end
22
28
  end
23
29
 
24
30
  private
25
31
 
26
32
  def any_check_failing?(service)
33
+ failed = false
34
+ @error_messages = []
27
35
  checks.each do |check|
28
36
  service.containers.each do |container|
29
- return true unless check.call(container)
37
+ unless check.call(container)
38
+ failed = true
39
+ end
40
+ end
41
+ if failed && check.respond_to?(:error_message)
42
+ @error_messages << ( "\nMessage: #{check.error_message} | Service Name: #{service.name}" )
30
43
  end
31
44
  end
32
- false
45
+ failed
33
46
  end
34
47
  end
35
48
  end
@@ -1,8 +1,8 @@
1
1
  module KumoDockerCloud
2
2
  class StackChecker
3
- def initialize(specific_checks = {}, common_check = nil, timeout = 300)
3
+ def initialize(specific_checks = {}, default_check = nil, timeout = 300)
4
4
  @checks = specific_checks
5
- @default_check = common_check
5
+ @default_check = default_check
6
6
  @timeout = timeout
7
7
  end
8
8
 
@@ -28,7 +28,7 @@ module KumoDockerCloud
28
28
  private
29
29
 
30
30
  def default_check
31
- @default_check ||= [lambda { |container| container.state == 'Running' }]
31
+ @default_check ||= [ServiceCheck.new(lambda { |container| container.state == 'Running' }, "Service is not running")]
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module KumoDockerCloud
2
- VERSION = '3.1.1'
2
+ VERSION = '3.2.0'
3
3
  end
@@ -4,5 +4,6 @@ require 'kumo_dockercloud/stack'
4
4
  require 'kumo_dockercloud/stack_checker'
5
5
  require 'kumo_dockercloud/service'
6
6
  require 'kumo_dockercloud/service_checker'
7
+ require 'kumo_dockercloud/service_check'
7
8
  require 'kumo_dockercloud/errors'
8
9
  require 'kumo_dockercloud/console_jockey'
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe KumoDockerCloud::ServiceChecker do
2
4
  describe ".initialize" do
3
5
  context "defaults" do
@@ -18,49 +20,118 @@ describe KumoDockerCloud::ServiceChecker do
18
20
  end
19
21
 
20
22
  describe '#verify' do
21
- let(:happy_check) { lambda { |container| expect(container).to eq(container); true } }
22
- let(:sad_check) { lambda { |container| expect(container).to eq(container); false } }
23
23
  let(:container) { double(:my_container) }
24
- let(:checks) {[happy_check]}
25
- let(:timeout) { 5 }
26
-
27
24
  let(:containers) { [container, container] }
25
+ let(:service) { instance_double(KumoDockerCloud::Service, containers: containers, name: 'service') }
26
+ let(:timeout) { 0.5 }
27
+ let(:quiet_time) { 0.1 }
28
28
 
29
- let(:service) { instance_double(KumoDockerCloud::Service, containers: containers) }
29
+ subject { described_class.new(checks, timeout, quiet_time).verify(service) }
30
+
31
+ before do
32
+ allow(KumoDockerCloud::ConsoleJockey).to receive(:write_char).and_return(nil)
33
+ end
30
34
 
31
- subject { described_class.new(checks, timeout, 1).verify(service) }
35
+ context 'passing ServiceCheck objects' do
36
+ let(:check) { KumoDockerCloud::ServiceCheck.new(check_lambda, check_error_message) }
37
+ let(:check_lambda) { lambda { |_container| true } }
38
+ let(:check_error_message) { "" }
39
+ let(:checks) { [check] }
32
40
 
33
- context "all checks successful" do
34
- it "runs without incident" do
35
- subject
41
+ context 'all checks successful' do
42
+ it 'runs without incident' do
43
+ subject
44
+ end
36
45
  end
37
46
 
38
- context "no checks" do
39
- let(:checks) { [] }
47
+ context "timing out check" do
48
+ let(:timeout) { 2 }
49
+ let(:check_lambda) { lambda { |_container| false } }
50
+ let(:check_error_message) { "Expected error message" }
40
51
 
41
- it "runs without retrieving containers" do
42
- expect(service).not_to receive(:containers)
52
+ it "raises an error with service detail" do
53
+ expect { subject }.to raise_error(KumoDockerCloud::ServiceDeployError, "One or more checks failed to pass within the timeout.\nMessage: #{check_error_message} | Service Name: #{service.name}")
54
+ end
55
+ end
56
+
57
+ context "checks that pass the second time" do
58
+ let(:mutating_state) { [] }
59
+ let(:check_lambda) { lambda { |_container| mutating_state << 1; mutating_state.size > 1 } }
60
+ let(:check_error_message) { "Your mutant became a zombie" }
61
+
62
+ it "runs without incident" do
43
63
  subject
44
64
  end
45
65
  end
46
- end
47
66
 
48
- context "timing out check" do
49
- let(:timeout) { 2 }
50
- let(:checks) { [sad_check] }
67
+ context "one check failing and succeding and one check failing" do
68
+ let(:mutating_state) { [] }
69
+ let(:failed_and_passed_lambda) { lambda { |_container| mutating_state << 1; mutating_state.size > 1 } }
70
+ let(:failed_and_passed_error_message) { "Your mutant became a zombie" }
71
+ let(:failed_and_passed_check) { KumoDockerCloud::ServiceCheck.new(failed_and_passed_lambda, failed_and_passed_error_message) }
72
+ let(:failing_lambda) { lambda { |_container| false } }
73
+ let(:failing_error_message) { "You failed. Too bad." }
74
+ let(:failing_check) { KumoDockerCloud::ServiceCheck.new(failing_lambda, failing_error_message) }
75
+ let(:checks) { [failed_and_passed_check, failing_check] }
76
+
77
+ it "runs without incident" do
78
+ expect { subject }.to raise_error(KumoDockerCloud::ServiceDeployError, "One or more checks failed to pass within the timeout.\nMessage: #{failing_error_message} | Service Name: #{service.name}")
79
+ end
80
+ end
81
+
82
+ context 'multiple checks failing' do
83
+ let(:failing_lambda_a) { lambda { |_container| false } }
84
+ let(:failing_error_message_a) { "You failed check A. Too bad." }
85
+ let(:failing_check_a) { KumoDockerCloud::ServiceCheck.new(failing_lambda_a, failing_error_message_a) }
86
+ let(:failing_lambda_b) { lambda { |_container| false } }
87
+ let(:failing_error_message_b) { "You failed check B. Too bad." }
88
+ let(:failing_check_b) { KumoDockerCloud::ServiceCheck.new(failing_lambda_b, failing_error_message_b) }
89
+ let(:checks) { [failing_check_a, failing_check_b] }
90
+ let(:containers) { [container] }
51
91
 
52
- it "raises an error" do
53
- expect { subject }.to raise_error(KumoDockerCloud::ServiceDeployError, "One or more checks failed to pass within the timeout")
92
+ it 'includes all error messages' do
93
+ expect { subject }.to raise_error(KumoDockerCloud::ServiceDeployError, "One or more checks failed to pass within the timeout.\nMessage: #{failing_error_message_a} | Service Name: #{service.name}\nMessage: #{failing_error_message_b} | Service Name: #{service.name}")
94
+ end
54
95
  end
55
96
  end
56
97
 
57
- context "second time is the charm" do
58
- let(:mutating_state) { [] }
59
- let(:mutating_check) { lambda { |_container| mutating_state << 1; mutating_state.size > 1 } }
60
- let(:checks) { [mutating_check] }
98
+ context 'passing lambdas' do
99
+ let(:happy_check) { lambda { |container| expect(container).to eq(container); true } }
100
+ let(:sad_check) { lambda { |container| expect(container).to eq(container); false } }
101
+ let(:checks) {[happy_check]}
102
+
103
+ context "all checks successful" do
104
+ it "runs without incident" do
105
+ subject
106
+ end
107
+
108
+ context "no checks" do
109
+ let(:checks) { [] }
110
+
111
+ it "runs without retrieving containers" do
112
+ expect(service).not_to receive(:containers)
113
+ subject
114
+ end
115
+ end
116
+ end
61
117
 
62
- it "runs without incident" do
63
- subject
118
+ context "timing out check" do
119
+ let(:timeout) { 2 }
120
+ let(:checks) { [sad_check] }
121
+
122
+ it "raises an error" do
123
+ expect { subject }.to raise_error(KumoDockerCloud::ServiceDeployError, "One or more checks failed to pass within the timeout. I'd show you what went wrong but the checks were lambdas so I can't. Maybe you should update your usage to the new ServiceCheck object instead of lambdas?")
124
+ end
125
+ end
126
+
127
+ context "second time is the charm" do
128
+ let(:mutating_state) { [] }
129
+ let(:mutating_check) { lambda { |_container| mutating_state << 1; mutating_state.size > 1 } }
130
+ let(:checks) { [mutating_check] }
131
+
132
+ it "runs without incident" do
133
+ subject
134
+ end
64
135
  end
65
136
  end
66
137
  end
@@ -5,8 +5,8 @@ describe KumoDockerCloud::StackChecker do
5
5
  let(:services) { [service]}
6
6
  let(:failed_services) { double(:service_api, name: 'redbubble', state: 'Stopped')}
7
7
  let(:service_checker) { instance_double(KumoDockerCloud::ServiceChecker, verify: nil)}
8
- let(:default_service_check) { [double(:default_check)] }
9
- let(:specific_service_check) { { "redbubble" => [double(:specific_check)] } }
8
+ let(:default_service_check) { instance_double(KumoDockerCloud::ServiceCheck) }
9
+ let(:specific_service_check) { { "redbubble" => [instance_double(KumoDockerCloud::ServiceCheck)] } }
10
10
 
11
11
  subject { described_class.new.verify(stack) }
12
12
 
@@ -33,13 +33,13 @@ describe KumoDockerCloud::StackChecker do
33
33
 
34
34
  context 'single service' do
35
35
  context 'without passing services checks' do
36
- before { allow_any_instance_of(KumoDockerCloud::StackChecker).to receive(:default_check).and_return(default_service_check) }
36
+ before { allow(KumoDockerCloud::ServiceCheck).to receive(:new).and_return(default_service_check) }
37
37
  it 'returns true when verify successful' do
38
38
  expect(subject).to be true
39
39
  end
40
40
 
41
41
  it 'uses default check' do
42
- expect(KumoDockerCloud::ServiceChecker).to receive(:new).with(default_service_check, 300)
42
+ expect(KumoDockerCloud::ServiceChecker).to receive(:new).with([default_service_check], 300)
43
43
  subject
44
44
  end
45
45
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumo_dockercloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbubble
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-24 00:00:00.000000000 Z
13
+ date: 2016-05-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httpi
@@ -150,6 +150,7 @@ files:
150
150
  - lib/kumo_dockercloud/environment_config.rb
151
151
  - lib/kumo_dockercloud/errors.rb
152
152
  - lib/kumo_dockercloud/service.rb
153
+ - lib/kumo_dockercloud/service_check.rb
153
154
  - lib/kumo_dockercloud/service_checker.rb
154
155
  - lib/kumo_dockercloud/stack.rb
155
156
  - lib/kumo_dockercloud/stack_checker.rb