Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Inspectme functionality into log_object embedded method. #386

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billfitzgerald0120
can we change this whole method to

def self.ar_object?(obj)
   obj.respond_to?(:object_class)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor The changes worked so I am updating PR. Thanks

obj.respond_to?(:object_class)
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