On Sat, Nov 14, 2020 at 11:08:16AM +0800, Cao Xueliang wrote:
The new result root dir: /srv/result/$suite/$submit_date/$tbox_group/$rootfs/$pp_params/$job_id
Example: rootfs: openeuler-20.09-aarch64 ($os-$os_version-$os_aarch) pp_params: socket-process-50 (use "-" connect pp's value up to 40 size)
Signed-off-by: Cao Xueliang caoxl78320@163.com
src/lib/job.cr | 22 ++++++++++++-- src/scheduler/pp_params.cr | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/scheduler/pp_params.cr
diff --git a/src/lib/job.cr b/src/lib/job.cr index be0fdbb..f723100 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -8,6 +8,7 @@ require "any_merge" require "scheduler/constants.cr" require "scheduler/jobfile_operate.cr" require "scheduler/kernel_params.cr" +require "scheduler/pp_params.cr"
struct JSON::Any def []=(key : String, value : String) @@ -78,6 +79,9 @@ class Job initrd_pkg initrd_deps initrds_uri
- rootfs
- pp_params
- submit_date result_root access_key access_key_file
@@ -135,6 +139,9 @@ class Job append_init_field() set_user_lkp_src() set_os_dir()
- set_submit_date()
- set_pp_params()
- set_rootfs() set_result_root() set_result_service() set_os_mount()
@@ -188,10 +195,21 @@ class Job self["os_dir"] = "#{os}/#{os_arch}/#{os_version}" end
- private def set_submit_date
- self["submit_date"] = Time.local.to_s("%F")
- end
- private def set_rootfs
- self["rootfs"] = "#{os}-#{os_version}-#{os_arch}"
- end
- def set_result_root update_tbox_group_from_testbox # id must exists, need update tbox_group
- date = Time.local.to_s("%F")
- self["result_root"] = "/result/#{suite}/#{tbox_group}/#{date}/#{id}"
- if pp_params != ""
self["result_root"] = "/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}/#{pp_params}/#{id}"
- else
self["result_root"] = "/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}/#{id}"
- end
maybe can use:
self["result_root"] = File.join("/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}", pp_params, "#{id}"
even if pp_params == "", it still work well.
Thanks, Kaiyi
# access_key has information based on "result_root" # so when set result_root, we need redo set_ to update it
diff --git a/src/scheduler/pp_params.cr b/src/scheduler/pp_params.cr new file mode 100644 index 0000000..28ec6ef --- /dev/null +++ b/src/scheduler/pp_params.cr @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+class Job
- private def set_pp_params
- temp_hash = Hash(String, JSON::Any).new
- if @hash["pp"]
flat_hash(@hash["pp"].as_h, temp_hash)
- end
- self["pp_params"] = sort_keys_return_values(temp_hash)
- end
- private def flat_hash(old_hash, new_hash)
- old_hash.each do |key1, value1|
if value1.as_h?
next if value1.as_h.empty?
temp_hash = Hash(String, JSON::Any).new
value1.as_h.each do |key2, value2|
temp_hash.merge!({"#{key1}-#{key2}" => value2})
end
flat_hash(temp_hash, new_hash)
else
new_hash.merge!({key1 => value1})
end
- end
- end
- private def sort_keys_return_values(hash)
- values = [] of String
- items_size = 0
- hash.keys.sort.each do |key|
value = format_string(hash[key].to_s)
next if 0 == value.size
if 40 > value.size + items_size + values.size
values << value
items_size += value.size
else
break
end
- end
- return values.join("-")
- end
- private def format_string(original_str)
- temp = [] of String
- original_str.each_char do |char|
if "#{char}" =~ /-|\w/
temp << "#{char}"
end
- end
- return temp.join()
- end
+end
2.23.0