1. monitor job state to get job runtime,
start time: job_state => 'boot'
end_time : job_state => 'extract-finished'
2. es-find to get job_state and result_root.
Signed-off-by: Liu Yinsi <liuyinsi(a)163.com>
---
.../maintain/walk-os-test/walk-os-iperf-test | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test
index 9910723..ccbff68 100755
--- a/user-client/maintain/walk-os-test/walk-os-iperf-test
+++ b/user-client/maintain/walk-os-test/walk-os-iperf-test
@@ -17,6 +17,21 @@
# End Cost/sec Job_State Result_Url
# 2020-10-19/18:44:48 127 finished #{SRV_HTTP_HOST}:#{SRV_HTTP_PORT}/#{result_root}
+require 'set'
+require 'open3'
+require "#{ENV['LKP_SRC']}/lib/monitor"
+require "#{ENV['CCI_SRC']}/container/defconfig.rb"
+
+names = Set.new %w[
+ SRV_HTTP_HOST
+ SRV_HTTP_PORT
+]
+
+defaults = relevant_defaults(names)
+
+SRV_HTTP_HOST = defaults['SRV_HTTP_HOST'] || Open3.capture3('curl ip.sb')[0].chomp
+SRV_HTTP_PORT = defaults['SRV_HTTP_PORT'] || '11300'
+
TEST_OS = [
'openeuler aarch64 20.03',
'centos aarch64 7.6.1810',
@@ -30,6 +45,44 @@ TESTBOX = %w[vm-2p8g vm-pxe-2p8g].freeze
TEST_REPORT = 'walk-test.report'
TEST_YAML = 'iperf-walk-os.yaml'
+def logging(*log_params)
+ log_format = '%-18s %-37s %-23s %-23s %-12s %-13s %-50s'
+ File.open(TEST_REPORT, 'a') do |f|
+ f.puts format(log_format, *log_params)
+ end
+end
+
+def monitor(query, actions, timeout)
+ monitor = Monitor.new
+ monitor.overrides = query
+ monitor.action = actions
+ monitor.run(timeout)
+end
+
+def monitor_job(job_id, job_state)
+ state_code = monitor({ 'job_id' => job_id, 'job_state' => job_state }, { 'stop' => true }, '600s')
+ Time.now.to_s.split[0..1].join '/' if state_code.zero?
+end
+
+def es_find(job_id, search_field)
+ %x(es-find id=#{job_id}| grep #{search_field}| awk -F '"' '{print $4}').chomp
+end
+
+def get_log_params(os_array, message)
+ job_id = message.split('=')[1].chomp
+ os_params = os_array.join '/'
+ s_time = monitor_job(job_id, 'boot')
+ e_time = monitor_job(job_id, 'extract_finished')
+ return if s_time.nil? || e_time.nil?
+
+ c_time = (s_time - e_time).floor
+ job_state = es_find(job_id, 'job_state')
+ result_root = es_find(job_id, 'result_root')
+ result_url = SRV_HTTP_HOST.concat ':', SRV_HTTP_PORT, result_root
+
+ logging(job_id, os_params, s_time, e_time, c_time, job_state, result_url)
+end
+
def submit_job(os_array, testbox)
os = os_array[0]
os_arch = os_array[1]
@@ -42,6 +95,8 @@ def submit_job(os_array, testbox)
# Process.fork do
# %x(./my-qemu.sh >/dev/null 2>&1)
# end
+
+ get_log_params(os_array, message)
end
def get_os_array(os_mount, testbox)
@@ -56,4 +111,6 @@ def get_testbox(os_mount)
TESTBOX.each { |testbox| get_os_array(os_mount, testbox) }
end
+logging('Job_ID', 'OS', 'Begin', 'End', 'Cost/sec', 'Job_State', 'Result_Url')
+
MOUNT_TYPE.each { |os_mount| get_testbox(os_mount) }
--
2.23.0