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 +4 -4
- data/Gemfile +4 -0
- data/lib/kumo_dockercloud/console_jockey.rb +6 -0
- data/lib/kumo_dockercloud/service_check.rb +14 -0
- data/lib/kumo_dockercloud/service_checker.rb +17 -4
- data/lib/kumo_dockercloud/stack_checker.rb +3 -3
- data/lib/kumo_dockercloud/version.rb +1 -1
- data/lib/kumo_dockercloud.rb +1 -0
- data/spec/kumo_dockercloud/service_checker_spec.rb +97 -26
- data/spec/kumo_dockercloud/stack_checker_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d56a26a559069438a8dffe96f6197a43ff784a88
|
4
|
+
data.tar.gz: b8b55150263ca7259d21524b8bd759c412561122
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36456d19ed2a73171023e65d5ed7e09de4a71d4c23d1e305a4c57c73dd488c5f43963289550f88648657dd0354e0c6184d725ed55df064694927f349e30073a7
|
7
|
+
data.tar.gz: 65858ebe4cabbd00d82b18e281c978cc1e2e5016925f4056a610a703844fc94b36669615bff7a8e1fe7edcc0448d9ef6945314c60a0bdbb042ac4af5ba4bbd2d
|
data/Gemfile
CHANGED
@@ -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
|
-
|
17
|
+
ConsoleJockey.write_char '.'
|
16
18
|
sleep(quiet_time)
|
17
19
|
end
|
18
20
|
|
19
21
|
end
|
20
22
|
rescue Timeout::Error
|
21
|
-
|
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
|
-
|
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
|
-
|
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 = {},
|
3
|
+
def initialize(specific_checks = {}, default_check = nil, timeout = 300)
|
4
4
|
@checks = specific_checks
|
5
|
-
@default_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
|
data/lib/kumo_dockercloud.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
41
|
+
context 'all checks successful' do
|
42
|
+
it 'runs without incident' do
|
43
|
+
subject
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
|
-
context "
|
39
|
-
let(:
|
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 "
|
42
|
-
expect
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
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
|
58
|
-
let(:
|
59
|
-
let(:
|
60
|
-
let(:checks) {
|
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
|
-
|
63
|
-
|
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) {
|
9
|
-
let(:specific_service_check) { { "redbubble" => [
|
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 {
|
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.
|
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-
|
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
|