mobilize-ssh 1.0.55 → 1.0.65

Sign up to get free protection for your applications and to get access to all the features.
@@ -126,28 +126,36 @@ module Mobilize
126
126
  return tmp_file_path
127
127
  end
128
128
 
129
- def Ssh.get_file_hash(gsheet_paths,gdrive_slot)
130
- file_hash = {}
131
- gsheet_paths.map do |gpath|
132
- string = Gsheet.find_by_path(gpath,gdrive_slot).to_tsv
133
- fname = gpath.split("/").last
134
- {fname => string}
135
- end.each do |f|
136
- file_hash = f.merge(file_hash)
129
+ def Ssh.file_hash_by_task_path(task_path)
130
+ #this is not meant to be called directly
131
+ #from the Runner -- it's used by run_by_task_path
132
+ t = Task.where(:path=>task_path).first
133
+ params = t.params
134
+ gsheet_paths = if params['sources']
135
+ params['sources']
136
+ elsif params['source']
137
+ [params['source']]
138
+ end
139
+ if gsheet_paths and gsheet_paths.length>0
140
+ gdrive_slot = Gdrive.slot_worker_by_path(task_path)
141
+ file_hash = {}
142
+ gsheet_paths.map do |gpath|
143
+ string = Gsheet.find_by_path(gpath,gdrive_slot).to_tsv
144
+ fname = gpath.split("/").last
145
+ {fname => string}
146
+ end.each do |f|
147
+ file_hash = f.merge(file_hash)
148
+ end
149
+ Gdrive.unslot_worker_by_path(task_path)
150
+ return file_hash
137
151
  end
138
- file_hash
139
152
  end
140
153
 
141
154
  def Ssh.run_by_task_path(task_path)
142
155
  t = Task.where(:path=>task_path).first
143
156
  params = t.params
144
157
  node, command = [params['node'],params['cmd']]
145
- file_hash = if params['sources']
146
- gdrive_slot = Gdrive.slot_worker_by_path(task_path)
147
- result = Ssh.get_file_hash(params['sources'],gdrive_slot)
148
- Gdrive.unslot_worker_by_path(task_path)
149
- result
150
- end
158
+ file_hash = Ssh.file_hash_by_task_path(task_path)
151
159
  su_user = t.params['su_user']
152
160
  Ssh.run(node,command,file_hash,su_user)
153
161
  end
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Ssh
3
- VERSION = "1.0.55"
3
+ VERSION = "1.0.65"
4
4
  end
5
5
  end
@@ -18,6 +18,10 @@ describe "Mobilize" do
18
18
  u = Mobilize::User.where(:name=>user_name).first
19
19
  r = u.runner
20
20
 
21
+ rb_code_sheet = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/code.rb",gdrive_slot)
22
+ sh_code_sheet = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/code.sh",gdrive_slot)
23
+ [rb_code_sheet,sh_code_sheet].each {|s| s.delete if s}
24
+
21
25
  puts "add test code"
22
26
  rb_code_sheet = Mobilize::Gsheet.find_or_create_by_path("#{r.path.split("/")[0..-2].join("/")}/code.rb",gdrive_slot)
23
27
  rb_code_tsv = File.open("#{Mobilize::Base.root}/test/code.rb").read
@@ -29,20 +33,32 @@ describe "Mobilize" do
29
33
 
30
34
  jobs_sheet = r.gsheet(gdrive_slot)
31
35
 
36
+ #delete target sheets if they exist
37
+ ssh_target_sheet_1 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_1.out",gdrive_slot)
38
+ ssh_target_sheet_2 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_2.out",gdrive_slot)
39
+ ssh_target_sheet_3 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_3.out",gdrive_slot)
40
+ [ssh_target_sheet_1,ssh_target_sheet_2,ssh_target_sheet_3].each {|s| s.delete if s}
41
+
32
42
  ssh_job_rows = ::YAML.load_file("#{Mobilize::Base.root}/test/ssh_job_rows.yml")
43
+ ssh_job_rows.map{|j| r.jobs(j['name'])}.each{|j| j.delete if j}
33
44
  jobs_sheet.add_or_update_rows(ssh_job_rows)
34
45
 
35
- puts "job row added, force enqueued runner, wait 90s"
46
+ puts "job row added, force enqueued runner, wait 120s"
36
47
  r.enqueue!
37
- sleep 90
48
+ sleep 120
38
49
 
39
50
  puts "update job status and activity"
40
51
  r.update_gsheet(gdrive_slot)
41
52
 
42
53
  puts "jobtracker posted data to test sheet"
43
- ssh_target_sheet = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh.out",gdrive_slot)
54
+ ssh_target_sheet_1 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_1.out",gdrive_slot)
55
+ ssh_target_sheet_2 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_2.out",gdrive_slot)
56
+ ssh_target_sheet_3 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/test_ssh_3.out",gdrive_slot)
57
+
58
+ assert ssh_target_sheet_1.to_tsv.length > 100
59
+ assert ssh_target_sheet_2.to_tsv.length > 100
60
+ assert ssh_target_sheet_3.to_tsv.length > 3
44
61
 
45
- assert ssh_target_sheet.to_tsv.length > 100
46
62
  end
47
63
 
48
64
  end
@@ -1,6 +1,18 @@
1
- - name: test_ssh
1
+ - name: test_ssh_1
2
2
  active: true
3
3
  trigger: once
4
4
  status: ""
5
5
  task1: 'ssh.run node:"test_node", cmd:"ruby code.rb", su_user:"root", sources:["Runner_mobilize(test)/code.rb", "Runner_mobilize(test)/code.sh"]'
6
- task2: 'gsheet.write source:"task1", target:"Runner_mobilize(test)/test_ssh.out"'
6
+ task2: 'gsheet.write source:"task1", target:"Runner_mobilize(test)/test_ssh_1.out"'
7
+ - name: test_ssh_2
8
+ active: true
9
+ trigger: once
10
+ status: ""
11
+ task1: 'ssh.run node:"test_node", cmd:"sh code.sh", su_user:"root", source:"Runner_mobilize(test)/code.sh"'
12
+ task2: 'gsheet.write source:"task1", target:"Runner_mobilize(test)/test_ssh_2.out"'
13
+ - name: test_ssh_3
14
+ active: true
15
+ trigger: once
16
+ status: ""
17
+ task1: 'ssh.run node:"test_node", cmd:"whoami"'
18
+ task2: 'gsheet.write source:"task1", target:"Runner_mobilize(test)/test_ssh_3.out"'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilize-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.55
4
+ version: 1.0.65
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: