From 9a5751688272ed7387c728c17fc07b2dff723a10 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 ----------------- .../miq_ae_engine/miq_ae_builtin_method.rb | 7 -- .../engine/miq_ae_engine/miq_ae_object.rb | 41 ------------ .../miq_ae_engine/miq_ae_workspace_runtime.rb | 19 ------ spec/miq_ae_object_spec.rb | 17 ----- .../miq_ae_datastore/xml_export_spec.rb | 66 ------------------- 7 files changed, 218 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 65f77a702..892de4498 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/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb index 113be317c..deeb3d5f2 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb @@ -28,13 +28,6 @@ def self.miq_log_object(obj, _inputs) $miq_ae_logger.info("===========================================") end - def self.miq_log_workspace(obj, _inputs) - $miq_ae_logger.info("===========================================") - $miq_ae_logger.info("Dumping Workspace") - $miq_ae_logger.info(obj.workspace.to_expanded_xml) - $miq_ae_logger.info("===========================================") - end - def self.miq_send_email(_obj, inputs) MiqAeMethodService::MiqAeServiceMethods.send_email(inputs["to"], inputs["from"], inputs["subject"], inputs["body"], :cc => inputs["cc"], :bcc => inputs["bcc"], :content_type => inputs["content_type"]) end diff --git a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb index 0552d8a0d..5e2743935 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb @@ -186,47 +186,6 @@ def state_machine? @aec.state_machine? end - def attribute_value_to_xml(value, xml) - case value.class.to_s - when 'MiqAePassword' then xml.Password(OPAQUE_PASSWORD) - when 'String' then xml.String(value) - when 'Fixnum' then xml.Fixnum(value) - when 'Symbol' then xml.Symbol(value.to_s) - when 'TrueClass', 'FalseClass' then xml.Boolean(value.to_s) - when /MiqAeMethodService::(.*)/ then xml.tag!($1.gsub(/::/, '-'), :object_id => value.object_id, :id => value.id) - when 'Array' - xml.Array do - value.each_index do |i| - xml.Element(:index => i + 1) { attribute_value_to_xml(value[i], xml) } - end - end - when 'Hash' - xml.Hash do - value.each do |k, v| - xml.Key(:name => k.to_s) { attribute_value_to_xml(v, xml) } - end - end - when 'DRb::DRbUnknown' - $miq_ae_logger.error("Found DRbUnknown for value: #{value.inspect} in XML: #{xml.inspect}") - xml.String(value) - else - xml.tag!(value.class.to_s.gsub(/::/, '-')) { xml.cdata!(value.inspect) } - end - end - - def to_xml(options = {}) - require 'builder' - xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) - xml_attrs = {:namespace => @namespace, :class => @klass, :instance => @instance} - xml.MiqAeObject(xml_attrs) do - @attributes.keys.sort.each do |k| - xml.MiqAeAttribute(:name => k) { attribute_value_to_xml(@attributes[k], xml) } - end - - children.each { |c| c.to_xml(:builder => xml) } - end - end - def fields(message = nil) @fields_ordered.collect do |fname| @fields[fname] if message.nil? || self.class.message_matches?(message_parse(@fields[fname]['message']), message) diff --git a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_workspace_runtime.rb b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_workspace_runtime.rb index b5a6af58c..aa6566a38 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_workspace_runtime.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_workspace_runtime.rb @@ -191,25 +191,6 @@ def pop_state_machine_info reset_state_info(@state_machine_objects.last) unless @state_machine_objects.empty? end - def to_expanded_xml(path = nil) - objs = path.nil? ? roots : get_obj_from_path(path) - objs = [objs] unless objs.kind_of?(Array) - - require 'builder' - xml = Builder::XmlMarkup.new(:indent => 2) - xml.MiqAeWorkspace do - objs.each { |obj| obj.to_xml(:builder => xml) } - end - end - - def to_xml(path = nil) - objs = path.nil? ? roots : get_obj_from_path(path) - result = objs.collect { |obj| to_hash(obj) }.compact - s = "" - XmlHash.from_hash({"MiqAeObject" => result}, {:rootname => "MiqAeWorkspace"}).to_xml.write(s, 2) - s - end - def to_dot(path = nil) require "rubygems" require "graphviz" diff --git a/spec/miq_ae_object_spec.rb b/spec/miq_ae_object_spec.rb index 509f2395c..0b5466d60 100644 --- a/spec/miq_ae_object_spec.rb +++ b/spec/miq_ae_object_spec.rb @@ -17,23 +17,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/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