diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 88c6841c27b..4bb16e813d8 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -359,14 +359,16 @@ def start_runner_via_fork pid end - def self.build_command_line(options) - require 'awesome_spawn' - raise ArgumentError, "expected options hash, received: #{options.class}" unless options.kind_of?(Hash) - raise ArgumentError, "missing :guid options key" unless options.key?(:guid) + def self.build_command_line(guid, ems_id = nil) + raise ArgumentError, "No guid provided" unless guid + require 'awesome_spawn' cmd = "#{Gem.ruby} #{runner_script}" cmd = "nice #{nice_increment} #{cmd}" if ENV["APPLIANCE"] - "#{AwesomeSpawn::CommandLineBuilder.new.build(cmd, options.merge(:heartbeat => nil))} #{name}" + + options = {:guid => guid, :heartbeat => nil} + options[:ems_id] = ems_id if ems_id + "#{AwesomeSpawn::CommandLineBuilder.new.build(cmd, options)} #{name}" end def self.runner_script @@ -376,7 +378,7 @@ def self.runner_script end def command_line - self.class.build_command_line(worker_options) + self.class.build_command_line(*worker_options.values_at(:guid, :ems_id)) end def start_runner_via_spawn diff --git a/spec/models/miq_worker_spec.rb b/spec/models/miq_worker_spec.rb index 6735d8a9138..a4441cbb85c 100644 --- a/spec/models/miq_worker_spec.rb +++ b/spec/models/miq_worker_spec.rb @@ -346,11 +346,6 @@ def check_has_required_role(worker_role_names, expected_result) end context "#command_line" do - it "with nil worker_options" do - allow(@worker).to receive(:worker_options).and_return(nil) - expect { @worker.command_line }.to raise_error(ArgumentError) - end - it "without guid in worker_options" do allow(@worker).to receive(:worker_options).and_return({}) expect { @worker.command_line }.to raise_error(ArgumentError) @@ -369,7 +364,10 @@ def check_has_required_role(worker_role_names, expected_result) ENV['APPLIANCE'] = 'true' cmd = @worker.command_line expect(cmd).to start_with("nice +10") - expect(cmd).to end_with("--ems-id 1234 --guid #{@worker.guid} --heartbeat MiqWorker") + expect(cmd).to include("--ems-id 1234") + expect(cmd).to include("--guid #{@worker.guid}") + expect(cmd).to include("--heartbeat") + expect(cmd).to end_with("MiqWorker") ensure # ENV['x'] = nil deletes the key because ENV accepts only string values ENV['APPLIANCE'] = old_env