diff --git a/app/models/job.rb b/app/models/job.rb index f5f9e50cd40..f3b7789f82c 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -29,7 +29,7 @@ def self.create_job(process_type, options = {}) job.initialize_attributes job.save job.create_miq_task(job.attributes_for_task) - $log.info "Job created: guid: [#{job.guid}], userid: [#{job.userid}], name: [#{job.name}], target class: [#{job.target_class}], target id: [#{job.target_id}], process type: [#{job.type}], agent class: [#{job.agent_class}], agent id: [#{job.agent_id}], zone: [#{job.zone}]" + $log.info "Job created: #{job.attributes_log}" job.signal(:initializing) job end @@ -55,11 +55,11 @@ def initialize_attributes def check_active_on_destroy if self.is_active? - _log.warn "Job is active, delete not allowed - guid: [#{guid}], userid: [#{self.userid}], name: [#{self.name}], target class: [#{target_class}], target id: [#{target_id}], process type: [#{type}], agent class: [#{agent_class}], agent id: [#{agent_id}], zone: [#{zone}]" + _log.warn "Job is active, delete not allowed - #{attributes_log}" throw :abort end - _log.info "Job deleted: guid: [#{guid}], userid: [#{self.userid}], name: [#{self.name}], target class: [#{target_class}], target id: [#{target_id}], process type: [#{type}], agent class: [#{agent_class}], agent id: [#{agent_id}], zone: [#{zone}]" + _log.info "Job deleted: #{attributes_log}" true end @@ -251,4 +251,8 @@ def attributes_for_task :zone => zone, :started_on => started_on} end + + def attributes_log + "guid: [#{guid}], userid: [#{self.userid}], name: [#{self.name}], target class: [#{target_class}], target id: [#{target_id}], process type: [#{type}], agent class: [#{agent_class}], agent id: [#{agent_id}], zone: [#{zone}]" + end end # class Job diff --git a/app/models/job_proxy_dispatcher.rb b/app/models/job_proxy_dispatcher.rb index fa5ca12066c..001c91c7256 100644 --- a/app/models/job_proxy_dispatcher.rb +++ b/app/models/job_proxy_dispatcher.rb @@ -165,7 +165,7 @@ def queue_signal(job, options) def start_job_on_proxy(job, proxy) assign_proxy_to_job(proxy, job) - _log.info "Job [#{job.guid}] update: userid: [#{job.userid}], name: [#{job.name}], target class: [#{job.target_class}], target id: [#{job.target_id}], process type: [#{job.type}], agent class: [#{job.agent_class}], agent id: [#{job.agent_id}]" + _log.info "Job #{job.attributes_log}" job_options = {:args => ["start"], :zone => MiqServer.my_zone} job_options.merge!(:server_guid => proxy.guid, :role => "smartproxy") if proxy.kind_of?(MiqServer) @active_vm_scans_by_zone[MiqServer.my_zone] += 1 diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 2e35dec9234..caf2504abd8 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -293,6 +293,13 @@ end end + describe "#attributes_log" do + it "returns attributes for logging" do + job = Job.create_job("VmScan", :name => "Hello, World!") + expect(job.attributes_log).to include("VmScan", "Hello, World!", job.guid) + end + end + context "belongs_to task" do before(:each) do @job = Job.create_job("VmScan", :name => "Hello, World!") @@ -320,6 +327,7 @@ ) end end + context "after_update_commit callback calls" do describe "#update_linked_task" do it "executes when 'after_update_commit' callbacke triggered" do