Skip to content

Commit

Permalink
Adding Inspectme functionality into log_object embedded method.
Browse files Browse the repository at this point in the history
Added the ability to log all attributes, associations, and tags.
Inspectme is a great tool for debugging and now will be available from an embedded method.

ManageIQ#350

Added tests
Changed object_prefix to log_prefix as requested.
  • Loading branch information
billfitzgerald0120 committed Aug 13, 2018
1 parent 5dd26d1 commit be9fe61
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Description: Display Log messages for object attributes for root, current or desired object.
#
# Added InspectMe functionality

module ManageIQ
module Automate
Expand Down Expand Up @@ -37,10 +37,61 @@ def self.current(handle = $evm)
# instance method
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(vm, "My Object", @handle)

def self.log(obj, object_string = 'Automation Object', handle = $evm)
handle.log("info", "Listing #{object_string} Attributes - Begin")
def self.log(obj, log_prefix = 'Automation Object', handle = $evm)
handle.log("info", "Listing #{log_prefix} Attributes - Begin")
obj.attributes.sort.each { |k, v| handle.log("info", " Attribute - #{k}: #{v}") }
handle.log("info", "Listing #{object_string} Attributes - End")
handle.log("info", "Listing #{log_prefix} Attributes - End")
end

def self.ar_object?(obj)
if /DRb::DRbObject/.match?(obj.class.to_s) && obj.try(:object_class)
true
elsif /MiqAeMethodService::MiqAeService/.match?(obj.class.to_s)
true
else
false
end
end

def self.log_ar_objects(log_prefix = 'VMDB Object', handle = $evm)
handle.log("info", "#{log_prefix} log_ar_objects Begins")
handle.root.attributes.sort.each do |k, v|
log_ar_object(k, v, log_prefix, handle) if ar_object?(v)
end
end

def self.log_ar_object(key, object, log_prefix, handle = $evm)
handle.log("info", "key:<#{key}> object:<#{object}>")
attributes(object, log_prefix, handle)
associations(object, log_prefix, handle)
tags(object, log_prefix, handle)
end

def self.attributes(obj, log_prefix, handle = $evm)
handle.log("info", " #{log_prefix} Begin Attributes [object.attributes]")
obj.attributes.sort.each do |k, v|
handle.log("info", " Attribute: #{k} = #{v.inspect}")
end
handle.log("info", " #{log_prefix} End Attributes [object.attributes]")
end

def self.associations(obj, log_prefix, handle = $evm)
return unless ar_object?(obj)
handle.log("info", " #{log_prefix} Begin Associations [object.associations]")
obj.associations.sort.each do |assc|
handle.log("info", " Associations - #{assc}")
end
handle.log("info", " #{log_prefix} End Associations [object.associations]")
end

def self.tags(obj, log_prefix, handle = $evm)
return if obj.tags.nil?
handle.log("info", " #{log_prefix} Begin Tags [object.tags]")
obj.tags.sort.each do |tag_element|
tag_text = tag_element.split('/')
handle.log("info", " Category:<#{tag_text.first.inspect}> Tag:<#{tag_text.last.inspect}>")
end
handle.log("info", " #{log_prefix} End Tags [object.tags]")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
let(:user) { FactoryGirl.create(:user_with_email_and_group) }
let(:svc_model_user) { MiqAeMethodService::MiqAeServiceUser.find(user.id) }
let(:ems) { FactoryGirl.create(:ext_management_system) }
let(:ar_object) { svc_model_user }

let(:root) do
Spec::Support::MiqAeMockObject.new(
'dialog_provider' => ems.id.to_s,
'user' => svc_model_user,
'ar_object' => ar_object,
'current' => current_object
)
end

let(:small_environment_zone) { FactoryGirl.create(:small_environment) }
let(:parent_classification) { FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :read_only => false) }
let(:classification) { FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent => parent_classification, :read_only => true) }
let(:vm1) do
small_environment_zone

Vm.first
end

let(:svc_model_vm1) { MiqAeMethodService::MiqAeServiceVm.find(vm1.id) }

let(:current_object) { Spec::Support::MiqAeMockObject.new('a' => 1, 'b' => 2) }
let(:ae_service) do
Spec::Support::MiqAeMockService.new(root).tap do |service|
Expand Down Expand Up @@ -47,4 +59,52 @@
# described_class.log(ae_service, root)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(root, 'My Object', ae_service)
end

context 'log ar_objects' do
let(:ar_object) { svc_model_vm1 }

it 'with default VMDB Object string' do
classification.assign_entry_to(vm1)
expect(ae_service).to receive(:log).with('info', /log_ar_objects/).exactly(1).times
expect(ae_service).to receive(:log).with('info', /key:/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / VMDB Object Begin Attributes/).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Attribute:/).exactly(vm1.attributes.count).times
expect(ae_service).to receive(:log).with('info', / VMDB Object End Attributes/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / VMDB Object Begin Associations/).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Associations -/).exactly(MiqAeMethodService::MiqAeServiceVm.associations.count).times
expect(ae_service).to receive(:log).with('info', / VMDB Object End Associations/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / VMDB Object Begin Tags /).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Category:/).exactly(vm1.tags.count).times
expect(ae_service).to receive(:log).with('info', / VMDB Object End Tags/).exactly(1).times
# described_class.log_ar_objects('VMDB Object', ae_service)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log_ar_objects('VMDB Object', ae_service)
end
end

context 'log ar_objects' do
let(:ar_object) { svc_model_vm1 }

it ' with My Database Object string' do
classification.assign_entry_to(vm1)
expect(ae_service).to receive(:log).with('info', /log_ar_objects/).exactly(1).times
expect(ae_service).to receive(:log).with('info', /key:/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / My Database Object Begin Attributes/).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Attribute:/).exactly(vm1.attributes.count).times
expect(ae_service).to receive(:log).with('info', / My Database Object End Attributes/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / My Database Object Begin Associations/).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Associations -/).exactly(MiqAeMethodService::MiqAeServiceVm.associations.count).times
expect(ae_service).to receive(:log).with('info', / My Database Object End Associations/).exactly(1).times

expect(ae_service).to receive(:log).with('info', / My Database Object Begin Tags /).exactly(1).times
expect(ae_service).to receive(:log).with('info', / Category:/).exactly(vm1.tags.count).times
expect(ae_service).to receive(:log).with('info', / My Database Object End Tags/).exactly(1).times
# described_class.log_ar_objects('My Database Object', ae_service)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log_ar_objects('My Database Object', ae_service)
end
end
end

0 comments on commit be9fe61

Please sign in to comment.