We need to create the access_key in the dir which we want to upload file, it is hard to handle that. So we save the upload_dirs in redis, then we can set the field in scheduler, the result-webdav container will read the value by job id and check the upload dir.
Signed-off-by: Cao Xueliang caoxl78320@163.com --- src/lib/job.cr | 23 ++++++++++++++--------- src/scheduler/close_job.cr | 6 ------ src/scheduler/find_job_boot.cr | 10 +++++----- 3 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 0083a7d..083a233 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -88,8 +88,7 @@ class Job pp_params submit_date result_root - access_key - access_key_file + upload_dirs lkp_initrd_user user_lkp_src kernel_uri @@ -243,15 +242,21 @@ 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 + if @hash["cci-makepkg"]? + package_dir = ",/initrd/pkg" + elsif @hash["cci-depends"]? + package_dir = ",/initrd/deps" + elsif @hash["build-pkg"]? + package_dir = ",/initrd/build-pkg" + else + package_dir = "" + end + + self["upload_dirs"] = "#{result_root}#{package_dir}" end
private def set_result_service diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr index 579c2c0..d8f80d7 100644 --- a/src/scheduler/close_job.cr +++ b/src/scheduler/close_job.cr @@ -8,8 +8,6 @@ class Sched
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 @@ -27,8 +25,4 @@ class Sched
@log.info(%({"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 5a11523..6623a5e 100644 --- a/src/scheduler/find_job_boot.cr +++ b/src/scheduler/find_job_boot.cr @@ -141,10 +141,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 += Array(String).from_json(job.initrds_uri).join("\n") + "\n" @@ -155,8 +151,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"