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.

#350

Added tests
  • Loading branch information
billfitzgerald0120 committed Aug 3, 2018
1 parent 5dd26d1 commit 469bde6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,48 @@ def self.log(obj, object_string = 'Automation Object', handle = $evm)
obj.attributes.sort.each { |k, v| handle.log("info", " Attribute - #{k}: #{v}") }
handle.log("info", "Listing #{object_string} Attributes - End")
end

def self.log_ar_objects(object_string = 'VMDB Object', handle = $evm)
handle.log("info", "#{object_string} log_ar_objects Begins")
handle.root.attributes.sort.each do |k, v|
log_ar_object(k, v, object_string, handle) if v.class.to_s =~ /MiqAeMethodService::MiqAeService/
end
end

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

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

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

def self.tags(obj, object_string, handle = $evm)
return if obj.tags.nil?
handle.log("info", " #{object_string} 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", " #{object_string} End Tags [object.tags]")
end
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,54 @@
# described_class.log(ae_service, root)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(root, 'My Object', ae_service)
end

context 'log ar_object' 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(svc_model_vm1.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_object' 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(svc_model_vm1.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 469bde6

Please sign in to comment.