We add the testbox env use the submit script in lkp-tests,
but the submit don't need to do that,
so, we add the testbox env in scheduler.
Signed-off-by: Cao Xueliang <caoxl78320(a)163.com>
---
src/lib/job.cr | 2 ++
src/scheduler/testbox_env.cr | 33 +++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
create mode 100644 src/scheduler/testbox_env.cr
diff --git a/src/lib/job.cr b/src/lib/job.cr
index 1afc22f..c3eeaf4 100644
--- a/src/lib/job.cr
+++ b/src/lib/job.cr
@@ -9,6 +9,7 @@ require "scheduler/constants.cr"
require "scheduler/jobfile_operate.cr"
require "scheduler/kernel_params.cr"
require "scheduler/pp_params.cr"
+require "scheduler/testbox_env.cr"
require "../scheduler/elasticsearch_client"
require "./json_logger"
@@ -52,6 +53,7 @@ class Job
def initialize(job_content : JSON::Any, id)
@hash = job_content.as_h
+ @hash.merge!(testbox_env)
@es = Elasticsearch::Client.new
@account_info = Hash(String, JSON::Any).new
@log = JSONLogger.new
diff --git a/src/scheduler/testbox_env.cr b/src/scheduler/testbox_env.cr
new file mode 100644
index 0000000..bf8cd8a
--- /dev/null
+++ b/src/scheduler/testbox_env.cr
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: MulanPSL-2.0+
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+
+class Job
+ def get_service_env
+ hash = Hash(String, JSON::Any).new
+ yaml_any = File.open("/etc/compass-ci/service/service-env.yaml") do |content|
+ YAML.parse(content).as_h?
+ end
+ return hash unless yaml_any
+
+ return Hash(String, JSON::Any).from_json(yaml_any.to_json)
+ end
+
+ def testbox_env(flag = "local")
+ service_env = get_service_env
+ hash = Hash(String, JSON::Any).new
+
+ yaml_any = File.open("/etc/compass-ci/scheduler/#{flag}-testbox-env.yaml") do |content|
+ YAML.parse(content).as_h?
+ end
+ return hash unless yaml_any
+
+ hash.merge!(Hash(String, JSON::Any).from_json(yaml_any.to_json))
+ hash.each do |key, value|
+ if value == nil
+ hash[key] = service_env[key]
+ end
+ end
+
+ hash
+ end
+end
--
2.23.0