diff --git a/app/models/miq_ae_yaml_export.rb b/app/models/miq_ae_yaml_export.rb index 95a07e6e4..0ec69b6f1 100644 --- a/app/models/miq_ae_yaml_export.rb +++ b/app/models/miq_ae_yaml_export.rb @@ -168,7 +168,9 @@ def write_all_methods(ns_fqname, class_obj) class_obj.ae_methods.sort_by(&:fqname).each do |meth_obj| export_file_hash['created_on'] = meth_obj.created_on export_file_hash['updated_on'] = meth_obj.updated_on - write_method_file(meth_obj, export_file_hash) unless meth_obj.location == 'builtin' + if meth_obj.location == 'inline' + write_method_file(meth_obj, export_file_hash) + end write_method_attributes(meth_obj, export_file_hash) end end @@ -176,7 +178,9 @@ def write_all_methods(ns_fqname, class_obj) def write_method_attributes(method_obj, export_file_hash) envelope_hash = setup_envelope(method_obj, METHOD_OBJ_TYPE) envelope_hash['object']['inputs'] = method_obj.method_inputs - envelope_hash['object']['attributes'].delete('data') + if method_obj.location == "inline" + envelope_hash['object']['attributes'].delete('data') + end if method_obj.embedded_methods.empty? envelope_hash['object']['attributes'].delete('embedded_methods') end diff --git a/app/models/miq_ae_yaml_import.rb b/app/models/miq_ae_yaml_import.rb index 72a68ee32..231ac5865 100644 --- a/app/models/miq_ae_yaml_import.rb +++ b/app/models/miq_ae_yaml_import.rb @@ -217,7 +217,8 @@ def process_instance(class_obj, instance_yaml) def process_method(class_obj, ruby_method_file_name, method_yaml) method_attributes = method_yaml.fetch_path('object', 'attributes') if method_attributes['location'] == 'inline' - method_yaml.store_path('object', 'attributes', 'data', load_method_ruby(ruby_method_file_name)) + data = load_method_ruby(ruby_method_file_name) + method_yaml.store_path('object', 'attributes', 'data', data) if data end method_obj = MiqAeMethod.find_by(:name => method_attributes['name'], :class_id => class_obj.id) unless class_obj.nil? track_stats('method', method_obj) diff --git a/spec/models/miq_ae_yaml_import_export_spec.rb b/spec/models/miq_ae_yaml_import_export_spec.rb index 049c7e463..bcf984daf 100644 --- a/spec/models/miq_ae_yaml_import_export_spec.rb +++ b/spec/models/miq_ae_yaml_import_export_spec.rb @@ -6,13 +6,14 @@ 'max_retries' => "10", 'collect' => "dinosaurs", 'max_time' => "100"} + @expression_data = "---\n:db: VmOrTemplate\n:expression:\n STARTS WITH:\n field: VmOrTemplate-name\n value: :user_input\n" @clear_default_password = 'little_secret' @clear_password = 'secret' @relations_value = "bedrock relations" @domain_counts = {'dom' => 1, 'ns' => 3, 'class' => 4, 'inst' => 10, - 'meth' => 3, 'field' => 12, 'value' => 8} + 'meth' => 4, 'field' => 12, 'value' => 8} @domain_counts_with_extra_items = {'dom' => 1, 'ns' => 4, 'class' => 5, 'inst' => 11, - 'meth' => 3, 'field' => 12, 'value' => 8} + 'meth' => 4, 'field' => 12, 'value' => 8} EvmSpecHelper.local_miq_server @tenant = Tenant.seed create_factory_data("manageiq", 0, MiqAeDomain::SYSTEM_SOURCE) @@ -225,7 +226,7 @@ def assert_all_domains_imported(export_options, import_options) export_model(MiqAeYamlImportExportMixin::ALL_DOMAINS, export_options) reset_and_import(@export_dir, MiqAeYamlImportExportMixin::ALL_DOMAINS, import_options) check_counts('dom' => 2, 'ns' => 6, 'class' => 8, 'inst' => 20, - 'meth' => 6, 'field' => 24, 'value' => 16) + 'meth' => 8, 'field' => 24, 'value' => 16) end it "import single domain, from directory" do @@ -370,7 +371,7 @@ def assert_import_as(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) check_counts('dom' => 2, 'ns' => 6, 'class' => 8, 'inst' => 20, - 'meth' => 6, 'field' => 24, 'value' => 16) + 'meth' => 8, 'field' => 24, 'value' => 16) expect(MiqAeDomain.find_by_fqname(import_options['import_as'])).not_to be_nil end @@ -419,7 +420,7 @@ def assert_import_namespace_only(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) check_counts('dom' => 1, 'ns' => 2, 'class' => 3, 'inst' => 6, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) end it "domain, import only multi-part namespace, to directory" do @@ -470,7 +471,7 @@ def assert_import_class_only(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) end it "namespace, to directory" do @@ -495,7 +496,7 @@ def assert_single_namespace_export(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) check_counts('dom' => 1, 'ns' => 2, 'class' => 3, 'inst' => 6, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) end it "namespace, multi-part, to directory" do @@ -528,7 +529,7 @@ def assert_multi_namespace_export(export_options, import_options) export_model(@manageiq_domain.name, options) reset_and_import(@export_dir, @manageiq_domain.name) check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) @manageiq_domain = MiqAeNamespace.find_by_fqname('manageiq', false) @aen1_aec1 = MiqAeClass.find_by_name('manageiq_test_class_1') @aen1_aec1_aei2 = FactoryGirl.create(:miq_ae_instance, @@ -538,7 +539,7 @@ def assert_multi_namespace_export(export_options, import_options) export_model(@manageiq_domain.name, options) MiqAeImport.new(@manageiq_domain.name, 'preview' => false, 'import_dir' => @export_dir).import check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 3, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) end it "class, with methods, to directory" do @@ -565,7 +566,7 @@ def assert_class_with_methods_export(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2, - 'meth' => 2, 'field' => 6, 'value' => 4) + 'meth' => 3, 'field' => 6, 'value' => 4) end it "class, with builtin methods, as directory" do @@ -588,15 +589,35 @@ def assert_class_with_methods_export(export_options, import_options) assert_class_with_builtin_methods_export(export_options, import_options) end - def assert_class_with_builtin_methods_export(export_options, import_options) + it "class, with expression methods, as zip" do + export_options = {'namespace' => @aen1.name, 'class' => @aen1_aec1.name} + export_options['zip_file'] = @zip_file + import_options = {'zip_file' => @zip_file} + assert_class_with_expression_methods_export(export_options, import_options) + end + + def assert_methods_export(export_options, import_options) export_model(@manageiq_domain.name, export_options) reset_and_import(@export_dir, @manageiq_domain.name, import_options) - check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2, - 'meth' => 2, 'field' => 6, 'value' => 4) + check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2, + 'meth' => 3, 'field' => 6, 'value' => 4) + end + + def assert_class_with_builtin_methods_export(export_options, import_options) + assert_methods_export(export_options, import_options) + assert_method_data('test2', 'builtin', nil) + end + + def assert_class_with_expression_methods_export(export_options, import_options) + assert_methods_export(export_options, import_options) + assert_method_data('test3', 'expression', @expression_data) + end + + def assert_method_data(name, location, data) aen1_aec1 = MiqAeClass.find_by_name('manageiq_test_class_1') - builtin_method = MiqAeMethod.find_by_class_id_and_name(aen1_aec1.id, 'test2') - expect(builtin_method.location).to eql 'builtin' - expect(builtin_method.data).to be_nil + method = MiqAeMethod.find_by_class_id_and_name(aen1_aec1.id, name) + expect(method.location).to eql location + expect(method.data).to eq(data) end it "class, without methods, to directory" do @@ -771,6 +792,13 @@ def create_factory_data(domain_name, priority, source = MiqAeDomain::USER_SOURCE :scope => "instance", :language => "ruby", :location => "builtin") + FactoryGirl.create(:miq_ae_method, + :class_id => n1_c1.id, + :name => 'test3', + :scope => "instance", + :language => "ruby", + :data => @expression_data, + :location => "expression") FactoryGirl.create(:miq_ae_instance, :name => 'test_instance2', :class_id => n1_c1.id) create_fields(n1_c1, n1_c1_i1, n1_c1_m1)