From 7b98161fd81fb43632263f821f6790434718841c Mon Sep 17 00:00:00 2001 From: william fitzgerald Date: Thu, 2 Aug 2018 13:18:44 -0400 Subject: [PATCH] Adding Inspectme functionality into log_object embedded method. 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. https://github.com/ManageIQ/manageiq-content/issues/350 --- .../Utils.class/__methods__/log_object.rb | 37 +++++++++++++++++++ .../__methods__/log_object_spec.rb | 27 ++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object.rb b/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object.rb index 9e8df3bb0..967a08277 100644 --- a/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object.rb +++ b/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object.rb @@ -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 diff --git a/spec/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object_spec.rb b/spec/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object_spec.rb index 721daa66b..7482b6235 100644 --- a/spec/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object_spec.rb +++ b/spec/content/automate/ManageIQ/System/CommonMethods/Utils.class/__methods__/log_object_spec.rb @@ -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| @@ -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 @@ -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