The function get_boot_ipxe use initrds_path, kernel, kernel_params from
job class as response.
Signed-off-by: Cao Xueliang <caoxl78320(a)163.com>
---
src/lib/job.cr | 120 +++++++++++++++++++++++++++++++++----
src/lib/sched.cr | 65 ++------------------
src/scheduler/constants.cr | 4 ++
3 files changed, 116 insertions(+), 73 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr
index 53a560c..b301c47 100644
--- a/src/lib/job.cr
+++ b/src/lib/job.cr
@@ -72,11 +72,15 @@ class Job
lab
initrd_pkg
initrd_deps
+ initrds
+ initrds_path
result_root
access_key
access_key_file
lkp_initrd_user
+ kernel
kernel_append_root
+ kernel_params
docker_image
)
@@ -123,8 +127,12 @@ class Job
set_result_root()
set_result_service()
set_os_mount()
- set_kernel_append_root()
set_pp_initrd()
+ set_initrds()
+ set_initrds_path()
+ set_kernel()
+ set_kernel_append_root()
+ set_kernel_params()
set_lkp_server()
end
@@ -228,27 +236,114 @@ class Job
end
end
- private def set_kernel_append_root
- os_real_path = JobHelper.service_path("#{SRV_OS}/#{os_dir}")
- lkp_real_path = JobHelper.service_path("#{SRV_OS}/#{os_dir}/initrd.lkp")
- lkp_basename = File.basename(lkp_real_path)
+ private def vmlinuz
+ if os_mount == "initramfs"
+ return "#{INITRD_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{os_dir}/vmlinuz")}"
+ else
+ return "#{OS_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_OS}/#{os_dir}/vmlinuz")}"
+ end
+ end
+
+ private def set_kernel
+ self["kernel"] = "kernel #{vmlinuz()}"
+ end
+
+ private def kernel_common_params
+ return "user=lkp job=/lkp/scheduled/job.yaml RESULT_ROOT=/result/job rootovl ip=dhcp ro"
+ end
+
+ private def common_initrds
+ temp_initrds = [] of String
+ temp_initrds << "#{INITRD_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_INITRD}/lkp/#{lkp_initrd_user}/lkp-#{os_arch}.cgz")}"
+ temp_initrds << "#{SCHED_HTTP_PREFIX}/job_initrd_tmpfs/#{id}/job.cgz"
+
+ return temp_initrds
+ end
+
+ private def initramfs_initrds
+ temp_initrds = [] of String
+
+ temp_initrds << "#{INITRD_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{os_dir}/current")}"
+ temp_initrds << "#{INITRD_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{os_dir}/run-ipconfig.cgz")}"
+
+ temp_initrds.concat(initrd_deps.split(/ /)) unless initrd_deps.empty?
+ temp_initrds.concat(initrd_pkg.split(/ /)) unless initrd_pkg.empty?
+
+ return temp_initrds
+ end
+
+ private def nfs_cifs_initrds
+ temp_initrds = [] of String
+ temp_initrds << "#{OS_HTTP_PREFIX}" +
+ "#{JobHelper.service_path("#{SRV_OS}/#{os_dir}/initrd.lkp")}"
+
+ return temp_initrds
+ end
+
+ private def set_initrds
+ temp_initrds = [] of String
- current_basename = ""
if "#{os_mount}" == "initramfs"
- current_real_path = JobHelper.service_path("#{SRV_INITRD}/osimage/#{os_dir}/current")
- current_basename = File.basename(current_real_path)
+ temp_initrds.concat(initramfs_initrds())
+ else
+ temp_initrds.concat(nfs_cifs_initrds())
end
+ temp_initrds.concat(common_initrds())
+
+ self["initrds"] = temp_initrds.join(" ")
+ end
+
+ private def initrds_basename
+ basenames = ""
+
+ initrds.split(/ /).each do |initrd|
+ basenames += "initrd=#{File.basename(initrd)} "
+ end
+
+ return basenames
+ end
+
+ private def set_initrds_path
+ paths = ""
+
+ initrds.split(/ /).each do |initrd|
+ paths += "initrd #{initrd}\n"
+ end
+
+ self["initrds_path"] = paths
+ end
+
+ private def set_kernel_append_root
+ os_real_path = JobHelper.service_path("#{SRV_OS}/#{os_dir}")
+
fs2root = {
- "nfs" => "root=#{OS_HTTP_HOST}:#{os_real_path} initrd=#{lkp_basename}",
+ "nfs" => "root=#{OS_HTTP_HOST}:#{os_real_path} #{initrds_basename()}",
"cifs" => "root=cifs://#{OS_HTTP_HOST}#{os_real_path}" +
- ",guest,ro,hard,vers=1.0,noacl,nouser_xattr initrd=#{lkp_basename}",
- "initramfs" => "rdinit=/sbin/init prompt_ramdisk=0 initrd=#{current_basename}",
- "container" => ""
+ ",guest,ro,hard,vers=1.0,noacl,nouser_xattr #{initrds_basename()}",
+ "initramfs" => "rdinit=/sbin/init prompt_ramdisk=0 #{initrds_basename()}",
+ "container" => "",
}
self["kernel_append_root"] = fs2root[os_mount]
end
+ private def kernel_console
+ if os_arch == "x86_64"
+ return "console=ttyS0,115200 console=tty0"
+ else
+ return ""
+ end
+ end
+
+ private def set_kernel_params
+ self["kernel_params"] = " #{kernel_common_params()} #{kernel_append_root} #{kernel_console()}"
+ end
+
private def set_pp_initrd
initrd_deps_arr = Array(String).new
initrd_pkg_arr = Array(String).new
@@ -270,6 +365,7 @@ class Job
end
end
end
+
self["initrd_deps"] = initrd_deps_arr.join(" ")
self["initrd_pkg"] = initrd_pkg_arr.join(" ")
end
diff --git a/src/lib/sched.cr b/src/lib/sched.cr
index 47a2e54..04c6317 100644
--- a/src/lib/sched.cr
+++ b/src/lib/sched.cr
@@ -480,69 +480,12 @@ class Sched
extra_job_fields) if Dir.glob(full_path_patterns).size > 0
end
- private def add_kernel_console_param(arch_tmp)
- returned = ""
- if arch_tmp == "x86_64"
- returned = " console=ttyS0,115200 console=tty0"
- end
- return returned
- end
-
- private def get_pp_initrd(job : Job)
- initrd_deps = ""
- initrd_pkg = ""
- if job.os_mount == "initramfs"
- initrd_deps += job.initrd_deps.split.join() { |item| "initrd #{item}\n" }
- initrd_pkg += job.initrd_pkg.split.join() { |item| "initrd #{item}\n" }
- end
- return initrd_deps, initrd_pkg
- end
-
private def get_boot_ipxe(job : Job)
- initrd_lkp_cgz = "lkp-#{job.os_arch}.cgz"
-
- initrd_deps, initrd_pkg = get_pp_initrd(job)
-
- initrd_http_prefix = "http://#{INITRD_HTTP_HOST}:#{INITRD_HTTP_PORT}"
- sched_http_prefix = "http://#{SCHED_HOST}:#{SCHED_PORT}"
- os_http_prefix = "http://#{OS_HTTP_HOST}:#{OS_HTTP_PORT}"
-
response = "#!ipxe\n\n"
- if job.os_mount == "initramfs"
- response += "initrd #{initrd_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{job.os_dir}/current")}\n"
- response += "initrd #{initrd_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{job.os_dir}/run-ipconfig.cgz")}\n"
- else
- response += "initrd #{os_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_OS}/#{job.os_dir}/initrd.lkp")}\n"
- end
- response += "initrd #{initrd_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_INITRD}/lkp/#{job.lkp_initrd_user}/#{initrd_lkp_cgz}")}\n"
- response += "initrd #{sched_http_prefix}/job_initrd_tmpfs/#{job.id}/job.cgz\n"
- response += initrd_deps
- response += initrd_pkg
- if job.os_mount == "initramfs"
- response += "kernel #{initrd_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_INITRD}/osimage/#{job.os_dir}/vmlinuz")}"
- else
- response += "kernel #{os_http_prefix}" +
- "#{JobHelper.service_path("#{SRV_OS}/#{job.os_dir}/vmlinuz")}"
- end
- response += " user=lkp"
- response += " job=/lkp/scheduled/job.yaml RESULT_ROOT=/result/job rootovl ip=dhcp ro"
- response += " #{job.kernel_append_root}"
- response += add_kernel_console_param(job.os_arch)
- if job.os_mount == "initramfs"
- response += " initrd=#{initrd_lkp_cgz} initrd=job.cgz"
- job.initrd_deps.split.each do |initrd_dep|
- response += " initrd=#{File.basename(initrd_dep)}"
- end
- response += " initrd=#{File.basename(JobHelper.service_path("#{SRV_INITRD}/osimage/#{job.os_dir}/run-ipconfig.cgz"))}\n"
- else
- response += " initrd=#{initrd_lkp_cgz} initrd=job.cgz\n"
- end
- response += "boot\n"
+ response += job.initrds_path
+ response += job.kernel
+ response += job.kernel_params
+ response += "\nboot\n"
puts %({"job_id": "#{job.id}", "job_state": "boot"})
return response
diff --git a/src/scheduler/constants.cr b/src/scheduler/constants.cr
index 7ce49a1..839c241 100644
--- a/src/scheduler/constants.cr
+++ b/src/scheduler/constants.cr
@@ -24,4 +24,8 @@ OS_HTTP_PORT = (ENV.has_key?("OS_HTTP_PORT") ? ENV["OS_HTTP_PORT"] : 8000).to_i3
SRV_OS = "/srv/os"
SRV_INITRD = "/srv/initrd"
+INITRD_HTTP_PREFIX = "http://#{INITRD_HTTP_HOST}:#{INITRD_HTTP_PORT}"
+OS_HTTP_PREFIX = "http://#{OS_HTTP_HOST}:#{OS_HTTP_PORT}"
+SCHED_HTTP_PREFIX = "http://#{SCHED_HOST}:#{SCHED_PORT}"
+
DEMO_JOB = %({"suite":"pixz","testcase":"pixz","category":"benchmark","nr_threads":1,"pixz":null,"job_origin":"jobs/pixz.yaml","testbox":"wfg-e595","arch":"x86_64","tbox_group":"wfg-e595","id":"100","kmsg":null,"boot-time":null,"uptime":null,"iostat":null,"heartbeat":null,"vmstat":null,"numa-numastat":null,"numa-vmstat":null,"numa-meminfo":null,"proc-vmstat":null,"proc-stat":null,"meminfo":null,"slabinfo":null,"interrupts":null,"kconfig":"x86_64-rhel-7.6","compiler":"gcc-7"})
--
2.23.0