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
  • Loading branch information
billfitzgerald0120 committed Aug 2, 2018
1 parent 5dd26d1 commit 7b98161
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ 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(handle = $evm)
handle.log("info", "log_ar_objects Begins")
handle.root.attributes.sort.each do |k, v|
log_ar_object(k, v) if v.kind_of?(DRb::DRbObject) && v.try(:object_class)
end
end

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

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

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

def self.tags(obj, handle = $evm)
return if obj.tags.nil?

handle.log("info", " 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", " End Tags [object.tags]")
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
)
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) { FactoryGirl.create(:vm_vmware, :name => "VM1") }

let(:current_object) { Spec::Support::MiqAeMockObject.new('a' => 1, 'b' => 2) }
let(:ae_service) do
Spec::Support::MiqAeMockService.new(root).tap do |service|
Expand All @@ -23,6 +28,7 @@
let(:log_header_footer_count) { 2 }
let(:root_attr_count) { 3 }
let(:current_attr_count) { 2 }
let(:log_header_count) { 1 }

it '.root' do
expect(ae_service).to receive(:log).with('info', /Listing root Attributes/).exactly(log_header_footer_count).times
Expand All @@ -47,4 +53,25 @@
# described_class.log(ae_service, root)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(root, 'My Object', ae_service)
end

it '.log_ar_objects main' do
expect(ae_service).to receive(:log).with('info', /log_ar_objects/).exactly(log_header_count).times

# described_class.log(ae_service)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log_ar_objects(ae_service)
end

it '.log_ar_objects attributes, rest' do
# byebug
small_environment_zone
vm1.tag_with("red blue yellow", :ns => "/test", :cat => "tags")

# expect(ae_service).to receive(:log).with('info', /key:/).exactly(log_header_count).times
# expect(ae_service).to receive(:log).with('info', / Begin Attributes/).exactly(log_header_count).times
# expect(ae_service).to receive(:log).with('info', / Begin Associations/).exactly(log_header_count).times
expect(ae_service).to receive(:log).with('info', / Begin Tags /).exactly(log_header_count).times

# described_class.log(ae_service, root)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log_ar_objects(ae_service)
end
end

0 comments on commit 7b98161

Please sign in to comment.