mobilize-ssh 1.0.55 → 1.0.65
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/lib/mobilize-ssh/handlers/ssh.rb +23 -15
- data/lib/mobilize-ssh/version.rb +1 -1
- data/test/mobilize-ssh_test.rb +20 -4
- data/test/ssh_job_rows.yml +14 -2
- metadata +1 -1
@@ -126,28 +126,36 @@ module Mobilize
|
|
126
126
|
return tmp_file_path
|
127
127
|
end
|
128
128
|
|
129
|
-
def Ssh.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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 =
|
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
|
data/lib/mobilize-ssh/version.rb
CHANGED
data/test/mobilize-ssh_test.rb
CHANGED
@@ -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
|
46
|
+
puts "job row added, force enqueued runner, wait 120s"
|
36
47
|
r.enqueue!
|
37
|
-
sleep
|
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
|
-
|
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
|
data/test/ssh_job_rows.yml
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
- name:
|
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)/
|
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"'
|