[PATCH lkp-tests] lib: add multi-args in job yaml

[original style] os: openeuler os_verison: 20.03 os_arch: aarch64 os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64 [point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files. Signed-off-by: Bai Jing <799286817@qq.com> --- lib/job.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/job.rb b/lib/job.rb index 01719c2e..f8608e94 100755 --- a/lib/job.rb +++ b/lib/job.rb @@ -250,7 +250,7 @@ class Job hash.delete('override') end hash.merge!(@overrides) - @jobs << hash + @jobs.concat(multi_args(hash)) # return [hash] or [h1,h2] end rescue StandardError => e log_error "#{jobfile}: " + e.message @@ -280,6 +280,30 @@ class Job @jobfile = jobfile end + def multi_args(hash) + jobs_array = [] + hash.each { |key, value| + next unless key =~ /^\w.*\s+.*\w$/ + + next unless value.class == Array + + key_array = key.split + value.each do |v| + v_array = v.split + next unless key_array.size == v_array.size + + hash_job = hash.clone + key_array.size.times do |i| + hash_job[key_array[i]] = v_array[i] + end + hash_job.delete(key) + jobs_array << hash_job + end + } + jobs_array = [hash] if jobs_array.empty? + return jobs_array + end + def delete_keys_from_spec(spec_file) return unless File.exist? spec_file @@ -703,7 +727,8 @@ class Job @jobs.each do |hash| @load_hosts_done = false @job = deepcopy(job) - @job2 = hash + @job.merge!(hash) + @job2 = {} load_defaults load_hosts_config each_job_init -- 2.23.0

On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64 ^----- extra space, pat atttention to indent.
[point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files.
Signed-off-by: Bai Jing <799286817@qq.com> --- lib/job.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/job.rb b/lib/job.rb index 01719c2e..f8608e94 100755 --- a/lib/job.rb +++ b/lib/job.rb @@ -250,7 +250,7 @@ class Job hash.delete('override') end hash.merge!(@overrides) - @jobs << hash + @jobs.concat(multi_args(hash)) # return [hash] or [h1,h2] end rescue StandardError => e log_error "#{jobfile}: " + e.message @@ -280,6 +280,30 @@ class Job @jobfile = jobfile end
+ def multi_args(hash) + jobs_array = [] + hash.each { |key, value| + next unless key =~ /^\w.*\s+.*\w$/ + + next unless value.class == Array + + key_array = key.split + value.each do |v| + v_array = v.split + next unless key_array.size == v_array.size + + hash_job = hash.clone + key_array.size.times do |i| + hash_job[key_array[i]] = v_array[i] + end + hash_job.delete(key) + jobs_array << hash_job + end + }
just keep one style, perhaps it will be better. "do.....end" or "{}" Thanks, Liushaofei
+ jobs_array = [hash] if jobs_array.empty? + return jobs_array + end + def delete_keys_from_spec(spec_file) return unless File.exist? spec_file
@@ -703,7 +727,8 @@ class Job @jobs.each do |hash| @load_hosts_done = false @job = deepcopy(job) - @job2 = hash + @job.merge!(hash) + @job2 = {} load_defaults load_hosts_config each_job_init -- 2.23.0

On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64
add blank line.
[now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64
add blank line. Thanks, Liushaofei
[point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files.
Signed-off-by: Bai Jing <799286817@qq.com> --- lib/job.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/job.rb b/lib/job.rb index 01719c2e..f8608e94 100755 --- a/lib/job.rb +++ b/lib/job.rb @@ -250,7 +250,7 @@ class Job hash.delete('override') end hash.merge!(@overrides) - @jobs << hash + @jobs.concat(multi_args(hash)) # return [hash] or [h1,h2] end rescue StandardError => e log_error "#{jobfile}: " + e.message @@ -280,6 +280,30 @@ class Job @jobfile = jobfile end
+ def multi_args(hash) + jobs_array = [] + hash.each { |key, value| + next unless key =~ /^\w.*\s+.*\w$/ + + next unless value.class == Array + + key_array = key.split + value.each do |v| + v_array = v.split + next unless key_array.size == v_array.size + + hash_job = hash.clone + key_array.size.times do |i| + hash_job[key_array[i]] = v_array[i] + end + hash_job.delete(key) + jobs_array << hash_job + end + } + jobs_array = [hash] if jobs_array.empty? + return jobs_array + end + def delete_keys_from_spec(spec_file) return unless File.exist? spec_file
@@ -703,7 +727,8 @@ class Job @jobs.each do |hash| @load_hosts_done = false @job = deepcopy(job) - @job2 = hash + @job.merge!(hash) + @job2 = {} load_defaults load_hosts_config each_job_init -- 2.23.0

On Fri, Nov 13, 2020 at 11:35:22AM +0800, Liu Shaofei wrote:
On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64
add blank line.
[now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64
add blank line. Thanks, Liushaofei
Ok, i will change it. Thanks, Baijing
[point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files.
Signed-off-by: Bai Jing <799286817@qq.com> --- lib/job.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/job.rb b/lib/job.rb index 01719c2e..f8608e94 100755 --- a/lib/job.rb +++ b/lib/job.rb @@ -250,7 +250,7 @@ class Job hash.delete('override') end hash.merge!(@overrides) - @jobs << hash + @jobs.concat(multi_args(hash)) # return [hash] or [h1,h2] end rescue StandardError => e log_error "#{jobfile}: " + e.message @@ -280,6 +280,30 @@ class Job @jobfile = jobfile end
+ def multi_args(hash) + jobs_array = [] + hash.each { |key, value| + next unless key =~ /^\w.*\s+.*\w$/ + + next unless value.class == Array + + key_array = key.split + value.each do |v| + v_array = v.split + next unless key_array.size == v_array.size + + hash_job = hash.clone + key_array.size.times do |i| + hash_job[key_array[i]] = v_array[i] + end + hash_job.delete(key) + jobs_array << hash_job + end + } + jobs_array = [hash] if jobs_array.empty? + return jobs_array + end + def delete_keys_from_spec(spec_file) return unless File.exist? spec_file
@@ -703,7 +727,8 @@ class Job @jobs.each do |hash| @load_hosts_done = false @job = deepcopy(job) - @job2 = hash + @job.merge!(hash) + @job2 = {} load_defaults load_hosts_config each_job_init -- 2.23.0

On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64 [point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files.
Please keep the same indentation. Thanks, Zhangyu

On Fri, Nov 13, 2020 at 11:45:32AM +0800, Zhang Yu wrote:
On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64 [point] Currently, only one key of this style(xx xxx xx) can be contained in YAML files.
Please keep the same indentation.
Ok, i will change it. Thanks, Baijing

On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64
Is there version 20 for centos? If no, please change to an exist version. I know it's only a style sample, but it would makes people confused. Thanks, Yuanchao

On Fri, Nov 13, 2020 at 02:43:42PM +0800, Li Yuanchao wrote:
On Fri, Nov 13, 2020 at 11:18:59AM +0800, Bai Jing wrote:
[original style] os: openeuler os_verison: 20.03 os_arch: aarch64
os: centos os_version: 8.7 os_arch: aarch64 [now style] os os_version os_arch: - openeuler 20.03 aarch64 - centos 20 aarch64
Is there version 20 for centos? If no, please change to an exist version. I know it's only a style sample, but it would makes people confused.
Ok, I will change it. Thanks, Baijing
participants (4)
-
Bai Jing
-
Li Yuanchao
-
Liu Shaofei
-
Zhang Yu