From 6313933b692d9ae6fe554223b10b7523681585c2 Mon Sep 17 00:00:00 2001 From: Boris Odnopozov Date: Wed, 20 Jun 2018 12:40:04 +0300 Subject: [PATCH] Add sysprep support for ovirt Add sysprep specification support for vm provisioning from template for the oVirt provider. Depends on: https://github.com/ManageIQ/manageiq/pull/17636 Required for: https://github.com/ManageIQ/manageiq-ui-classic/pull/4211 Implements: https://bugzilla.redhat.com/show_bug.cgi?id=1553833 --- .../infra_manager/provision/configuration.rb | 10 ++++++---- .../redhat/infra_manager/provision_workflow.rb | 14 +++++++++++--- .../provision/configuration_spec.rb | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/models/manageiq/providers/redhat/infra_manager/provision/configuration.rb b/app/models/manageiq/providers/redhat/infra_manager/provision/configuration.rb index 7efff7017..e53927f57 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/provision/configuration.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/provision/configuration.rb @@ -21,8 +21,7 @@ def configure_cloud_init end def configure_sysprep - content = get_option(:sysprep_upload_text) - + content = sysprep_specification_selected? ? customization_template_content : get_option(:sysprep_upload_text) return unless content with_provider_destination { |d| d.update_sysprep!(content) } @@ -37,9 +36,8 @@ def configure_container configure_cpu(rhevm_vm) configure_host_affinity(rhevm_vm) configure_network_adapters - sysprep_option = get_option(:sysprep_enabled) - if sysprep_option == 'file' + if sysprep_option == 'file' || sysprep_specification_selected? configure_sysprep elsif sysprep_option == 'fields' configure_cloud_init @@ -49,6 +47,10 @@ def configure_container private + def sysprep_specification_selected? + options.dig(:sysprep_enabled, 1) == "Sysprep Specification" + end + def customization_template_content return unless customization_template options = prepare_customization_template_substitution_options diff --git a/app/models/manageiq/providers/redhat/infra_manager/provision_workflow.rb b/app/models/manageiq/providers/redhat/infra_manager/provision_workflow.rb index 5524ad879..33d97181a 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/provision_workflow.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/provision_workflow.rb @@ -1,5 +1,6 @@ class ManageIQ::Providers::Redhat::InfraManager::ProvisionWorkflow < MiqProvisionInfraWorkflow include CloudInitTemplateMixin + include SysprepTemplateMixin def self.default_dialog_file 'miq_provision_dialogs' @@ -55,7 +56,11 @@ def update_field_visibility_linked_clone(_options = {}, f) def allowed_customization_templates(options = {}) if supports_native_clone? - allowed_cloud_init_customization_templates(options) + if get_source_vm.platform == 'windows' + allowed_sysprep_customization_templates(options) + else + allowed_cloud_init_customization_templates(options) + end else super(options) end @@ -73,8 +78,11 @@ def allowed_customization(_options = {}) result = {"disabled" => ""} case src[:vm].platform - when 'windows' then result["file"] = "Sysprep Answer File" - when 'linux' then result["fields"] = "Specification" + when 'windows' + result["file"] = "Sysprep Answer File" + result["fields"] = "Sysprep Specification" + when 'linux' + result["fields"] = "Specification" end result diff --git a/spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb b/spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb index e30559136..03a0528f5 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb +++ b/spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb @@ -80,6 +80,23 @@ expect(task.phase_context[:boot_with_sysprep]).to eq(true) end + + let(:cust_template) { FactoryGirl.create(:customization_template_sysprep, :script => "the script: <%= evm[:replace_me] %>" ) } + + it "provisions sysprep from template with substitutions" do + allow(MiqRegion).to receive_message_chain(:my_region, :remote_ui_url => "1.1.1.1") + task.options[:sysprep_enabled] = ["fields", "Sysprep Specification"] + task.options[:customization_template_id] = cust_template.id + task.options[:replace_me] = "replaced!" + + expect(vm_service).to receive(:update).with(OvirtSDK4::Vm.new( + :initialization => { + :custom_script => "the script: replaced!" + } + )) + + task.configure_sysprep + end end context "#configure_container" do @@ -115,3 +132,4 @@ end end end +