Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com --- src/lib/job.cr | 22 ++++++++++++++++++++++ src/lib/sched.cr | 1 + 2 files changed, 23 insertions(+)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 53a560c..5008638 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -28,6 +28,19 @@ module JobHelper return tbox_group end
+ def self.match_host(testbox : String) + # "xxx-xxx-123" remove "-123" + find = testbox.match(/(.*)-\d+$/) + if testbox[0, 3] == "vm-" + # "vm-xxx-xxx--xxx" remove "--xxx" + # "vm-xxx-2xx-xxx" remove "-xxx" + find = testbox.match(/(.*)--.+$/) || + testbox.match(/(.*-\d\w*)-[a-zA-Z]+$/) || + find + end + find ? find[1] : testbox + end + def self.service_path(path) temp_path = File.real_path(path) return temp_path.split("/srv")[-1] @@ -161,6 +174,7 @@ class Job
private def set_result_root update_tbox_group_from_testbox # id must exists, need update tbox_group + update_host_from_testbox # id must exists, need update host date = Time.local.to_s("%F") self["result_root"] = "/result/#{suite}/#{tbox_group}/#{date}/#{id}"
@@ -186,6 +200,14 @@ class Job end end
+ # if not assign host, set it to a match result from testbox + # if job special host, should we just set host=host + private def update_host_from_testbox + if self["host"] == "" + @hash["host"] = JSON::Any.new(JobHelper.match_host(testbox)) + end + end + def [](key : String) : String "#{@hash[key]?}" end diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 15f5c9e..4e71959 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -226,6 +226,7 @@ class Sched # add to job content when multi-test job["testbox"] = tbox_group job.update_tbox_group(tbox_group) + job.update_host(tbox_group) job["node_roles"] = config["roles"].as_a.join(" ") job["node_macs"] = config["macs"].as_a.join(" ")