+NR_VM = opt['nr_vm'] || 1 +QUEUES = opt['queues'] || "vm-2p8g.#{RUBY_PLATFORM.split('-')[0]}"
hao about set default value for opt, and no matter add -c, -n -q, the opt will still has the ele opt['hostname_prefix'], opt['nr_vm'], and opt['queues'], you do not need || here, and no need to check ARGV.size.zero?
understand, but i need this case: if run ./multi-qemu need show help message
because multi-qemu need sepcifies diff parameter for every user, if use default may be not suitable
Thanks, Shenwei
Thanks Luan Shengde
+LOG_DIR = '/srv/cci/serial/logs'
-def run(seqno)
- loop do
- start_time = Time.new
- hostname = "#{HOSTNAME}-#{seqno}"
- log_file = "/srv/cci/serial/logs/#{hostname}"
+def main(hostname)
- start_time = Time.new.strftime('%Y-%m-%d %H:%M:%S')
- log_file = "#{LOG_DIR}/#{hostname}"
- record_runtime(log_file, start_time)
- run_vm(hostname)
- duration = ((Time.new - Time.parse(start_time)) / 60).round(2)
- record_runtime(log_file, duration, is_start: false)
+end
+def record_runtime(log_file, message, is_start: true)
- if is_start File.open(log_file, 'w') do |f| # fluentd refresh time is 1s # let fluentd to monitor this file first sleep(2)
f.puts "\n#{start_time.strftime('%Y-%m-%d %H:%M:%S')} starting QEMU"
endf.puts "\n#{message} starting QEMU"
- return
- end
- File.open(log_file, 'a') do |f|
- f.puts "\nTotal QEMU duration: #{message} minutes"
- end
+end
- pwd_hostname = File.join(PWD, hostname)
- FileUtils.mkdir_p(pwd_hostname) unless File.exist?(pwd_hostname)
- FileUtils.cd(pwd_hostname)
- system(
{ 'hostname' => hostname },
ENV['CCI_SRC'] + '/providers/qemu.sh'
- )
- duration = ((Time.new - start_time) / 60).round(2)
- File.open(log_file, 'a') do |f|
f.puts "\nTotal QEMU duration: #{duration} minutes"
- end
+def run_vm(hostname)
- pwd_hostname = File.join(PWD, hostname)
- FileUtils.mkdir_p(pwd_hostname) unless File.exist?(pwd_hostname)
- FileUtils.cd(pwd_hostname)
- system(
- { 'hostname' => hostname, 'queues' => QUEUES },
- ENV['CCI_SRC'] + '/providers/qemu.sh'
- )
+end
- # sleep 5s is for fluentd to collect it's log
- sleep(5)
+def loop_main(hostname)
- loop do
- begin
main(hostname)
- rescue StandardError => e
puts e.backtrace
# if an exception happend, request the next time after 30 seconds
sleep 25
- ensure
sleep 5
- end end
end
@@ -55,7 +105,7 @@ def multiqemu pids = [] NR_VM.to_i.times do |i| pid = Process.fork do
run i
end pids << pid endloop_main("#{HOSTNAME}-#{i}")
-- 2.23.0