Before: Use access_key_file to limit job upload, need to create the file in upload dirs, that's not flexible enough.
After: Set $job_id => "$dir1,$dir2,..." in "id2upload_dirs" hash of the redis. The dir of job upload must be equal or deeper than one of "$dir1,$dir2,...".
Signed-off-by: Cao Xueliang caoxl78320@163.com --- src/lib/job.cr | 13 ++++--------- src/scheduler/close_job.cr | 6 ------ src/scheduler/find_job_boot.cr | 10 +++++----- 3 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 4bef329..cb187a4 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -83,8 +83,7 @@ class Job pp_params submit_date result_root - access_key - access_key_file + upload_dirs lkp_initrd_user user_lkp_src kernel_uri @@ -206,15 +205,11 @@ class Job def set_result_root update_tbox_group_from_testbox # id must exists, need update tbox_group self["result_root"] = File.join("/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}", "#{pp_params}", "#{id}") - - # access_key has information based on "result_root" - # so when set result_root, we need redo set_ to update it - set_access_key() + set_upload_dirs() end
- private def set_access_key - self["access_key"] = "#{Random::Secure.hex(10)}-#{id}" - self["access_key_file"] = File.join("/srv/", "#{result_root}", ".#{access_key}") + def set_upload_dirs + self["upload_dirs"] = "#{result_root}" end
private def set_result_service diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr index d071d69..b5aaa63 100644 --- a/src/scheduler/close_job.cr +++ b/src/scheduler/close_job.cr @@ -5,8 +5,6 @@ class Sched def close_job(job_id : String) job = @redis.get_job(job_id)
- delete_access_key_file(job) if job - response = @es.set_job_content(job) if response["_id"] == nil # es update fail, raise exception @@ -24,8 +22,4 @@ class Sched
return %({"job_id": "#{job_id}", "job_state": "complete"}) end - - def delete_access_key_file(job : Job) - File.delete(job.access_key_file) if File.exists?(job.access_key_file) - end end diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr index b5a23c5..968b9ed 100644 --- a/src/scheduler/find_job_boot.cr +++ b/src/scheduler/find_job_boot.cr @@ -128,10 +128,6 @@ class Sched return response end
- def touch_access_key_file(job : Job) - FileUtils.touch(job.access_key_file) - end - private def get_boot_ipxe(job : Job) response = "#!ipxe\n\n" response += job.initrds_uri @@ -142,8 +138,12 @@ class Sched return response end
+ def set_id2upload_dirs(job) + @redis.hash_set("sched/id2upload_dirs",job.id, job.upload_dirs) + end + def boot_content(job : Job | Nil, boot_type : String) - touch_access_key_file(job) if job + set_id2upload_dirs(job) if job
case boot_type when "ipxe"
Pls ignore this patch
Thanks, Xueliang
On Mon, Nov 23, 2020 at 04:00:02PM +0800, Cao Xueliang wrote:
Before: Use access_key_file to limit job upload, need to create the file in upload dirs, that's not flexible enough.
After: Set $job_id => "$dir1,$dir2,..." in "id2upload_dirs" hash of the redis. The dir of job upload must be equal or deeper than one of "$dir1,$dir2,...".
Signed-off-by: Cao Xueliang caoxl78320@163.com
src/lib/job.cr | 13 ++++--------- src/scheduler/close_job.cr | 6 ------ src/scheduler/find_job_boot.cr | 10 +++++----- 3 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 4bef329..cb187a4 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -83,8 +83,7 @@ class Job pp_params submit_date result_root
- access_key
- access_key_file
- upload_dirs lkp_initrd_user user_lkp_src kernel_uri
@@ -206,15 +205,11 @@ class Job def set_result_root update_tbox_group_from_testbox # id must exists, need update tbox_group self["result_root"] = File.join("/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}", "#{pp_params}", "#{id}")
- # access_key has information based on "result_root"
- # so when set result_root, we need redo set_ to update it
- set_access_key()
- set_upload_dirs() end
- private def set_access_key
- self["access_key"] = "#{Random::Secure.hex(10)}-#{id}"
- self["access_key_file"] = File.join("/srv/", "#{result_root}", ".#{access_key}")
def set_upload_dirs
self["upload_dirs"] = "#{result_root}" end
private def set_result_service
diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr index d071d69..b5aaa63 100644 --- a/src/scheduler/close_job.cr +++ b/src/scheduler/close_job.cr @@ -5,8 +5,6 @@ class Sched def close_job(job_id : String) job = @redis.get_job(job_id)
- delete_access_key_file(job) if job
- response = @es.set_job_content(job) if response["_id"] == nil # es update fail, raise exception
@@ -24,8 +22,4 @@ class Sched
return %({"job_id": "#{job_id}", "job_state": "complete"})
end
- def delete_access_key_file(job : Job)
- File.delete(job.access_key_file) if File.exists?(job.access_key_file)
- end
end diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr index b5a23c5..968b9ed 100644 --- a/src/scheduler/find_job_boot.cr +++ b/src/scheduler/find_job_boot.cr @@ -128,10 +128,6 @@ class Sched return response end
- def touch_access_key_file(job : Job)
- FileUtils.touch(job.access_key_file)
- end
- private def get_boot_ipxe(job : Job) response = "#!ipxe\n\n" response += job.initrds_uri
@@ -142,8 +138,12 @@ class Sched return response end
- def set_id2upload_dirs(job)
- @redis.hash_set("sched/id2upload_dirs",job.id, job.upload_dirs)
- end
- def boot_content(job : Job | Nil, boot_type : String)
- touch_access_key_file(job) if job
set_id2upload_dirs(job) if job
case boot_type when "ipxe"
-- 2.23.0