gosen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.md
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Pierre Riteau
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Gosen
2
+
3
+ Gosen is a Ruby library for the [Grid'5000 RESTful API](https://api.grid5000.fr/).
4
+
5
+ ## Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2010 Pierre Riteau. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gosen"
8
+ gem.summary = %Q{A Ruby library for the Grid'5000 RESTful API}
9
+ gem.description = %Q{Gosen is a Ruby library providing high-level operations using the Grid'5000 RESTful API, such as Kadeploy deployments}
10
+ gem.email = "priteau@gmail.com"
11
+ gem.homepage = "http://github.com/priteau/gosen"
12
+ gem.authors = ["Pierre Riteau"]
13
+ gem.add_dependency "restfully", ">= 0.5.1"
14
+ gem.add_development_dependency "mocha", ">= 0.9.8"
15
+ gem.add_development_dependency "shoulda", ">= 2.10.2"
16
+ gem.add_development_dependency "yard", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ begin
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new
51
+ rescue LoadError
52
+ task :yardoc do
53
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
54
+ end
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ module Gosen
2
+ class NullLogger
3
+ def method_missing(method, *args)
4
+ nil
5
+ end
6
+ end
7
+
8
+ class Deployment
9
+ attr_reader :environment, :logger, :max_deploy_runs, :min_deployed_nodes, :nodes, :site, :ssh_public_key
10
+
11
+ # Launch a new deployment
12
+ # @param [Restfully::Resource] site the deployment site, as a restfully resource
13
+ # @param [String] environment the name of the environment to deploy
14
+ # @param [Enumerable] nodes the list of nodes to deploy to
15
+ # @param [Hash] options options
16
+ def initialize(site, environment, nodes, options = {})
17
+ @site = site
18
+ @environment = environment
19
+ @nodes = Array.new(nodes)
20
+ @good_nodes = []
21
+ @bad_nodes = Array.new(nodes)
22
+ @all_runs_done = false
23
+ @api_options = {}
24
+ @logger = options.delete(:logger) || NullLogger.new
25
+
26
+ @min_deployed_nodes = options[:min_deployed_nodes] || 1
27
+ raise Gosen::Error if @min_deployed_nodes > @nodes.length || @min_deployed_nodes < 0
28
+
29
+ @max_deploy_runs = options[:max_deploy_runs] || 1
30
+ raise Gosen::Error if @max_deploy_runs < 1
31
+
32
+ if options[:ssh_public_key]
33
+ @api_options[:key] = @ssh_public_key = options[:ssh_public_key]
34
+ end
35
+ end
36
+
37
+ def good_nodes
38
+ raise Gosen::Error unless @all_runs_done
39
+ @good_nodes
40
+ end
41
+
42
+ def bad_nodes
43
+ raise Gosen::Error unless @all_runs_done
44
+ @bad_nodes
45
+ end
46
+
47
+ def join
48
+ @max_deploy_runs.times do |i|
49
+ @deployment_resource = Gosen::DeploymentRun.new(@site, @environment, @bad_nodes)
50
+ @logger.info("Kadeploy run #{i + 1} with #{@bad_nodes.length} nodes (#{@good_nodes.length} already deployed, need #{@min_deployed_nodes - @good_nodes.length} more)")
51
+ @deployment_resource.wait_for_completion
52
+ @deployment_resource.update_nodes
53
+ @bad_nodes = @deployment_resource.bad_nodes
54
+ @good_nodes |= @deployment_resource.good_nodes
55
+ @logger.info("Nodes deployed: #{@deployment_resource.good_nodes.join(' ')}") unless @deployment_resource.good_nodes.empty?
56
+ @logger.info("Nodes which failed: #{@deployment_resource.bad_nodes.join(' ')}") unless @deployment_resource.bad_nodes.empty?
57
+ if no_more_required?
58
+ @all_runs_done = true
59
+ @logger.info("Had to run #{i + 1} kadeploy runs, deployed #{@good_nodes.length} nodes")
60
+ return
61
+ end
62
+ end
63
+ raise Gosen::Error.new('Not enough nodes')
64
+ end
65
+
66
+ def no_more_required?
67
+ @good_nodes.length >= @min_deployed_nodes
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,71 @@
1
+ module Gosen
2
+ class DeploymentRun
3
+ # Time between two checks of the deployment run status
4
+ POLLING_TIME = 30
5
+
6
+ attr_reader :environment, :nodes, :site, :ssh_public_key
7
+
8
+ # Launch a new deployment run
9
+ # @param [Restfully:Resource] site the deployment site, as a restfully resource
10
+ # @param [String] environment the name of the environment to deploy
11
+ # @param [Enumerable] nodes the list of nodes to deploy to
12
+ # @param [Hash] options options
13
+ def initialize(site, environment, nodes, options = {})
14
+ @site = site
15
+ @environment = environment
16
+ @nodes = nodes
17
+ @good_nodes = []
18
+ @bad_nodes = Array.new(@nodes)
19
+ @api_options = {}
20
+
21
+ if options[:ssh_public_key]
22
+ @api_options[:key] = @ssh_public_key = options[:ssh_public_key]
23
+ end
24
+ submit_deployment
25
+ end
26
+
27
+ def terminated?
28
+ @deployment_resource['status'] == 'terminated'
29
+ end
30
+
31
+ def good_nodes
32
+ raise Gosen::Error unless terminated?
33
+ @good_nodes.sort
34
+ end
35
+
36
+ def bad_nodes
37
+ raise Gosen::Error unless terminated?
38
+ @bad_nodes.sort
39
+ end
40
+
41
+ def submit_deployment
42
+ @deployment_resource = @site.deployments.submit({
43
+ :environment => @environment,
44
+ :nodes => @bad_nodes,
45
+ }.merge(@api_options))
46
+ end
47
+
48
+ # Wait for a deployment to complete
49
+ def join
50
+ wait_for_completion
51
+ update_nodes
52
+ end
53
+
54
+ # Wait for a single deployment run to complete
55
+ def wait_for_completion
56
+ until terminated? do
57
+ Kernel.sleep(Gosen::DeploymentRun::POLLING_TIME)
58
+ @deployment_resource.reload
59
+ end
60
+ end
61
+
62
+ def update_nodes
63
+ @deployment_resource['result'].each do |node, node_result|
64
+ if node_result['state'] == 'OK'
65
+ @good_nodes << node
66
+ @bad_nodes.delete(node)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,4 @@
1
+ module Gosen
2
+ class Error < StandardError
3
+ end
4
+ end
data/lib/gosen.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'restfully'
2
+ require 'gosen/deployment_run'
3
+ require 'gosen/deployment'
4
+ require 'gosen/error'
5
+
6
+ module Gosen
7
+ # Extracts the site part of a Grid'5000 node hostname, and returns a hash indexing the nodes by their site
8
+ # Example:
9
+ #
10
+ # Input is:
11
+ # [
12
+ # 'paramount-1.rennes.grid5000.fr',
13
+ # 'paramount-2.rennes.grid5000.fr',
14
+ # 'grelon-1.nancy.grid5000.fr',
15
+ # 'grelon-2.nancy.grid5000.fr'
16
+ # ]
17
+ #
18
+ # Result is:
19
+ # {
20
+ # 'rennes' => [ 'paramount-1.rennes.grid5000.fr', 'paramount-2.rennes.grid5000.fr' ],
21
+ # 'nancy' => [ 'grelon-1.nancy.grid5000.fr', 'grelon-2.nancy.grid5000.fr' ]
22
+ # }
23
+ def self.index_nodes_by_site(nodes)
24
+ result = Hash.new { |hash, key| hash[key] = Array.new }
25
+ nodes.each do |node|
26
+ if node =~ /^[a-z]+-[0-9]+\.([a-z]+)\.grid5000\.fr$/
27
+ site = $1
28
+ result[site] << node
29
+ else
30
+ raise Gosen::Error
31
+ end
32
+ end
33
+ return result
34
+ end
35
+ end
@@ -0,0 +1,189 @@
1
+ require 'helper'
2
+
3
+ class TestDeployment < Test::Unit::TestCase
4
+ context 'A deployment instance' do
5
+ setup do
6
+ @site = mock()
7
+ @site_name = "Rennes"
8
+ @site.stubs(:name).returns(@site_name)
9
+ @environment = 'lenny-x64-base'
10
+ @nodes = [ 'paramount-1.rennes.grid5000.fr', 'paramount-2.rennes.grid5000.fr' ]
11
+ @null_logger = Gosen::NullLogger.new
12
+ Gosen::NullLogger.stubs(:new).returns(@null_logger)
13
+ end
14
+
15
+ context 'without options' do
16
+ setup do
17
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes)
18
+ end
19
+
20
+ should 'have a reader on environment' do
21
+ assert_equal(@environment, @deployment.environment)
22
+ end
23
+
24
+ should 'have a reader on nodes' do
25
+ assert_equal(@nodes, @deployment.nodes)
26
+ end
27
+
28
+ should 'have a reader on site' do
29
+ assert_equal(@site, @deployment.site)
30
+ end
31
+
32
+ should 'have a reader on ssh_public_key' do
33
+ assert_equal(@ssh_public_key, @deployment.ssh_public_key)
34
+ end
35
+
36
+ should 'have a reader on logger defaulting to NullLogger' do
37
+ assert_equal(@null_logger, @deployment.logger)
38
+ end
39
+
40
+ should 'throw an error when accessing good_nodes' do
41
+ assert_raise(Gosen::Error) {
42
+ @deployment.good_nodes
43
+ }
44
+ end
45
+
46
+ should 'throw an error when accessing bad_nodes' do
47
+ assert_raise(Gosen::Error) {
48
+ @deployment.bad_nodes
49
+ }
50
+ end
51
+
52
+ should 'have a reader on min_deployed_nodes defaulting to 1' do
53
+ assert_equal(1, @deployment.min_deployed_nodes)
54
+ end
55
+
56
+ should 'have a reader on max_deploy_runs defaulting to 1' do
57
+ assert_equal(1, @deployment.max_deploy_runs)
58
+ end
59
+ end
60
+
61
+ context 'with options' do
62
+ should 'have a reader on ssh_public_key' do
63
+ @ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
64
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :ssh_public_key => @ssh_public_key })
65
+ assert_equal(@ssh_public_key, @deployment.ssh_public_key)
66
+ end
67
+
68
+ should 'have a reader on min_deployed_nodes' do
69
+ @min_deployed_nodes = @nodes.length
70
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => @min_deployed_nodes })
71
+ assert_equal(@min_deployed_nodes, @deployment.min_deployed_nodes)
72
+ end
73
+
74
+ should 'have a reader on logger' do
75
+ logger = mock()
76
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :logger => logger })
77
+ assert_equal(logger, @deployment.logger)
78
+ end
79
+
80
+ should 'throw an error if not enough nodes are available from the start' do
81
+ assert_raise(Gosen::Error) {
82
+ Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => @nodes.length + 1 })
83
+ }
84
+ end
85
+
86
+ should 'throw an error if min_deployed_nodes is negative' do
87
+ assert_raise(Gosen::Error) {
88
+ Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => -1 })
89
+ }
90
+ end
91
+
92
+ should 'have a reader on max_deploy_runs' do
93
+ @max_deploy_runs = 42
94
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :max_deploy_runs => @max_deploy_runs })
95
+ assert_equal(@max_deploy_runs, @deployment.max_deploy_runs)
96
+ end
97
+
98
+ should 'throw an error if max_deploy_runs is less than 1' do
99
+ assert_raise(Gosen::Error) {
100
+ Gosen::Deployment.new(@site, @environment, @nodes, { :max_deploy_runs => -1 })
101
+ }
102
+ assert_raise(Gosen::Error) {
103
+ Gosen::Deployment.new(@site, @environment, @nodes, { :max_deploy_runs => 0 })
104
+ }
105
+ assert_nothing_raised(Gosen::Error) {
106
+ Gosen::Deployment.new(@site, @environment, @nodes, { :max_deploy_runs => 1 })
107
+ }
108
+ end
109
+ end
110
+
111
+ context 'that is in progress' do
112
+ setup do
113
+ Kernel.stubs(:sleep).with(Gosen::DeploymentRun::POLLING_TIME)
114
+ @site_deployments = mock()
115
+ @site.stubs(:deployments).returns(@site_deployments)
116
+ @logger = mock()
117
+
118
+ @deployment_resource = mock()
119
+ @deployment_resource.stubs(:reload)
120
+ @deployment_resource.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
121
+ end
122
+
123
+ should 'submit a deployment run and wait for the result' do
124
+ @deployment_result = {
125
+ 'paramount-1.rennes.grid5000.fr' => { 'state' => 'OK' },
126
+ 'paramount-2.rennes.grid5000.fr' => { 'state' => 'OK' }
127
+ }
128
+ @deployment_resource.expects(:[]).with('result').returns(@deployment_result)
129
+ @site_deployments.expects(:submit).with({ :environment => @environment, :nodes => @nodes }).returns(@deployment_resource)
130
+ @min_deployed_nodes = 2
131
+ @logger.expects(:info).with("Kadeploy run 1 with #{@nodes.length} nodes (0 already deployed, need #{@min_deployed_nodes} more)")
132
+ @logger.expects(:info).with("Nodes deployed: paramount-1.rennes.grid5000.fr paramount-2.rennes.grid5000.fr")
133
+ @logger.expects(:info).with("Had to run 1 kadeploy runs, deployed #{@deployment_result.length} nodes")
134
+
135
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :logger => @logger, :min_deployed_nodes => @min_deployed_nodes })
136
+ @deployment.join
137
+ assert_equal(@nodes, @deployment.good_nodes)
138
+ assert_equal([], @deployment.bad_nodes)
139
+ end
140
+
141
+ should 'throw an error when not enough nodes are available after all runs are completed' do
142
+ @deployment_result = {
143
+ 'paramount-1.rennes.grid5000.fr' => { 'state' => 'OK' },
144
+ 'paramount-2.rennes.grid5000.fr' => { 'state' => 'KO' }
145
+ }
146
+ @deployment_resource.expects(:[]).with('result').returns(@deployment_result)
147
+ @site_deployments.expects(:submit).with({ :environment => @environment, :nodes => @nodes }).returns(@deployment_resource)
148
+
149
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => 2 })
150
+ assert_raise(Gosen::Error) {
151
+ @deployment.join
152
+ }
153
+ end
154
+
155
+ should 'submit new deployment runs when needed' do
156
+ @deployment_resource1 = mock()
157
+ @deployment_resource2 = mock()
158
+ @deployment_resource1.stubs(:reload)
159
+ @deployment_resource2.stubs(:reload)
160
+
161
+ @deployment_result1 = {
162
+ 'paramount-1.rennes.grid5000.fr' => { 'state' => 'OK' },
163
+ 'paramount-2.rennes.grid5000.fr' => { 'state' => 'KO' }
164
+ }
165
+ @deployment_result2 = {
166
+ 'paramount-2.rennes.grid5000.fr' => { 'state' => 'OK' }
167
+ }
168
+ @deployment_resource1.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
169
+ @deployment_resource2.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
170
+ @deployment_resource1.expects(:[]).with('result').returns(@deployment_result1)
171
+ @deployment_resource2.expects(:[]).with('result').returns(@deployment_result2)
172
+ @min_deployed_nodes = 2
173
+ @site_deployments.expects(:submit).with({ :environment => @environment, :nodes => @nodes }).returns(@deployment_resource1)
174
+ @site_deployments.expects(:submit).with({ :environment => @environment, :nodes => [ 'paramount-2.rennes.grid5000.fr'] }).returns(@deployment_resource2)
175
+ @logger.expects(:info).with("Kadeploy run 1 with 2 nodes (0 already deployed, need 2 more)")
176
+ @logger.expects(:info).with("Nodes deployed: paramount-1.rennes.grid5000.fr")
177
+ @logger.expects(:info).with("Nodes which failed: paramount-2.rennes.grid5000.fr")
178
+ @logger.expects(:info).with("Kadeploy run 2 with 1 nodes (1 already deployed, need 1 more)")
179
+ @logger.expects(:info).with("Nodes deployed: paramount-2.rennes.grid5000.fr")
180
+ @logger.expects(:info).with("Had to run 2 kadeploy runs, deployed 2 nodes")
181
+
182
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :logger => @logger, :min_deployed_nodes => @min_deployed_nodes, :max_deploy_runs => 2 })
183
+ @deployment.join
184
+ assert_equal(@nodes, @deployment.good_nodes)
185
+ assert_equal([], @deployment.bad_nodes)
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,91 @@
1
+ require 'helper'
2
+
3
+ class TestDeploymentRun < Test::Unit::TestCase
4
+ context 'A new deployment run instance' do
5
+ setup do
6
+ @resource = {
7
+ 'status' => 'processing'
8
+ }
9
+ @deployments = mock()
10
+ @deployments.expects(:submit).returns(@resource)
11
+ @site = stub(:deployments => @deployments)
12
+ @environment = 'lenny-x64-base'
13
+ @nodes = [ 'paramount-1.rennes.grid5000.fr' ]
14
+ end
15
+
16
+ context 'without options' do
17
+ setup do
18
+ @deployment = Gosen::DeploymentRun.new(@site, @environment, @nodes)
19
+ end
20
+
21
+ should 'have a reader on site' do
22
+ assert_equal(@site, @deployment.site)
23
+ end
24
+
25
+ should 'have a reader on environment' do
26
+ assert_equal(@environment, @deployment.environment)
27
+ end
28
+
29
+ should 'have a reader on nodes' do
30
+ assert_equal(@nodes, @deployment.nodes)
31
+ end
32
+
33
+ should 'return nil on ssh_public_key' do
34
+ assert_equal(nil, @deployment.ssh_public_key)
35
+ end
36
+
37
+ should 'throw an error when accessing good_nodes' do
38
+ assert_raise(Gosen::Error) {
39
+ @deployment.good_nodes
40
+ }
41
+ end
42
+
43
+ should 'throw an error when accessing bad_nodes' do
44
+ assert_raise(Gosen::Error) {
45
+ @deployment.bad_nodes
46
+ }
47
+ end
48
+ end
49
+
50
+ context 'with options' do
51
+ should 'have a reader on ssh_public_key' do
52
+ @ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
53
+ @deployment = Gosen::DeploymentRun.new(@site, @environment, @nodes, { :ssh_public_key => @ssh_public_key })
54
+ assert_equal(@ssh_public_key, @deployment.ssh_public_key)
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'A deployment run instance' do
60
+ setup do
61
+ @result = {
62
+ 'paramount-1.rennes.grid5000.fr' => {
63
+ 'last_cmd_stderr' => '',
64
+ 'ip' => '131.254.202.60',
65
+ 'last_cmd_exit_status' => 0,
66
+ 'state' => 'OK'
67
+ }
68
+ }
69
+ @resource = mock()
70
+ @resource.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
71
+ @resource.expects(:[]).with('result').returns(@result)
72
+ @resource.expects(:reload).twice
73
+ Kernel.expects(:sleep).with(Gosen::DeploymentRun::POLLING_TIME).twice
74
+
75
+ @deployments = mock()
76
+ @deployments.expects(:submit).returns(@resource)
77
+ @site = stub(:deployments => @deployments)
78
+ @environment = 'lenny-x64-base'
79
+ @nodes = [ 'paramount-1.rennes.grid5000.fr' ]
80
+ @deployment = Gosen::DeploymentRun.new(@site, @environment, @nodes)
81
+ end
82
+
83
+ should 'wait for deployment completion and give access to the results' do
84
+ assert_nothing_raised(Exception) {
85
+ @deployment.join
86
+ }
87
+ assert_equal(@nodes, @deployment.good_nodes)
88
+ assert_equal([], @deployment.bad_nodes)
89
+ end
90
+ end
91
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'shoulda'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'gosen'
9
+
10
+ class Test::Unit::TestCase
11
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class TestGosen < Test::Unit::TestCase
4
+ context 'A valid list of nodes' do
5
+ setup do
6
+ @nodes = [
7
+ 'grelon-1.nancy.grid5000.fr',
8
+ 'grelon-2.nancy.grid5000.fr',
9
+ 'paramount-1.rennes.grid5000.fr',
10
+ 'paramount-2.rennes.grid5000.fr'
11
+ ]
12
+ end
13
+
14
+ should 'be indexable by their site name' do
15
+ result = {
16
+ 'nancy' => [ 'grelon-1.nancy.grid5000.fr', 'grelon-2.nancy.grid5000.fr' ],
17
+ 'rennes' => [ 'paramount-1.rennes.grid5000.fr', 'paramount-2.rennes.grid5000.fr' ]
18
+ }
19
+ assert_equal(result, Gosen.index_nodes_by_site(@nodes))
20
+ end
21
+ end
22
+
23
+ context 'An invalid list of nodes' do
24
+ setup do
25
+ @nodes_lists = [
26
+ [ 'grelon' ],
27
+ [ 'grelon.' ],
28
+ [ 'grelon..grid5000.fr' ],
29
+ [ 'grelon.abc123.grid5000.fr' ],
30
+ [ 'grelon.nancy.grid50001.fr' ],
31
+ [ 'grelon.nancy.grid5000.de' ]
32
+ ]
33
+ end
34
+
35
+ should 'throw an error' do
36
+ @nodes_lists.each do |nodes|
37
+ assert_raise(Gosen::Error) { Gosen.index_nodes_by_site(nodes) }
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gosen
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Pierre Riteau
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-02 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: restfully
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 1
31
+ version: 0.5.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mocha
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 8
45
+ version: 0.9.8
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 10
58
+ - 2
59
+ version: 2.10.2
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ type: :development
73
+ version_requirements: *id004
74
+ description: Gosen is a Ruby library providing high-level operations using the Grid'5000 RESTful API, such as Kadeploy deployments
75
+ email: priteau@gmail.com
76
+ executables: []
77
+
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE
82
+ - README.md
83
+ files:
84
+ - .document
85
+ - .gitignore
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - VERSION
90
+ - lib/gosen.rb
91
+ - lib/gosen/deployment.rb
92
+ - lib/gosen/deployment_run.rb
93
+ - lib/gosen/error.rb
94
+ - test/gosen/test_deployment.rb
95
+ - test/gosen/test_deployment_run.rb
96
+ - test/helper.rb
97
+ - test/test_gosen.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/priteau/gosen
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.6
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: A Ruby library for the Grid'5000 RESTful API
128
+ test_files:
129
+ - test/gosen/test_deployment.rb
130
+ - test/gosen/test_deployment_run.rb
131
+ - test/helper.rb
132
+ - test/test_gosen.rb