gosen 0.1.5 → 0.1.6
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/VERSION +1 -1
- data/lib/gosen.rb +1 -1
- data/lib/gosen/deployment.rb +24 -10
- data/lib/gosen/deployment_run.rb +2 -2
- data/test/gosen/test_deployment.rb +42 -1
- data/test/gosen/test_deployment_run.rb +9 -2
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.6
|
data/lib/gosen.rb
CHANGED
data/lib/gosen/deployment.rb
CHANGED
|
@@ -23,11 +23,15 @@ module Gosen
|
|
|
23
23
|
@api_options = {}
|
|
24
24
|
@logger = options.delete(:logger) || NullLogger.new
|
|
25
25
|
|
|
26
|
+
@site.session.default_headers['User-Agent'] = "Gosen/#{Gosen::VERSION} Restfully/#{Restfully::VERSION}"
|
|
27
|
+
|
|
26
28
|
@min_deployed_nodes = options.delete(:min_deployed_nodes) || 1
|
|
27
|
-
raise Gosen::Error if @min_deployed_nodes > @nodes.length || @min_deployed_nodes < 0
|
|
29
|
+
raise Gosen::Error.new("Invalid minimal number of deployed nodes, should be between 0 and #{@nodes.length}") if @min_deployed_nodes > @nodes.length || @min_deployed_nodes < 0
|
|
28
30
|
|
|
29
31
|
@max_deploy_runs = options.delete(:max_deploy_runs) || 1
|
|
30
|
-
raise Gosen::Error if @max_deploy_runs < 1
|
|
32
|
+
raise Gosen::Error.new("Invalid maximal number of deployments, should be greater than or equal to 1") if @max_deploy_runs < 1
|
|
33
|
+
|
|
34
|
+
@continue_if_error = options.delete(:continue_if_error) || false
|
|
31
35
|
|
|
32
36
|
if options[:ssh_public_key]
|
|
33
37
|
@ssh_public_key = options[:ssh_public_key]
|
|
@@ -48,21 +52,31 @@ module Gosen
|
|
|
48
52
|
|
|
49
53
|
def join
|
|
50
54
|
@max_deploy_runs.times do |i|
|
|
51
|
-
@
|
|
55
|
+
@deployment_run = Gosen::DeploymentRun.new(@site, @environment, @bad_nodes, @api_options)
|
|
52
56
|
@logger.info("Kadeploy run #{i + 1} with #{@bad_nodes.length} nodes (#{@good_nodes.length} already deployed, need #{@min_deployed_nodes - @good_nodes.length} more)")
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
begin
|
|
58
|
+
@deployment_run.wait_for_completion
|
|
59
|
+
rescue Gosen::Error => e
|
|
60
|
+
if e.message =~ /^Deployment error/ && @continue_if_error
|
|
61
|
+
@logger.warn("Deployment error: #{@deployment_run.deployment_resource['output']}")
|
|
62
|
+
@logger.warn("Continuing because continue_if_error is set")
|
|
63
|
+
next
|
|
64
|
+
else
|
|
65
|
+
raise e
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
@deployment_run.update_nodes
|
|
69
|
+
@bad_nodes = @deployment_run.bad_nodes
|
|
70
|
+
@good_nodes |= @deployment_run.good_nodes
|
|
71
|
+
@logger.info("Nodes deployed: #{@deployment_run.good_nodes.join(' ')}") unless @deployment_run.good_nodes.empty?
|
|
72
|
+
@logger.info("Nodes which failed: #{@deployment_run.bad_nodes.join(' ')}") unless @deployment_run.bad_nodes.empty?
|
|
59
73
|
if no_more_required?
|
|
60
74
|
@all_runs_done = true
|
|
61
75
|
@logger.info("Had to run #{i + 1} kadeploy runs, deployed #{@good_nodes.length} nodes")
|
|
62
76
|
return
|
|
63
77
|
end
|
|
64
78
|
end
|
|
65
|
-
raise Gosen::Error.new(
|
|
79
|
+
raise Gosen::Error.new("Not enough nodes deployed after #{@max_deploy_runs} deployment(s): needed #{@min_deployed_nodes} nodes, got only #{@good_nodes.length}")
|
|
66
80
|
end
|
|
67
81
|
|
|
68
82
|
def no_more_required?
|
data/lib/gosen/deployment_run.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Gosen
|
|
|
3
3
|
# Time between two checks of the deployment run status
|
|
4
4
|
POLLING_TIME = 10
|
|
5
5
|
|
|
6
|
-
attr_reader :environment, :nodes, :site, :ssh_public_key
|
|
6
|
+
attr_reader :deployment_resource, :environment, :nodes, :site, :ssh_public_key
|
|
7
7
|
|
|
8
8
|
# Launch a new deployment run
|
|
9
9
|
# @param [Restfully:Resource] site the deployment site, as a restfully resource
|
|
@@ -57,7 +57,7 @@ module Gosen
|
|
|
57
57
|
Kernel.sleep(Gosen::DeploymentRun::POLLING_TIME)
|
|
58
58
|
@deployment_resource.reload
|
|
59
59
|
end
|
|
60
|
-
raise Gosen::Error if @deployment_resource['status'] == 'error'
|
|
60
|
+
raise Gosen::Error.new("Deployment error: #{@deployment_resource['output']}") if @deployment_resource['status'] == 'error'
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def update_nodes
|
|
@@ -4,6 +4,11 @@ class TestDeployment < Test::Unit::TestCase
|
|
|
4
4
|
context 'A deployment instance' do
|
|
5
5
|
setup do
|
|
6
6
|
@site = mock()
|
|
7
|
+
@session = mock()
|
|
8
|
+
@default_headers = mock()
|
|
9
|
+
@default_headers.stubs(:[]=).with('User-Agent', "Gosen/#{Gosen::VERSION} Restfully/#{Restfully::VERSION}")
|
|
10
|
+
@session.stubs(:default_headers).returns(@default_headers)
|
|
11
|
+
@site.stubs(:session).returns(@session)
|
|
7
12
|
@site_name = "Rennes"
|
|
8
13
|
@site.stubs(:name).returns(@site_name)
|
|
9
14
|
@environment = 'lenny-x64-base'
|
|
@@ -148,7 +153,12 @@ class TestDeployment < Test::Unit::TestCase
|
|
|
148
153
|
|
|
149
154
|
@deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => 2 })
|
|
150
155
|
assert_raise(Gosen::Error) {
|
|
151
|
-
|
|
156
|
+
begin
|
|
157
|
+
@deployment.join
|
|
158
|
+
rescue Gosen::Error => e
|
|
159
|
+
assert_equal("Not enough nodes deployed after 1 deployment(s): needed 2 nodes, got only 1", e.message)
|
|
160
|
+
raise e
|
|
161
|
+
end
|
|
152
162
|
}
|
|
153
163
|
end
|
|
154
164
|
|
|
@@ -196,6 +206,37 @@ class TestDeployment < Test::Unit::TestCase
|
|
|
196
206
|
assert_equal(@nodes, @deployment.good_nodes)
|
|
197
207
|
assert_equal([], @deployment.bad_nodes)
|
|
198
208
|
end
|
|
209
|
+
|
|
210
|
+
should 'continue deploying when an error happens and :continue_if_error was set' do
|
|
211
|
+
@ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
|
|
212
|
+
@deployment_resource1 = mock()
|
|
213
|
+
@deployment_resource2 = mock()
|
|
214
|
+
@deployment_resource1.stubs(:reload)
|
|
215
|
+
@deployment_resource2.stubs(:reload)
|
|
216
|
+
|
|
217
|
+
@output = 'Your key cannot be fetched.'
|
|
218
|
+
@deployment_result2 = {
|
|
219
|
+
'paramount-1.rennes.grid5000.fr' => { 'state' => 'OK' },
|
|
220
|
+
'paramount-2.rennes.grid5000.fr' => { 'state' => 'OK' }
|
|
221
|
+
}
|
|
222
|
+
@deployment_resource1.stubs(:[]).with('status').returns('processing', 'processing', 'error')
|
|
223
|
+
@deployment_resource1.stubs(:[]).with('output').returns(@output)
|
|
224
|
+
@deployment_resource2.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
|
|
225
|
+
@deployment_resource2.expects(:[]).with('result').returns(@deployment_result2)
|
|
226
|
+
@min_deployed_nodes = 2
|
|
227
|
+
@site_deployments.expects(:submit).twice.with({ :environment => @environment, :nodes => @nodes, :key => @ssh_public_key }).returns(@deployment_resource1, @deployment_resource2)
|
|
228
|
+
@logger.expects(:info).with("Kadeploy run 1 with 2 nodes (0 already deployed, need 2 more)")
|
|
229
|
+
@logger.expects(:warn).with("Deployment error: #{@output}")
|
|
230
|
+
@logger.expects(:warn).with("Continuing because continue_if_error is set")
|
|
231
|
+
@logger.expects(:info).with("Kadeploy run 2 with 2 nodes (0 already deployed, need 2 more)")
|
|
232
|
+
@logger.expects(:info).with("Nodes deployed: paramount-1.rennes.grid5000.fr paramount-2.rennes.grid5000.fr")
|
|
233
|
+
@logger.expects(:info).with("Had to run 2 kadeploy runs, deployed 2 nodes")
|
|
234
|
+
|
|
235
|
+
@deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :logger => @logger, :min_deployed_nodes => @min_deployed_nodes, :max_deploy_runs => 2, :ssh_public_key => @ssh_public_key, :continue_if_error => true })
|
|
236
|
+
@deployment.join
|
|
237
|
+
assert_equal(@nodes, @deployment.good_nodes)
|
|
238
|
+
assert_equal([], @deployment.bad_nodes)
|
|
239
|
+
end
|
|
199
240
|
end
|
|
200
241
|
end
|
|
201
242
|
end
|
|
@@ -95,6 +95,8 @@ class TestDeploymentRun < Test::Unit::TestCase
|
|
|
95
95
|
@ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
|
|
96
96
|
@resource = mock()
|
|
97
97
|
@resource.stubs(:[]).with('status').returns('processing', 'processing', 'error')
|
|
98
|
+
@output = 'Your key cannot be fetched.'
|
|
99
|
+
@resource.stubs(:[]).with('output').returns(@output)
|
|
98
100
|
@resource.expects(:reload).twice
|
|
99
101
|
Kernel.expects(:sleep).with(Gosen::DeploymentRun::POLLING_TIME).twice
|
|
100
102
|
|
|
@@ -106,9 +108,14 @@ class TestDeploymentRun < Test::Unit::TestCase
|
|
|
106
108
|
@deployment = Gosen::DeploymentRun.new(@site, @environment, @nodes, { :ssh_public_key => @ssh_public_key })
|
|
107
109
|
end
|
|
108
110
|
|
|
109
|
-
should 'raise an exception' do
|
|
111
|
+
should 'raise an exception and print the deployment output' do
|
|
110
112
|
assert_raise(Gosen::Error) {
|
|
111
|
-
|
|
113
|
+
begin
|
|
114
|
+
@deployment.join
|
|
115
|
+
rescue Gosen::Error => e
|
|
116
|
+
assert_equal("Deployment error: #{@output}", e.message)
|
|
117
|
+
raise e
|
|
118
|
+
end
|
|
112
119
|
}
|
|
113
120
|
end
|
|
114
121
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 6
|
|
9
|
+
version: 0.1.6
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Pierre Riteau
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-10-
|
|
17
|
+
date: 2010-10-26 00:00:00 +02:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|