From f7ec3870a89c7f31b608094f774cfb749f5d12f0 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Wed, 4 Mar 2020 23:43:24 -0500 Subject: [PATCH] Remove to_xml --- app/models/miq_ae_datastore.rb | 8 --- app/models/miq_ae_datastore/xml_export.rb | 60 ----------------- spec/miq_ae_collect_spec.rb | 3 - spec/miq_ae_object_spec.rb | 17 ----- spec/miq_ae_state_machine_spec.rb | 5 -- .../miq_ae_datastore/xml_export_spec.rb | 66 ------------------- 6 files changed, 159 deletions(-) delete mode 100644 app/models/miq_ae_datastore/xml_export.rb delete mode 100644 spec/models/miq_ae_datastore/xml_export_spec.rb diff --git a/app/models/miq_ae_datastore.rb b/app/models/miq_ae_datastore.rb index 16ffefe91..efd50ec68 100644 --- a/app/models/miq_ae_datastore.rb +++ b/app/models/miq_ae_datastore.rb @@ -110,14 +110,6 @@ def self.export(tenant) temp_export.unlink end - def self.export_class(namespace, class_name) - XmlExport.class_to_xml(namespace, class_name) - end - - def self.export_namespace(namespace) - XmlExport.namespace_to_xml(namespace) - end - def self.reset _log.info("Clearing datastore") [MiqAeClass, MiqAeField, MiqAeInstance, MiqAeNamespace, MiqAeMethod, MiqAeValue].each(&:delete_all) diff --git a/app/models/miq_ae_datastore/xml_export.rb b/app/models/miq_ae_datastore/xml_export.rb deleted file mode 100644 index b986c8cc8..000000000 --- a/app/models/miq_ae_datastore/xml_export.rb +++ /dev/null @@ -1,60 +0,0 @@ -require "builder" - -module MiqAeDatastore - class XmlExport - include Vmdb::Logging - def self.to_xml - _log.info("Exporting to XML") - xml = Builder::XmlMarkup.new(:indent => 2) - xml.instruct! - xml.MiqAeDatastore(:version => '1.0') do - MiqAeClass.all.sort_by(&:fqname).each do |miq_ae_class| - miq_ae_class.to_export_xml(:builder => xml, :skip_instruct => true, :indent => 2) - end - CustomButton.all.each do |custom_button| - custom_button.to_export_xml(:builder => xml, :skip_instruct => true, :indent => 2) - end - end - end - - def self.class_to_xml(namespace, class_name) - _log.info("Exporting class: #{class_name} to XML") - xml = Builder::XmlMarkup.new(:indent => 2) - xml.instruct! - xml.MiqAeDatastore(:version => '1.0') do - c = MiqAeClass.lookup_by_namespace_and_name(namespace, class_name) - c.to_export_xml(:builder => xml, :skip_instruct => true, :indent => 2) - end - end - - def self.export_sub_namespaces(namespace, xml) - namespace.ae_namespaces.each do |n| - sn = MiqAeNamespace.lookup_by_fqname(n.fqname) - export_all_classes_for_namespace(sn, xml) - export_sub_namespaces(sn, xml) - end - end - - def self.namespace_to_xml(namespace) - _log.info("Exporting namespace: #{namespace} to XML") - xml = Builder::XmlMarkup.new(:indent => 2) - xml.instruct! - rec = MiqAeNamespace.lookup_by_fqname(namespace) - if rec.nil? - _log.info("Namespace: <#{namespace}> not found.") - return nil - end - - xml.MiqAeDatastore(:version => '1.0') do - export_all_classes_for_namespace(rec, xml) - export_sub_namespaces(rec, xml) - end - end - - def self.export_all_classes_for_namespace(namespace, xml) - MiqAeClass.where(:namespace_id => namespace.id.to_i).sort_by(&:fqname).each do |c| - c.to_export_xml(:builder => xml, :skip_instruct => true, :indent => 2) - end - end - end -end diff --git a/spec/miq_ae_collect_spec.rb b/spec/miq_ae_collect_spec.rb index 7d4db4db4..1db0efa58 100644 --- a/spec/miq_ae_collect_spec.rb +++ b/spec/miq_ae_collect_spec.rb @@ -16,7 +16,6 @@ ws = MiqAeEngine.instantiate("/TEST/COLLECT/INFO#get_months", @user) expect(ws).not_to be_nil - # puts ws.to_xml months = ws.root("months") expect(months).not_to be_nil expect(months.class.to_s).to eq("Hash") @@ -34,7 +33,6 @@ it "collects weekdays" do ws = MiqAeEngine.instantiate("/TEST/COLLECT/INFO#get_weekdays", @user) expect(ws).not_to be_nil - # puts ws.to_xml weekdays = ws.root("weekdays") expect(weekdays).not_to be_nil expect(weekdays.class.to_s).to eq("Hash") @@ -51,7 +49,6 @@ ws = MiqAeEngine.instantiate("/TEST/COLLECT/INFO#get_weekdays", @user) expect(ws).not_to be_nil - # puts ws.to_xml weekdays = ws.root("weekdays") expect(weekdays).not_to be_nil expect(weekdays.class.to_s).to eq("Array") diff --git a/spec/miq_ae_object_spec.rb b/spec/miq_ae_object_spec.rb index aa4c54d96..46591c3c8 100644 --- a/spec/miq_ae_object_spec.rb +++ b/spec/miq_ae_object_spec.rb @@ -16,23 +16,6 @@ MiqAeDatastore.reset end - it "#to_xml" do - args = {'nil_arg' => nil, 'float_arg' => 5.98, - 'int_arg' => 10, 'string_arg' => 'Stringy', - 'svc_vm' => MiqAeMethodService::MiqAeServiceManageIQ_Providers_Vmware_InfraManager_Vm.find(@vm.id)} - - @miq_obj.process_args_as_attributes(args) - validate_xml(@miq_obj.to_xml, args) - end - - def validate_xml(xml, args) - hash = Hash.from_xml(xml) - attrs = hash['MiqAeObject']['MiqAeAttribute'] - args.each do |key, value| - expect(find_match(attrs, key, value)).to be_truthy - end - end - def find_match(attrs, key, value) item = attrs.detect { |i| i['name'] == key } return false unless item diff --git a/spec/miq_ae_state_machine_spec.rb b/spec/miq_ae_state_machine_spec.rb index f49fc4e7c..313c489ff 100644 --- a/spec/miq_ae_state_machine_spec.rb +++ b/spec/miq_ae_state_machine_spec.rb @@ -21,7 +21,6 @@ expect(ws.root['ae_result']).to eq('ok') expect(ws.root['ae_state']).to eq('final') - # puts ws.to_xml # puts "Old Provision Technique took #{t1 - t0} seconds" end @@ -36,7 +35,6 @@ expect(ws).not_to be_nil expect(ws.root['ae_result']).to eq('ok') expect(ws.root['ae_state']).to eq('') - # puts ws.to_xml # puts "New Provision Technique took #{t1 - t0} seconds" end @@ -52,7 +50,6 @@ expect(ws).not_to be_nil expect(ws.root['ae_result']).to eq('error') expect(ws.root['ae_state']).to eq('ProvisionCheck') - # puts ws.to_xml end it "raises exception properly during a provision request" do @@ -68,7 +65,6 @@ expect(ws).not_to be_nil expect(ws.root['ae_result']).to eq('error') expect(ws.root['ae_state']).to eq('ProvisionCheck') - # puts ws.to_xml end it "properly overrides class values with instance values, when they are present" do @@ -84,7 +80,6 @@ # t1 = Time.now expect(ws).not_to be_nil - # puts ws.to_xml # puts "New Provision (with instance override) Technique took #{t1 - t0} seconds" end diff --git a/spec/models/miq_ae_datastore/xml_export_spec.rb b/spec/models/miq_ae_datastore/xml_export_spec.rb deleted file mode 100644 index d6328dd3f..000000000 --- a/spec/models/miq_ae_datastore/xml_export_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -describe MiqAeDatastore::XmlExport do - describe ".to_xml" do - let(:custom_button) { double("CustomButton") } - let(:custom_buttons) { [custom_button] } - let(:miq_ae_class1) { double("MiqAeClass", :fqname => "z") } - let(:miq_ae_class2) { double("MiqAeClass", :fqname => "a") } - let(:miq_ae_classes) { [miq_ae_class1, miq_ae_class2] } - - let(:expected_xml) do - <<-XML - - - - - - - XML - end - - before do - # Populate the doubles *before* we start messing with .all - miq_ae_classes - custom_buttons - - allow(MiqAeClass).to receive(:all).and_return(miq_ae_classes) - allow(CustomButton).to receive(:all).and_return(custom_buttons) - end - - it "sorts the miq ae classes and returns the correct xml" do - expect(miq_ae_class2).to receive(:to_export_xml) do |options| - expect(options[:builder].target!).to eq <<~XML - - - XML - expect(options[:skip_instruct]).to be_truthy - expect(options[:indent]).to eq(2) - options[:builder].class2 - end - - expect(miq_ae_class1).to receive(:to_export_xml) do |options| - expect(options[:builder].target!).to eq <<~XML - - - - XML - expect(options[:skip_instruct]).to be_truthy - expect(options[:indent]).to eq(2) - options[:builder].class1 - end - - expect(custom_button).to receive(:to_export_xml) do |options| - expect(options[:builder].target!).to eq <<~XML - - - - - XML - expect(options[:skip_instruct]).to be_truthy - expect(options[:indent]).to eq(2) - options[:builder].custom_button - end - - expect(MiqAeDatastore::XmlExport.to_xml).to eq(expected_xml) - end - end -end