ruby-cute 0.0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 134cb9d25b87efcffb16969273bc4485b79a6086
4
- data.tar.gz: b2454f6b7878e1e7339bcfd412dd52e431e17f08
3
+ metadata.gz: f54b6b52751a03c02f575ef8e544f399df99229a
4
+ data.tar.gz: e2db4b6d5a93a21ec4d19cf238ec05606ee6ab97
5
5
  SHA512:
6
- metadata.gz: 5e73cc26463f9eafe501ba6b01f9439dcb7cb6874ee35c8ea3692797dcb75f1a73fbef9adce8df8d2ea410267a6be34a3852f968d84db9ae19b5cf3c58a444f5
7
- data.tar.gz: d5d5bf2fa5c5d0d99944bbe010fa6456356571487be772b4f9246213a5ade9d21f60ae29b3b4813091b94529c9ef1b5c44de948512c15fac2a7bdf086339ba79
6
+ metadata.gz: 8a6a3d01f0eb79fa5d66955467529b92bd53add1f597bf88df283f388e53751f2e46980b55a0398f350671b02ae7b68d8f00409fd22defd91dccd9220c2a2e4e
7
+ data.tar.gz: c4e54ceadd5e0aa271438b195942da1e4cc38bfe97d02db0394d787347c3f6a41be821d173e7cf6c83db2a7caa5b34cbe3d1141d58f6b2cde547a2f3c4f389e7
data/README.md CHANGED
@@ -141,11 +141,14 @@ g5k.release(job) # Frees resources.
141
141
 
142
142
  Ruby-Cute is maintained by the Algorille team at LORIA/Inria Nancy - Grand Est, and specifically by:
143
143
 
144
- * Sébastien Badia <sebastien.badia@inria.fr>
145
- * Tomasz Buchert <tomasz.buchert@inria.fr>
144
+ * Cristian Ruiz <cristian.ruiz@inria.fr>
146
145
  * Emmanuel Jeanvoine <emmanuel.jeanvoine@inria.fr>
147
146
  * Lucas Nussbaum <lucas.nussbaum@loria.fr>
147
+
148
+ Past contributors include:
149
+
150
+ * Sébastien Badia <sebastien.badia@inria.fr>
151
+ * Tomasz Buchert <tomasz.buchert@inria.fr>
148
152
  * Luc Sarzyniec <luc.sarzyniec@inria.fr>
149
- * Cristian Ruiz <cristian.ruiz@inria.fr>
150
153
 
151
154
  Questions/comments should be directed to Lucas Nussbaum and Emmanuel Jeanvoine.
@@ -1,5 +1,5 @@
1
- ruby-cute (0.0.1) UNRELEASED; urgency=low
1
+ ruby-cute (0.3) UNRELEASED; urgency=medium
2
2
 
3
- * Initial release, as a native package for now.
3
+ * Initial release.
4
4
 
5
- -- Lucas Nussbaum <lucas@debian.org> Wed, 13 Mar 2013 10:47:08 +0100
5
+ -- Lucas Nussbaum <lucas@debian.org> Tue, 10 Mar 2015 15:13:52 +0100
@@ -2,14 +2,18 @@ Source: ruby-cute
2
2
  Section: ruby
3
3
  Priority: optional
4
4
  Maintainer: Lucas Nussbaum <lucas@debian.org>
5
- Build-Depends: debhelper (>= 8~), gem2deb (>= 0.3.0~), rake, yard, ruby-redcloth, bc
6
- Standards-Version: 3.9.3
7
- Homepage: http://ruby-cute.gforge.inria.fr/
5
+ Build-Depends: debhelper (>= 7.0.50~), gem2deb, ruby-rspec, rake, yard, ruby-webmock, ruby-simplecov, ruby-rest-client, ruby-ipaddress, ruby-net-ssh-multi
6
+ Standards-Version: 3.9.5
7
+ Vcs-Git: git://github.com/ruby-cute/ruby-cute
8
+ Vcs-Browser: https://github.com/ruby-cute/ruby-cute
9
+ Homepage: http://ruby-cute.github.io/
10
+ Testsuite: autopkgtest
8
11
  XS-Ruby-Versions: all
9
12
 
10
13
  Package: ruby-cute
11
14
  Architecture: all
12
15
  XB-Ruby-Versions: ${ruby:Versions}
