diff --git a/app/models/manageiq/providers/vmware/infra_manager/inventory/parser.rb b/app/models/manageiq/providers/vmware/infra_manager/inventory/parser.rb index f9f128250..d0117c812 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/inventory/parser.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/inventory/parser.rb @@ -71,7 +71,7 @@ def parse_customization_spec_manager(_object, kind, props) :typ => spec_info[:type], :description => spec_info[:description], :last_update_time => spec_info[:last_update_time].to_s, - :spec => rbvmomi_to_vim_types(spec_info[:spec]) + :spec => rbvmomi_to_basic_types(spec_info[:spec]).deep_stringify_keys ) end end @@ -392,12 +392,10 @@ def lazy_find_managed_object(managed_object) parent_collection.lazy_find(managed_object._ref) end - def rbvmomi_to_vim_types(obj) + def rbvmomi_to_basic_types(obj) case obj when RbVmomi::BasicTypes::DataObject - VimHash.new(obj.class.wsdl_name) do |new_obj| - obj.props.each { |k, v| new_obj[k.to_s] = rbvmomi_to_vim_types(v) } - end + obj.props.transform_values { |v| rbvmomi_to_basic_types(v) } when Array obj.map { |v| rbvmomi_to_basic_types(v) } else diff --git a/app/models/manageiq/providers/vmware/infra_manager/provision/customization.rb b/app/models/manageiq/providers/vmware/infra_manager/provision/customization.rb index 97cdbaccd..92352d321 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/provision/customization.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/provision/customization.rb @@ -9,9 +9,11 @@ def build_customization_spec # If an existing VC customization spec was selected connect to VC and get the spec custom_spec_name = get_option(:sysprep_custom_spec).to_s.strip + custom_spec_name = nil if custom_spec_name == "__VC__NONE__" + sysprep_spec_override = get_option(:sysprep_spec_override) - spec = load_customization_spec(custom_spec_name) - spec = spec.spec unless spec.nil? + spec = load_customization_spec(custom_spec_name) if custom_spec_name + _log.info "Loaded custom spec [#{custom_spec_name}]. Override flag: [#{sysprep_spec_override}]" if spec && sysprep_spec_override == false adjust_nicSettingMap(spec) @@ -197,18 +199,18 @@ def validate_customization_spec(custom_spec) end def load_customization_spec(custom_spec_name) - custom_spec_name = nil if custom_spec_name == "__VC__NONE__" - unless custom_spec_name.blank? - _log.info "Using customization spec [#{custom_spec_name}]" - cs = source.ext_management_system.customization_specs.find_by_id(custom_spec_name) - cs = source.ext_management_system.customization_specs.find_by(:name => custom_spec_name) if cs.nil? - raise MiqException::MiqProvisionError, "Customization Specification [#{custom_spec_name}] does not exist." if cs.nil? - raise MiqException::MiqProvisionError, "Customization Specification [#{custom_spec_name}] for OS type [#{cs[:typ]}] does not match the template VM OS" if cs[:typ].downcase != source.platform - _log.info "Using customization spec [#{cs.name}]" - return cs - else - _log.info "Customization spec name is empty, no spec will be loaded." - return nil + _log.info "Using customization spec [#{custom_spec_name}]" + cs = source.ext_management_system.customization_specs.find_by_id(custom_spec_name) + cs = source.ext_management_system.customization_specs.find_by(:name => custom_spec_name) if cs.nil? + raise MiqException::MiqProvisionError, "Customization Specification [#{custom_spec_name}] does not exist." if cs.nil? + raise MiqException::MiqProvisionError, "Customization Specification [#{custom_spec_name}] for OS type [#{cs[:typ]}] does not match the template VM OS" if cs[:typ].downcase != source.platform + _log.info "Using customization spec [#{cs.name}]" + + source.ext_management_system.with_provider_connection do |vim| + vim.getVimCustomizationSpecManager&.getCustomizationSpec(cs.name)&.spec + rescue Handsoap::Fault => err + _log.warn("Failed to load customization spec [#{cs.name}]: #{err}") + nil end end diff --git a/spec/models/manageiq/providers/vmware/infra_manager/provision/customization_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager/provision/customization_spec.rb index a8016394f..2839feab9 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager/provision/customization_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager/provision/customization_spec.rb @@ -97,7 +97,11 @@ end context 'build_customization_spec for windows template' do + before do + + end it 'loads existing spec' do + expect(prov_vm).to receive(:load_customization_spec).and_return(spec) expect(prov_vm.build_customization_spec).to(eq(spec)) end @@ -108,7 +112,9 @@ spec_for_compare.identity.userData.orgName = options[:sysprep_organization] options[:sysprep_full_name] = 'sysprep_full_name_value' spec_for_compare.identity.userData.fullName = options[:sysprep_full_name] - spec_for_compare.identity.identification = {} + spec_for_compare.identity.identification = VimHash.new + + expect(prov_vm).to receive(:load_customization_spec).and_return(spec) expect(prov_vm.build_customization_spec).to(eq(spec_for_compare)) end @@ -116,6 +122,7 @@ custom_spec.spec = nil options[:sysprep_full_name] = 'sysprep_full_name_value' options[:sysprep_organization] = 'sysprep_organization_value' + expect(prov_vm).to receive(:load_customization_spec).and_return(nil) expect(prov_vm.build_customization_spec).to(eq(new_spec)) end end