13
- Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter
16
+ Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, ruby-rest-client, ruby-json, ruby-ipaddress, ruby-net-ssh-multi
17
+ Recommends: pry
14
18
  Description: Critically Useful Tools for Experiments
15
-
19
+ Ruby library for controlling experiments
@@ -5,6 +5,13 @@ Source: FIXME <http://example.com/>
5
5
  Files: *
6
6
  Copyright: <years> <put author's name and email here>
7
7
  <years> <likewise for another author>
8
+ License: GPL-2+ (FIXME)
9
+
10
+ Files: debian/*
11
+ Copyright: 2015 Lucas Nussbaum <lucas@debian.org>
12
+ License: GPL-2+ (FIXME)
13
+ Comment: the Debian packaging is licensed under the same terms as the original package.
14
+
8
15
  License: GPL-2+ (FIXME)
9
16
  This program is free software; you can redistribute it
10
17
  and/or modify it under the terms of the GNU General Public
@@ -26,8 +33,3 @@ License: GPL-2+ (FIXME)
26
33
  On Debian systems, the full text of the GNU General Public
27
34
  License version 2 can be found in the file
28
35
  `/usr/share/common-licenses/GPL-2'.
29
-
30
- Files: debian/*
31
- Copyright: 2013 Lucas Nussbaum <lucas@debian.org>
32
- License:
33
- [LICENSE TEXT]
@@ -0,0 +1 @@
1
+ examples/*
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec) do |spec|
4
+ spec.pattern = './spec/*_spec.rb'
5
+ end
6
+
7
+ task :default => :spec
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # Uncomment to ignore some test failures (but the tests will run anyway).
8
8
  # Valid values:
9
- #export DH_RUBY_IGNORE_TESTS=ruby1.8 ruby1.9.1 require-rubygems
9
+ #export DH_RUBY_IGNORE_TESTS=ruby2.1 require-rubygems
10
10
  #
11
11
  # If you need to specify the .gemspec (eg there is more than one)
12
12
  #export DH_RUBY_GEMSPEC=gem.gemspec
@@ -26,7 +26,8 @@ G5K_SITES.each{ |site|
26
26
  # here, we set wait_time to 200 seconds, like that we would just use the sites that are free.
27
27
  begin
28
28
  jobs[site] = g5k.reserve(:site => site, :resources => "slash_22=1+{virtual!='none'}/nodes=1",
29
- :walltime =>"01:00:00",:keys => "~/.ssh/id_rsa", :wait_time => 200)
29
+ :walltime =>"01:00:00",:keys => "~/.ssh/id_rsa", :wait => false)
30
+ jobs[site] = g5k.wait_for_job(jobs[site], :wait_time => 200)
30
31
  rescue Cute::G5K::EventTimeout
31
32
  puts "We waited long enough, releasing job in site #{site}"
32
33
  g5k.release(jobs[site]) # we release the job
@@ -40,6 +41,11 @@ G5K_SITES.each{ |site|
40
41
 
41
42
  threads.each{ |t| t.join}
42
43
 
44
+ if jobs.keys.empty? then
45
+ puts "no sites available"
46
+ exit
47
+ end
48
+
43
49
  nodes = []
44
50
  jobs.each{ |k,v| nodes+=v["assigned_nodes"]}
45
51
 
@@ -54,7 +60,7 @@ template = ERB.new(File.read("#{vm_dir}/vm-template.xml"))
54
60
 
55
61
  vms = []
56
62
 
57
- G5K_SITES.each{ |site|
63
+ jobs.keys.each{ |site|
58
64
  subnet = g5k.get_subnets(jobs[site]).first
59
65
  ips = subnet.map{ |ip| ip.to_s }
60
66
  num_vm.times{ |n|
@@ -114,7 +120,7 @@ Net::SSH::Multi.start do |session|
114
120
  end
115
121
 
116
122
  puts("Waiting for the machines to start")
117
- sleep 60
123
+ sleep 100
118
124
 
119
125
  # Executing some commands on the vms
120
126
 
@@ -703,7 +703,11 @@ module Cute
703
703
  # @return [Array] all the subnets defined in a given job
704
704
  # @param job [G5KJSON] as described in {Cute::G5K::G5KJSON job}
705
705
  def get_subnets(job)
706
- subnets = job.resources["subnets"]
706
+ if job.resources["subnets"].nil?
707
+ return nil
708
+ else
709
+ subnets = job.resources["subnets"]
710
+ end
707
711
  subnets.map{|s| IPAddress::IPv4.new s }
708
712
  end
709
713
 
@@ -725,6 +729,7 @@ module Cute
725
729
  # Releases all jobs on a site
726
730
  # @param site [String] a valid Grid'5000 site name
727
731
  def release_all(site)
732
+ raise ArgumentError, "parameter should be a string" unless site.is_a?(String)
728
733
  Timeout.timeout(20) do
729
734
  jobs = get_my_jobs(site,"running") + get_my_jobs(site,"waiting")
730
735
  break if jobs.empty?
@@ -738,9 +743,11 @@ module Cute
738
743
  end
739
744
 
740
745
  # Releases a resource, it can be a job or a deploy.
741
- def release(r)
746
+ # @param resource [G5KJSON] as described in {Cute::G5K::G5KJSON job}
747
+ def release(resource)
748
+ raise ArgumentError, "parameter should be a G5KJSON data type" unless resource.is_a?(Cute::G5K::G5KJSON)
742
749
  begin
743
- return @g5k_connection.delete_json(r.rel_self)
750
+ return @g5k_connection.delete_json(resource.rel_self)
744
751
  rescue Cute::G5K::RequestFailed => e
745
752
  raise unless e.response.include?('already killed')
746
753
  end
@@ -1,3 +1,3 @@
1
1
  module Cute
2
- VERSION = "0.0.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency "pry", "~> 0.10"
22
22
  s.add_development_dependency "webmock", "~> 1.20"
23
23
  s.add_development_dependency "yard", "~> 0.8"
24
+ s.add_development_dependency "simplecov", "~> 0.7"
24
25
 
25
26
  s.add_dependency 'rest-client', '1.6.7'
26
27
  s.add_dependency 'json', '~> 1.8'
@@ -112,8 +112,21 @@ describe Cute::G5K::API do
112
112
  expect(subject.get_vlan_nodes(job)).to be_nil
113
113
  end
114
114
 
115
+ it "subnet returns nil" do
116
+ job = Cute::G5K::G5KJSON.new
117
+ expect(subject.get_subnets(job)).to be_nil
118
+ end
119
+
120
+ it "raises an argument error in release method" do
121
+ expect{subject.release("string")}.to raise_error(ArgumentError)
122
+ end
123
+
124
+ it "raises an argument error in release_all method" do
125
+ expect{subject.release_all(["random"])}.to raise_error(ArgumentError)
126
+ end
127
+
115
128
  it "performs an advanced reservation" do
116
- time_schedule = Time.now + 60*30
129
+ time_schedule = Time.now + 60*20
117
130
  job =subject.reserve(:site => @rand_site, :nodes => 1, :reservation => time_schedule.strftime("%Y-%m-%d %H:%M:%S"))
118
131
  subject.release(job)
119
132
  end
@@ -0,0 +1,243 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'cute'
5
+
6
+ class Execute_test < Test::Unit::TestCase
7
+
8
+ def prepare_file()
9
+ @file = Tempfile.new("testons")
10
+ 1.upto(100) {|i| @file.puts i}
11
+ @file.close()
12
+ @cmd=['cat',@file.path]
13
+ @cmd2=['bash','-c',"cat #{@file.path} >&2"]
14
+ end
15
+ def test_execute()
16
+ prepare_file()
17
+ run = Cute::Execute[*@cmd].run!()
18
+ res = run.wait()
19
+ file = File.read(@file.path)
20
+ assert_equal(file,run.stdout)
21
+ assert(run.emptypipes,"pipes are empty")
22
+ assert(res[3],"pipes are empty")
23
+ end
24
+ def test_execute2()
25
+ prepare_file()
26
+ run = Cute::Execute[*@cmd].run!()
27
+ res = run.wait()
28
+ file = File.read(@file.path)
29
+ assert_equal(file,res[1])
30
+ assert(res[3],"pipes are empty")
31
+ end
32
+ def test_execute_err()
33
+ prepare_file()
34
+ run = Cute::Execute[*@cmd2].run!()
35
+ run.wait()
36
+ file = File.read(@file.path)
37
+ assert_equal(file,run.stderr)
38
+ assert(run.emptypipes,"pipes are empty")
39
+ end
40
+ def test_execute2_err()
41
+ prepare_file()
42
+ run = Cute::Execute[*@cmd2].run!()
43
+ res = run.wait()
44
+ file = File.read(@file.path)
45
+ assert_equal(file,res[2])
46
+ assert(res[3],"pipes are empty")
47
+ end
48
+ def test_execute_limit_stdout()
49
+ prepare_file()
50
+ run = Cute::Execute[*@cmd].run!(:stdout_size=>5)
51
+ run.wait()
52
+ assert_equal("1\n2\n3",run.stdout)
53
+ assert(!run.emptypipes,"pipes are not empty")
54
+ end
55
+ def test_execute_limit_stderr()
56
+ prepare_file()
57
+ run = Cute::Execute[*@cmd2].run!(:stderr_size=>5)
58
+ run.wait()
59
+ assert_equal("1\n2\n3",run.stderr)
60
+ assert(!run.emptypipes,"pipes are not empty")
61
+ end
62
+ def test_stdin()
63
+ run = Cute::Execute['ruby'].run!({:stdin=>true})
64
+ run.write_stdin('puts 2+2*2;puts Math.cos(Math::PI)')
65
+ run.wait()
66
+ assert_equal("6\n-1.0\n",run.stdout)
67
+ end
68
+ def test_signaled()
69
+ run = Cute::Execute["sleep","10"].run!()
70
+ sleep(0.2)
71
+ Process.kill("SIGKILL",run.exec_pid)
72
+ assert_raise(SignalException) do
73
+ run.wait()
74
+ end
75
+ end
76
+ def test_signaled_multithread()
77
+ run = Cute::Execute["sleep","10"].run!()
78
+ sleep(0.2)
79
+ Process.kill("SIGKILL",run.exec_pid)
80
+ t1 = Thread.new do
81
+ assert_raise(SignalException) do
82
+ run.wait()
83
+ end
84
+ end
85
+ t2 = Thread.new do
86
+ assert_raise(SignalException) do
87
+ run.wait()
88
+ end
89
+ end
90
+ t1.join
91
+ t2.join
92
+ end
93
+ # def test_non_null_exit
94
+ # run = Cute::Execute["ls","/zoefkzoifjauifhiagier"].run!()
95
+ # assert_raise(Exception) do
96
+ # run.wait()
97
+ # end
98
+ # assert_equal(2,run.status.exitstatus)
99
+ # end
100
+ def test_non_null_exit_ignored
101
+ run = Cute::Execute["ls","/zoefkzoifjauifhiagier"].run!()
102
+ assert_nothing_raised do
103
+ run.wait({})
104
+ end
105
+ assert_equal(2,run.status.exitstatus)
106
+ end
107
+ def test_non_null_exit_multithread
108
+ run = Cute::Execute["ls","/zoefkzoifjauifhiagier"].run!()
109
+ t1 = Thread.new do
110
+ assert_raise(RuntimeError) do
111
+ run.wait()
112
+ end
113
+ end
114
+ t2 = Thread.new do
115
+ assert_raise(RuntimeError) do
116
+ run.wait()
117
+ end
118
+ end
119
+ t1.join
120
+ t2.join
121
+ assert_equal(2,run.status.exitstatus)
122
+ end
123
+ def test_kill()
124
+ run = Cute::Execute["sleep","3"].run!()
125
+ run.kill
126
+ assert_nothing_raised(SignalException) do
127
+ run.wait()
128
+ end
129
+ assert(run.status.signaled?,"The process must be killed")
130
+ end
131
+ def test_kill2()
132
+ run = Cute::Execute["sleep","3"].run!()
133
+ run.kill
134
+ res = nil
135
+ assert_nothing_raised(SignalException) do
136
+ res = run.wait()
137
+ end
138
+ assert(res[0].signaled?,"The process must be killed")
139
+ end
140
+
141
+ def test_kill_multithread()
142
+ run = Cute::Execute["sleep","3"].run!()
143
+ t1 = Thread.new do
144
+ assert_nothing_raised(SignalException) do
145
+ run.wait()
146
+ end
147
+ end
148
+ t2 = Thread.new do
149
+ assert_nothing_raised(SignalException) do
150
+ run.wait()
151
+ end
152
+ end
153
+ run.kill
154
+ t1.join
155
+ t2.join
156
+ assert(run.status.signaled?,"The process must be killed")
157
+ end
158
+ def test_stderr_after_kill()
159
+ run = Cute::Execute["bash","-c","echo toto >&2;sleep 5"].run!()
160
+ t1 = Thread.new do
161
+ assert_nothing_raised(SignalException) do
162
+ run.wait()
163
+ end
164
+ end
165
+ sleep(0.2)
166
+ t1.kill
167
+ assert_nothing_raised(SignalException) do
168
+ t1.join
169
+ end
170
+ assert_equal("toto\n",run.stderr)
171
+ assert(run.status.signaled?,"The process must be killed")
172
+ end
173
+ def test_output_after_kill()
174
+ run = Cute::Execute["bash","-c","echo toto;sleep 5"].run!()
175
+ t1 = Thread.new do
176
+ assert_nothing_raised(SignalException) do
177
+ run.wait()
178
+ end
179
+ end
180
+ sleep(0.2)
181
+ t1.kill
182
+ assert_nothing_raised(SignalException) do
183
+ t1.join
184
+ end
185
+ assert_equal("toto\n",run.stdout)
186
+ assert(run.status.signaled?,"The process must be killed")
187
+ end
188
+ def test_kill_thread()
189
+ run = Cute::Execute["sleep","3"].run!()
190
+ t1 = Thread.new do
191
+ assert_nothing_raised(SignalException) do
192
+ run.wait()
193
+ end
194
+ end
195
+ sleep(0.2)
196
+ t1.kill()
197
+ assert_nothing_raised(SignalException) do
198
+ t1.join()
199
+ end
200
+ assert(run.status.signaled?,"The process must be killed")
201
+ end
202
+
203
+ def test_kill_thread_multithread()
204
+ run = Cute::Execute["sleep","3"].run!()
205
+ t1 = Thread.new do
206
+ assert_nothing_raised(SignalException) do
207
+ run.wait()
208
+ end
209
+ end
210
+ t2 = Thread.new do
211
+ assert_nothing_raised(SignalException) do
212
+ run.wait()
213
+ end
214
+ end
215
+ sleep(0.2)
216
+ t1.kill()
217
+ assert_nothing_raised(SignalException) do
218
+ t1.join()
219
+ end
220
+ t2.join()
221
+ assert(run.status.signaled?,"The process must be killed")
222
+ end
223
+ def test_nopipe
224
+ run = Cute::Execute["sleep","100"].run!(:stdout=>false,:stderr=>false,:stdin=>false)
225
+ sleep(0.2) #wait for fork finish the job
226
+ assert_equal("/dev/null",File.readlink("/proc/#{run.exec_pid}/fd/0"),"fd0")
227
+ assert_equal("/dev/null",File.readlink("/proc/#{run.exec_pid}/fd/1"),"fd1")
228
+ assert_equal("/dev/null",File.readlink("/proc/#{run.exec_pid}/fd/2"),"fd2")
229
+ run.kill()
230
+ run.wait()
231
+ end
232
+ def test_fd_leak
233
+ fd=File.open("/dev/urandom")
234
+ file=Tempfile.new("testpipeleak")
235
+ file.puts("#!/usr/bin/env ruby")
236
+ file.puts("exit(IO.new(#{fd.fileno}).closed? ? 0 : 10) rescue Exception")
237
+ file.close()
238
+ assert_nothing_raised do
239
+ Cute::Execute['ruby',file.path].run!().wait()
240
+ end
241
+ fd.close()
242
+ end
243
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-cute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algorille team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rest-client
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,8 @@ files:
171
185
  - debian/control
172
186
  - debian/copyright
173
187
  - debian/ruby-cute.docs
174
- - debian/ruby-tests.rb
188
+ - debian/ruby-cute.examples
189
+ - debian/ruby-tests.rake
175
190
  - debian/rules
176
191
  - debian/source/format
177
192
  - debian/watch
@@ -195,6 +210,7 @@ files:
195
210
  - spec/spec_helper.rb
196
211
  - spec/taktuk_spec.rb
197
212
  - test/test_bash.rb
213
+ - test/test_execute.rb
198
214
  homepage: http://ruby-cute.gforge.inria.fr/
199
215
  licenses:
200
216
  - CeCILL-B
@@ -225,4 +241,5 @@ test_files:
225
241
  - spec/spec_helper.rb
226
242
  - spec/taktuk_spec.rb
227
243
  - test/test_bash.rb
244
+ - test/test_execute.rb
228
245
  has_rdoc:
@@ -1,2 +0,0 @@
1
- $: << 'lib' << '.'
2
- Dir['{spec,test}/**/*.rb'].each { |f| require f }