diff --git a/app/models/miq_dialog.rb b/app/models/miq_dialog.rb index c15a3f8459c..a32f854e1ee 100644 --- a/app/models/miq_dialog.rb +++ b/app/models/miq_dialog.rb @@ -7,7 +7,6 @@ class MiqDialog < ApplicationRecord DIALOG_TYPES = [ [_("VM Provision"), "MiqProvisionWorkflow"], [_("Configured System Provision"), "MiqProvisionConfiguredSystemWorkflow"], - [_("Host Provision"), "MiqHostProvisionWorkflow"], [_("VM Migrate"), "VmMigrateWorkflow"], [_("Physical Server Provision"), "PhysicalServerProvisionWorkflow"] ].freeze diff --git a/app/models/miq_host_provision.rb b/app/models/miq_host_provision.rb deleted file mode 100644 index 902931bd475..00000000000 --- a/app/models/miq_host_provision.rb +++ /dev/null @@ -1,49 +0,0 @@ -class MiqHostProvision < MiqRequestTask - include_concern 'Configuration' - include_concern 'PostInstallCallback' - include_concern 'Ipmi' - include_concern 'OptionsHelper' - include_concern 'Placement' - include_concern 'Pxe' - include_concern 'Rediscovery' - include_concern 'StateMachine' - include_concern 'Tagging' - - alias_attribute :provision_type, :request_type - alias_attribute :miq_host_provision_request, :miq_request - alias_attribute :host, :source - - validates :request_type, - :inclusion => { :in => %w(host_pxe_install), - :message => "should be 'host_pxe_install'" - } - validates :state, - :inclusion => { :in => %w(pending queued active provisioned finished), - :message => 'should be pending, queued, active, provisioned or finished' } - - virtual_column :provision_type, :type => :string - - AUTOMATE_DRIVES = true - - def self.get_description(prov_obj) - prov_obj.description - end - - def self.base_model - MiqHostProvision - end - - def deliver_to_automate - super("host_provision") - end - - def do_request - signal :create_destination - end - - delegate :name, :to => :host, :prefix => true - - def self.display_name(number = 1) - n_('Host Provision', 'Host Provisions', number) - end -end diff --git a/app/models/miq_host_provision/configuration.rb b/app/models/miq_host_provision/configuration.rb deleted file mode 100644 index 5993f112d31..00000000000 --- a/app/models/miq_host_provision/configuration.rb +++ /dev/null @@ -1,64 +0,0 @@ -module MiqHostProvision::Configuration - def set_network_information - _log.info("Setting Network Information") - destination.update_attributes!(:ipaddress => ip_address, :hostname => hostname) - _log.info("Validating Host Credentials") - - # add the ssh host key even if there's an existing one from the prior OS install - destination.authentication_check(:default, :remember_host => true) - _log.info("Setting Network Information..complete -- ipaddress=[#{ip_address}], hostname=[#{hostname}]") - end - - # TODO: Subclass - def set_maintenance_mode_vmware - destination.with_provider_object(:connection_source => host) do |vim_host| - if vim_host.inMaintenanceMode? - _log.info("Host is already Maintenance Mode") - else - _log.info("Putting host into Maintenance Mode...") - vim_host.enterMaintenanceMode - _log.info("Putting host into Maintenance Mode...complete") - end - end - end - - def set_maintenance_mode - # TODO: Subclass - if destination.is_vmware? - set_maintenance_mode_vmware - else - _log.warn("VMM Vendor [#{destination.vmm_vendor_display}] is not supported") - end - end - - # TODO: Subclass - def add_storage_vmware - if destination.ext_management_system.nil? - _log.error("Host has no External Management System") - return - end - - destination.with_provider_object do |vim_host| - vim_dss = vim_host.datastoreSystem - storages_to_attach.each do |storage| - case storage.store_type - when 'NFS' - _log.info("Adding datastore: [#{storage.name}]") - vim_dss.addNasDatastoreByName(storage.name) - _log.info("Adding datastore: [#{storage.name}]...Complete") - else - _log.warn("Storage Type [#{storage.store_type}] is not supported") - end - end - end - end - - def add_storage - # TODO: Subclass - if destination.is_vmware? - add_storage_vmware - else - _log.warn("VMM Vendor [#{destination.vmm_vendor_display}] is not supported") - end - end -end diff --git a/app/models/miq_host_provision/ipmi.rb b/app/models/miq_host_provision/ipmi.rb deleted file mode 100644 index 4b90def7ab3..00000000000 --- a/app/models/miq_host_provision/ipmi.rb +++ /dev/null @@ -1,14 +0,0 @@ -module MiqHostProvision::Ipmi - def ipmi_reboot(_address, _userid, _password) - require 'miq-ipmi' - - # Force the host to restart (or just turn on if already off) - _log.info("Connecting with address: [#{host.ipmi_address}], userid: [#{host.authentication_userid(:ipmi)}]...") - ipmi = MiqIPMI.new(host.ipmi_address, *host.auth_user_pwd(:ipmi)) - ipmi_command = 'chassis bootdev pxe' - _log.info("Invoking [#{ipmi_command}]") - ipmi.run_command(ipmi_command) - _log.info("Invoking [power_reset]") - ipmi.power_reset - end -end diff --git a/app/models/miq_host_provision/options_helper.rb b/app/models/miq_host_provision/options_helper.rb deleted file mode 100644 index bfb3c52fb16..00000000000 --- a/app/models/miq_host_provision/options_helper.rb +++ /dev/null @@ -1,26 +0,0 @@ -module MiqHostProvision::OptionsHelper - def storage_ids - @attached_ds ||= options[:attached_ds] || [] - end - - def storages_to_attach - @storages_to_attach ||= storage_ids.collect { |sid| Storage.find_by(:id => sid) }.compact - end - - def src_hosts - @src_hosts ||= options[:src_host_ids].collect { |id_str| Host.find_by(:id => id_str.to_i) }.compact - end - - def description - @description ||= _("PXE install on [%{name}] from image [%{id}]") % {:name => host_name, - :id => get_option(:pxe_image_id)} - end - - def ip_address - @ip_address ||= get_option(:ip_addr) - end - - def hostname - @hostname ||= get_option(:hostname) - end -end diff --git a/app/models/miq_host_provision/placement.rb b/app/models/miq_host_provision/placement.rb deleted file mode 100644 index bd84726cc08..00000000000 --- a/app/models/miq_host_provision/placement.rb +++ /dev/null @@ -1,37 +0,0 @@ -module MiqHostProvision::Placement - def placement_ems - @placement_ems ||= ExtManagementSystem.find_by(:id => get_option(:placement_ems_name)) - end - - def placement_cluster - @placement_cluster ||= EmsCluster.find_by(:id => get_option(:placement_cluster_name)) - end - - def placement_folder - @placement_folder ||= EmsFolder.find_by(:id => get_option(:placement_folder_name)) - end - - # TODO: Subclass - def place_in_ems_vmware - ems_cluster = placement_cluster - unless ems_cluster.nil? - _log.info("Registering Host on Cluster: [#{ems_cluster.name}]") - return ems_cluster.register_host(host) - end - - ems_folder = placement_folder - unless ems_folder.nil? - _log.info("Registering Host on Folder: [#{ems_folder.name}]") - return ems_folder.register_host(host) - end - end - - def place_in_ems - # TODO: Subclass - if host.is_vmware? - place_in_ems_vmware - else - _log.warn("VMM Vendor [#{host.vmm_vendor_display}] is not supported") - end - end -end diff --git a/app/models/miq_host_provision/post_install_callback.rb b/app/models/miq_host_provision/post_install_callback.rb deleted file mode 100644 index 68cad4fdb86..00000000000 --- a/app/models/miq_host_provision/post_install_callback.rb +++ /dev/null @@ -1,7 +0,0 @@ -module MiqHostProvision::PostInstallCallback - extend ActiveSupport::Concern - - def provision_completed - signal :post_install_callback - end -end diff --git a/app/models/miq_host_provision/pxe.rb b/app/models/miq_host_provision/pxe.rb deleted file mode 100644 index 0dedeef120c..00000000000 --- a/app/models/miq_host_provision/pxe.rb +++ /dev/null @@ -1,76 +0,0 @@ -module MiqHostProvision::Pxe - def pxe_server - @pxe_server ||= PxeServer.find_by(:id => get_option(:pxe_server_id)) - end - - def pxe_image - pxe_and_windows_image.first - end - - def pxe_and_windows_image - return @pxe_image, @windows_image unless @pxe_image.nil? - - image_id = get_option(:pxe_image_id) - if image_id.kind_of?(String) - # "new" style of choosing either a pxe image or a windows image, and - # storing the pxe_image_id field as "ClassName::id" - klass, id = image_id.split("::") - image = klass.constantize.find_by(:id => id) - - if image.kind_of?(WindowsImage) - @pxe_image = pxe_server.default_pxe_image_for_windows - @windows_image = image - else - @pxe_image = image - @windows_image = nil - end - else - # "old" style of choosing both the pxe image and windows image manually - @pxe_image = PxeImage.find_by(:id => get_option(:pxe_image_id)) - @windows_image = WindowsImage.find_by(:id => get_option(:windows_image_id)) - end - - return @pxe_image, @windows_image - end - - def customization_template - @customization_template ||= CustomizationTemplate.find_by(:id => get_option(:customization_template_id)) - end - - # From http://stackoverflow.com/questions/1825928/netmask-to-cidr-in-ruby - def cidr - subnet_mask = get_option(:subnet_mask) - require 'ipaddr' - Integer(32 - Math.log2((IPAddr.new(subnet_mask.to_s, Socket::AF_INET).to_i ^ 0xffffffff) + 1)) - rescue ArgumentError => err - _log.warn("Cannot convert subnet #{subnet_mask.inspect} to CIDR because #{err.message}") - return nil - end - - def create_pxe_files - pxe_image, windows_image = pxe_and_windows_image - mac_address = host.mac_address - - raise _("MAC Address is nil") if mac_address.nil? - - substitution_options = nil - if customization_template - substitution_options = options.dup - substitution_options[:miq_host_provision_id] = id - substitution_options[:mac_address] = mac_address - substitution_options[:post_install_callback_url] = post_install_callback_url - substitution_options[:cidr] = cidr - end - - pxe_server.create_provisioning_files(pxe_image, mac_address, windows_image, customization_template, substitution_options) - end - - def delete_pxe_files - pxe_image, windows_image = pxe_and_windows_image - mac_address = host.mac_address - - raise _("MAC Address is nil") if mac_address.nil? - - pxe_server.delete_provisioning_files(pxe_image, mac_address, windows_image, customization_template) - end -end diff --git a/app/models/miq_host_provision/rediscovery.rb b/app/models/miq_host_provision/rediscovery.rb deleted file mode 100644 index efcba0acd9b..00000000000 --- a/app/models/miq_host_provision/rediscovery.rb +++ /dev/null @@ -1,30 +0,0 @@ -module MiqHostProvision::Rediscovery - def find_destination_in_vmdb - rediscover_host - host_rediscovered? ? host(true) : nil - end - - def host_rediscovered? - if pxe_image.try(:pxe_image_type).try(:esx?) - host && host.vmm_vendor_display.downcase != 'unknown' - else - state == 'provisioned' - end - end - - def rediscover_host - # TODO: why is this check here?? - unless state == 'active' - _log.info("provision task check has already been processed - state: [#{state}]") - return - end - - _log.info("Refreshing Power State via IPMI") - host.refresh_ipmi_power_state - - _log.info("Rediscovering Host on IP Address: #{ip_address.inspect}") - discovery_types = [] - discovery_types << :esx if pxe_image.try(:pxe_image_type).try(:esx?) - host.rediscover(ip_address, discovery_types) - end -end diff --git a/app/models/miq_host_provision/state_machine.rb b/app/models/miq_host_provision/state_machine.rb deleted file mode 100644 index b71077dd554..00000000000 --- a/app/models/miq_host_provision/state_machine.rb +++ /dev/null @@ -1,148 +0,0 @@ -module MiqHostProvision::StateMachine - def my_zone - ems = placement_ems - zone = ems.zone.name unless ems.nil? - zone ||= MiqServer.my_zone - zone - end - - def validate_provision - raise _("Unable to find PXE server with id [%{id}]") % {:id => get_option(:pxe_server_id)} if pxe_server.nil? - raise _("Unable to find PXE image with id [%{id}]") % {:id => get_option(:pxe_image_id)} if pxe_image.nil? - raise _("Host [%{name}] does not have a valid Mac Address") % {:name => host_name} if host.mac_address.blank? - if host.missing_credentials?(:ipmi) - raise _("Host [%{name}] does not have valid IPMI credentials") % {:name => host_name} - end - raise _("Host [%{name}] does not have an IP Address configured") % {:name => host_name} if ip_address.blank? - if host.v_total_vms > 0 - raise _("Host [%{name}] has %{number} VMs") % {:name => host_name, :number => host.v_total_vms} - end - if host.v_total_miq_templates > 0 - raise _("Host [%{name}] has %{number} Templates") % {:name => host_name, :number => host.v_total_miq_templates} - end - unless host.ext_management_system.nil? - raise _("Host [%{name}] is registered to %{system_name}") % {:name => host_name, - :system_name => host.ext_management_system.name} - end - end - - def create_destination - validate_provision - signal :reset_host_in_vmdb - end - - def reset_host_in_vmdb - host.reset_discoverable_fields - - ipmi_host_name = "IPMI (#{host.ipmi_address})" - host.update_attributes(:name => ipmi_host_name) - - userid = 'root' - password = get_option(:root_password) - host.update_authentication(:default => {:userid => userid, :password => password}) - - signal :reset_host_credentials - end - - def reset_host_credentials - userid = 'root' - password = get_option(:root_password) - host.update_authentication(:default => {:userid => userid, :password => password}) - - signal :create_pxe_configuration_files - end - - def create_pxe_configuration_files - create_pxe_files - - signal :reboot - end - - def reboot - ipmi_reboot(host.ipmi_address, *host.auth_user_pwd(:ipmi)) - - # Waiting for PXE Post-Provision to call back into :post_install_callback - end - - def post_install_callback - message = "PXE Provisioning Complete" - _log.info("#{message} #{for_destination}") - update_and_notify_parent(:message => message) - - signal :delete_pxe_configuration_files - end - - def delete_pxe_configuration_files - if get_option(:stateless) - message = "Stateless, NOT deleting PXE and Customization Files on PXE Server" - _log.info("#{message} #{for_destination}") - else - message = "Deleting PXE and Customization Files on PXE Server" - _log.info("#{message} #{for_destination}") - update_and_notify_parent(:message => message) - delete_pxe_files - end - - signal :poll_destination_in_vmdb - end - - def poll_destination_in_vmdb - update_and_notify_parent(:message => "Validating New Host") - - self.destination = find_destination_in_vmdb - if destination - # Update source in case the object subclass changes. - self.source = destination - signal :configure_destination - else - _log.info("Unable to find Host with IP Address [#{ip_address}], will retry") - requeue_phase - end - end - - def configure_destination - set_network_information - set_maintenance_mode - place_in_ems - add_storage - - signal :post_create_destination - end - - def post_create_destination - apply_tags(destination) - - signal :mark_as_completed - end - - def mark_as_completed - begin - inputs = {:host => destination} - MiqEvent.raise_evm_event(destination, 'host_provisioned', inputs) - rescue => err - _log.log_backtrace(err) - end - - message = "Finished New Host Placement" - if MiqHostProvision::AUTOMATE_DRIVES - update_and_notify_parent(:state => 'provisioned', :message => message) - else - update_and_notify_parent(:state => 'finished', :message => message) - call_automate_event('host_provision_postprocessing') - end - - signal :finish - end - - def finish - if status != 'Error' - _log.info("Executing provision request ... Complete") - end - end - - private - - def for_destination - "for Host with MAC Address: [#{host.mac_address.inspect}]" - end -end diff --git a/app/models/miq_host_provision/tagging.rb b/app/models/miq_host_provision/tagging.rb deleted file mode 100644 index be5d07c79e2..00000000000 --- a/app/models/miq_host_provision/tagging.rb +++ /dev/null @@ -1,8 +0,0 @@ -module MiqHostProvision::Tagging - def apply_tags(host) - tags do |tag, cat| - _log.info("Tagging [#{host.name}], Category: [#{cat}], Tag: #{tag}") - Classification.classify(host, cat.to_s, tag) - end - end -end diff --git a/app/models/miq_host_provision_request.rb b/app/models/miq_host_provision_request.rb deleted file mode 100644 index bc01ac27644..00000000000 --- a/app/models/miq_host_provision_request.rb +++ /dev/null @@ -1,73 +0,0 @@ -class MiqHostProvisionRequest < MiqRequest - alias_attribute :provision_type, :request_type - alias_attribute :miq_host_provisions, :miq_request_tasks - - TASK_DESCRIPTION = 'Host Provisioning' - SOURCE_CLASS_NAME = 'Host' - ACTIVE_STATES = %w( migrated ) + base_class::ACTIVE_STATES - - validates_inclusion_of :request_state, :in => %w( pending finished ) + ACTIVE_STATES, :message => "should be pending, #{ACTIVE_STATES.join(", ")} or finished" - validate :must_have_user - - virtual_column :provision_type, :type => :string - - def host_name - if options[:src_host_ids].length == 1 - host = Host.find_by(:id => options[:src_host_ids].first) - host.nil? ? "" : host.name - else - "Multiple Hosts" - end - end - - def requested_task_idx - options[:src_host_ids] - end - - def placement_ems - ems_id, _ems_name = options[:placement_ems_name] - ExtManagementSystem.find_by(:id => ems_id) if ems_id.kind_of?(Numeric) - end - - def placement_cluster - ems_cluster_id, _ems_cluster_name = options[:placement_cluster_name] - EmsCluster.find_by(:id => ems_cluster_id) if ems_cluster_id.kind_of?(Numeric) - end - - def placement_folder - ems_folder_id, _ems_folder_name = options[:placement_folder_name] - EmsFolder.find_by(:id => ems_folder_id) if ems_folder_id.kind_of?(Numeric) - end - - def pxe_server - pxe_server_id, _pxe_server_name = options[:pxe_server_id] - PxeServer.find_by(:id => pxe_server_id) if pxe_server_id.kind_of?(Numeric) - end - - def pxe_image - pxe_image_id, _pxe_image_name = options[:pxe_image_id] - PxeImage.find_by(:id => pxe_image_id) if pxe_image_id.kind_of?(Numeric) - end - - def src_hosts - options[:src_host_ids].collect { |id_str| Host.find_by(:id => id_str.to_i) }.compact - end - - def my_role(_action = nil) - 'ems_operations' - end - - def originating_controller - "host" - end - - def event_name(mode) - "host_provision_request_#{mode}" - end - - private - - def default_description - "PXE install on [#{host_name}] from image [#{get_option_last(:pxe_image_id)}]" - end -end diff --git a/app/models/miq_host_provision_workflow.rb b/app/models/miq_host_provision_workflow.rb deleted file mode 100644 index 706439d42a5..00000000000 --- a/app/models/miq_host_provision_workflow.rb +++ /dev/null @@ -1,251 +0,0 @@ -class MiqHostProvisionWorkflow < MiqRequestWorkflow - def self.base_model - MiqHostProvisionWorkflow - end - - def self.automate_dialog_request - 'UI_HOST_PROVISION_INFO' - end - - def self.default_dialog_file - 'miq_host_provision_dialogs' - end - - def self.encrypted_options_fields - [:root_password] - end - - def supports_iso? - false - end - - def make_request(request, values, requester = nil, auto_approve = false) - update_selected_storage_names(values) - super - end - - def get_source_and_targets(_refresh = false) - end - - def update_field_visibility - # Determine the visibility of fields based on current values and collect the fields - # together so we can update the dialog in one pass - - # Show/Hide Fields - f = Hash.new { |h, k| h[k] = [] } - - show_flag = get_value(@values[:addr_mode]) == 'static' ? :edit : :hide - f[show_flag] += [:hostname, :ip_addr, :subnet_mask, :gateway] - - # Update field :display value - f.each { |k, v| show_fields(k, v) } - end - - def set_default_values - super - @values[:attached_ds] = [] if @values[:attached_ds].nil? - get_source_and_targets - end - - # - # Methods for populating lists of allowed values for a field - # => Input - A hash containing options specific to the called method - # => Output - A hash with the format: => - # => New methods can be added as as needed - # - - def allowed_hosts(_options = {}) - return @allowed_hosts_cache unless @allowed_hosts_cache.nil? - - rails_logger('allowed_hosts', 0) - - host_ids = @values[:src_host_ids] - hosts = Host.where(:id => host_ids) - - @allowed_hosts_cache = hosts.collect do |h| - build_ci_hash_struct(h, [:name, :guid, :uid_ems, :ipmi_address, :mac_address]) - end - @allowed_hosts_cache - end - - def allowed_ws_hosts(_options = {}) - Host.where("mac_address is not NULL").select(&:ipmi_enabled) - end - - def allowed_ems(_options = {}) - result = {} - - ManageIQ::Providers::Vmware::InfraManager.select("id, name").each do |e| - result[e.id] = e.name - end - result - end - - def allowed_clusters(_options = {}) - ems = ExtManagementSystem.find_by(:id => get_value(@values[:placement_ems_name])) - result = {} - return result if ems.nil? - ems.ems_clusters.each { |c| result[c.id] = "#{c.v_parent_datacenter} / #{c.name}" } - result - end - - def allowed_storages(_options = {}) - result = [] - ems = ExtManagementSystem.find_by(:id => get_value(@values[:placement_ems_name])) - return result if ems.nil? - ems.storages.each do |s| - next unless s.store_type == "NFS" - s.ext_management_system = ems - result << build_ci_hash_struct(s, [:name, :free_space, :total_space]) - end - result - end - - # This is for summary screen display purposes only - def update_selected_storage_names(values) - values[:attached_ds_names] = Storage.where(:id => values[:attached_ds]).pluck(:name) - end - - def ws_template_fields(_values, fields) - data = parse_ws_string(fields) - _log.info("data:<#{data.inspect}>") - - name = data[:name].blank? ? nil : data[:name].downcase - mac_address = data[:mac_address].blank? ? nil : data[:mac_address].downcase - ipmi_address = data[:ipmi_address].blank? ? nil : data[:ipmi_address].downcase - - if name.nil? && mac_address.nil? && ipmi_address.nil? - raise _("No host search criteria values were passed. input data:<%{data}>") % {:data => data.inspect} - end - - _log.info("Host Passed : <#{name}> <#{mac_address}> <#{ipmi_address}>") - srcs = allowed_ws_hosts(:include_datacenter => true).find_all do |v| - _log.info("Host Detected: <#{v.name.downcase}> <#{v.mac_address}> <#{v.ipmi_address}>") - (name.nil? || name == v.name.downcase) && (mac_address.nil? || mac_address == v.mac_address.to_s.downcase) && (ipmi_address.nil? || ipmi_address == v.ipmi_address.to_s) - end - if srcs.length > 1 - raise _("Multiple source template were found from input data:<%{data}>") % {:data => data.inspect} - end - src = srcs.first - - raise _("No target host was found from input data:<%{data}>") % {:data => data.inspect} if src.nil? - _log.info("Host Found: <#{src.name}> MAC:<#{src.mac_address}> IPMI:<#{src.ipmi_address}>") - src - end - - def ws_host_fields(values, fields) - data = parse_ws_string(fields) - - _log.info("data:<#{data.inspect}>") - ws_service_fields(values, fields, data) - ws_environment_fields(values, fields, data) - refresh_field_values(values) - ws_customize_fields(values, fields, data) - ws_schedule_fields(values, fields, data) - - data.each { |k, v| _log.warn("Unprocessed key <#{k}> with value <#{v.inspect}>") } - end - - def ws_service_fields(values, _fields, data) - return if (dlg_fields = get_ws_dialog_fields(dialog_name = :service)).nil? - dlg_keys = dlg_fields.keys - - [[:pxe_server_id, :allowed_pxe_servers, [:name, :url], PxeServer], [:pxe_image_id, :allowed_pxe_images, [:name], nil]].each do |dlg_key, method, keys, klass| - result = ws_find_matching_ci(method, keys, data.delete(dlg_key), klass) - values[dlg_key] = result.kind_of?(Array) ? result : [result.id, result.name] unless result.nil? - end - - data.keys.each { |key| set_ws_field_value(values, key, data, dialog_name, dlg_fields) if dlg_keys.include?(key) } - end - - def ws_environment_fields(values, _fields, data) - return if (dlg_fields = get_ws_dialog_fields(dialog_name = :service)).nil? - dlg_keys = dlg_fields.keys - - [[:placement_ems_name, :allowed_ems, [:name, :hostname, :ipaddress], ExtManagementSystem]].each do |dlg_key, method, keys, klass| - result = ws_find_matching_ci(method, keys, data.delete(dlg_key), klass) - values[dlg_key] = result.kind_of?(Array) ? result : [result.id, result.name] unless result.nil? - end - - dlg_key = :placement_cluster_name - search_value = data.delete(dlg_key).to_s.downcase - values[dlg_key] = allowed_clusters.detect { |_idx, fq_name| fq_name.to_s.downcase == search_value } - - data.keys.each { |key| set_ws_field_value(values, key, data, dialog_name, dlg_fields) if dlg_keys.include?(key) } - end - - def ws_customize_fields(values, _fields, data) - return if (dlg_fields = get_ws_dialog_fields(dialog_name = :customize)).nil? - dlg_keys = dlg_fields.keys - - [[:customization_template_id, :allowed_customization_templates, [:name], nil]].each do |dlg_key, method, keys, klass| - result = ws_find_matching_ci(method, keys, data.delete(dlg_key), klass) - values[dlg_key] = result.kind_of?(Array) ? result : [result.id, result.name] unless result.nil? - end - - pwd_key = :root_password - root_pwd = data.delete(pwd_key) - unless root_pwd.blank? - values[pwd_key] = MiqPassword.try_encrypt(root_pwd) - end - - data.keys.each { |key| set_ws_field_value(values, key, data, dialog_name, dlg_fields) if dlg_keys.include?(key) } - end - - def ws_find_matching_ci(allowed_method, keys, match_str, klass) - return nil if match_str.blank? - match_str = match_str.to_s.downcase - - send(allowed_method).detect do |item| - ci = item.kind_of?(Array) ? klass.find_by(:id => item[0]) : item - keys.any? do |key| - value = ci.send(key).to_s.downcase - # _log.warn "<#{allowed_method}> - comparing <#{value}> to <#{match_str}>" - value.include?(match_str) - end - end - end - - def self.from_ws(*args) - # Move optional arguments into the MiqHashStruct object - prov_args = args[0, 6] - prov_options = MiqHashStruct.new(:values => args[6], :ems_custom_attributes => args[7], :miq_custom_attributes => args[8]) - prov_args << prov_options - MiqHostProvisionWorkflow.from_ws_ver_1_x(*prov_args) - end - - def self.from_ws_ver_1_x(version, user, template_fields, vm_fields, requester, tags, options) - options = MiqHashStruct.new if options.nil? - _log.warn("Web-service host provisioning starting with interface version <#{version}> by requester <#{user.userid}>") - - init_options = {:use_pre_dialog => false, :request_type => request_type(parse_ws_string(template_fields)[:request_type])} - data = parse_ws_string(requester) - unless data[:user_name].blank? - user = User.find_by_userid!(data[:user_name]) - _log.warn("Web-service requester changed to <#{user.userid}>") - end - - p = new(values = {}, user, init_options) - src = p.ws_template_fields(values, template_fields) - - # Populate required fields - p.init_from_dialog(values) - values[:src_host_ids] = [src.id] - p.refresh_field_values(values) - values[:placement_auto] = [true, 1] - - p.ws_host_fields(values, vm_fields) - p.ws_requester_fields(values, requester) - values[:vm_tags] = p.ws_tags(tags) # Tags are passed as category=value|cat2=value2... Example: cc=001|environment=test - values[:ws_values] = p.ws_values(options.values) - values[:ws_ems_custom_attributes] = p.ws_values(options.ems_custom_attributes, :parse_ws_string, :modify_key_name => false) - values[:ws_miq_custom_attributes] = p.ws_values(options.miq_custom_attributes, :parse_ws_string, :modify_key_name => false) - - p.make_request(nil, values, nil, values[:auto_approve]).tap do |request| - p.raise_validate_errors if request == false - end - rescue => err - _log.error("<#{err}>") - raise err - end -end # class MiqHostProvisionWorkflow diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index 8608963093a..11a28351f7f 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -64,11 +64,6 @@ class MiqRequest < ApplicationRecord :automation => N_("Automation") } }, - :Infrastructure => { - :MiqHostProvisionRequest => { - :host_pxe_install => N_("Host Provision") - }, - }, :Service => { :MiqProvisionConfiguredSystemRequest => { :provision_via_foreman => N_("%{config_mgr_type} Provision") % {:config_mgr_type => ui_lookup(:ui_title => 'foreman')} @@ -336,7 +331,7 @@ def self.workflow_class def self.request_task_class @request_task_class ||= begin case name - when 'MiqProvisionRequest', 'MiqHostProvisionRequest' + when 'MiqProvisionRequest' name.underscore.chomp('_request').camelize.constantize else name.underscore.gsub(/_request$/, "_task").camelize.constantize diff --git a/app/models/miq_request_task.rb b/app/models/miq_request_task.rb index 07dae68f7bf..2de02d79d04 100644 --- a/app/models/miq_request_task.rb +++ b/app/models/miq_request_task.rb @@ -94,8 +94,6 @@ def execute_callback(state, message, _result) def self.request_class if self <= MiqProvision MiqProvisionRequest - elsif self <= MiqHostProvision - MiqHostProvisionRequest else name.underscore.gsub(/_task$/, "_request").camelize.constantize end diff --git a/app/models/miq_request_workflow.rb b/app/models/miq_request_workflow.rb index 89cc31bc443..c6b1d71b8c9 100644 --- a/app/models/miq_request_workflow.rb +++ b/app/models/miq_request_workflow.rb @@ -1328,7 +1328,7 @@ def allowed_customization_templates(_options = {}) result = [] customization_template_id = get_value(@values[:customization_template_id]) @values[:customization_template_script] = nil if customization_template_id.nil? - prov_typ = self.class == MiqHostProvisionWorkflow ? "host" : "vm" + prov_typ = "vm" image = supports_iso? ? get_iso_image : get_pxe_image unless image.nil? result = image.customization_templates.collect do |c| @@ -1369,7 +1369,7 @@ def allowed_pxe_servers(_options = {}) def allowed_pxe_images(_options = {}) pxe_server = get_pxe_server return [] if pxe_server.nil? - prov_typ = self.class == MiqHostProvisionWorkflow ? "host" : "vm" + prov_typ = "vm" pxe_server.pxe_images.collect do |p| next if p.pxe_image_type.nil? || p.default_for_windows diff --git a/db/fixtures/miq_event_definitions.csv b/db/fixtures/miq_event_definitions.csv index 254d4038709..4e4fd617761 100644 --- a/db/fixtures/miq_event_definitions.csv +++ b/db/fixtures/miq_event_definitions.csv @@ -54,7 +54,6 @@ host_failure,Host Failure,Default,host_operations request_host_scan,Host Analysis Request,Default,host_operations host_scan_complete,Host Analysis Complete,Default,host_operations host_perf_complete,Host C & U Processing Complete,Default,host_operations -host_provisioned,Host Provision Complete,Default,host_operations host_add_to_cluster,Host Added to Cluster,Default,host_operations host_remove_from_cluster,Host Removed from Cluster,Default,host_operations host_compliance_check,Host Compliance Check,Default,compliance diff --git a/db/fixtures/miq_product_features.yml b/db/fixtures/miq_product_features.yml index 72b3edbd76e..2302338f15d 100644 --- a/db/fixtures/miq_product_features.yml +++ b/db/fixtures/miq_product_features.yml @@ -185,57 +185,6 @@ :feature_type: admin :identifier: miq_request_superadmin -# MiqRequest under Compute/Infrastructure tab for Host Requests -- :name: Requests - :description: Everything under Requests - :feature_type: node - :identifier: host_miq_request - :children: - - :name: View - :description: View Requests - :feature_type: view - :identifier: host_miq_request_view - :children: - - :name: List - :description: Display Lists of Requests - :feature_type: view - :identifier: host_miq_request_show_list - - :name: Show - :description: Display Individual Requests - :feature_type: view - :identifier: host_miq_request_show - - :name: Reload - :description: Reload Requests - :feature_type: view - :hidden: true - :identifier: host_miq_request_reload - - :name: Operate - :description: Perform Operations on Requests - :feature_type: control - :identifier: host_miq_request_control - :children: - - :name: Approve and Deny - :description: Approve and Deny Requests - :feature_type: control - :identifier: host_miq_request_approval - - :name: Modify - :description: Modify Requests - :feature_type: admin - :identifier: host_miq_request_admin - :children: - - :name: Copy - :description: Copy a Request - :feature_type: admin - :identifier: host_miq_request_copy - - :name: Delete - :description: Delete Requests - :feature_type: admin - :identifier: host_miq_request_delete - - :name: Edit - :description: Edit a Request - :feature_type: admin - :identifier: host_miq_request_edit - # MiqRequest under Automation/Automate tab for Automate Requests - :name: Requests :description: Everything under Requests @@ -1350,10 +1299,6 @@ :description: Edit a Host / Node :feature_type: admin :identifier: host_edit - - :name: Provision Hosts / Nodes - :description: Request to Provision Hosts / Nodes - :feature_type: admin - :identifier: host_miq_request_new - :name: Register Hosts / Nodes :description: Register new Hosts / Nodes :feature_type: admin diff --git a/db/fixtures/miq_shortcuts.yml b/db/fixtures/miq_shortcuts.yml index 85ab8405d48..6459b6507dd 100644 --- a/db/fixtures/miq_shortcuts.yml +++ b/db/fixtures/miq_shortcuts.yml @@ -164,11 +164,6 @@ :url: /infra_networking/explorer :rbac_feature_name: infra_networking :startup: true -- :name: miq_request_hosts - :description: Compute / Infrastructure / Requests - :url: /miq_request/show_list - :rbac_feature_name: miq_request_show_list - :startup: true - :name: infra_topology :description: Compute / Infrastructure / Topology :url: /infra_topology diff --git a/db/fixtures/notification_types.yml b/db/fixtures/notification_types.yml index 4c897f65af6..7601a31ac57 100644 --- a/db/fixtures/notification_types.yml +++ b/db/fixtures/notification_types.yml @@ -1,9 +1,4 @@ --- -- :name: host_provisioned - :message: Host %{subject} has been provisioned. - :expires_in: 7.days - :level: :success - :audience: tenant - :name: automate_service_provisioned :message: Service %{subject} has been provisioned. :expires_in: 7.days diff --git a/product/dialogs/miq_dialogs/miq_host_provision_dialogs.yaml b/product/dialogs/miq_dialogs/miq_host_provision_dialogs.yaml deleted file mode 100644 index 933322d9724..00000000000 --- a/product/dialogs/miq_dialogs/miq_host_provision_dialogs.yaml +++ /dev/null @@ -1,293 +0,0 @@ ---- -:name: miq_host_provision_dialogs -:description: Sample Host Provisioning Dialog -:dialog_type: MiqHostProvisionWorkflow -:content: - :buttons: - - :submit - - :cancel - :dialogs: - :requester: - :description: Request - :fields: - :owner_phone: - :description: Phone - :required: false - :display: :hide - :data_type: :string - :owner_country: - :description: Country/Region - :required: false - :display: :hide - :data_type: :string - :owner_phone_mobile: - :description: Mobile - :required: false - :display: :hide - :data_type: :string - :owner_title: - :description: Title - :required: false - :display: :hide - :data_type: :string - :owner_first_name: - :description: First Name - :required: false - :display: :edit - :data_type: :string - :owner_manager: - :description: Name - :required: false - :display: :edit - :data_type: :string - :owner_address: - :description: Address - :required: false - :display: :hide - :data_type: :string - :owner_company: - :description: Company - :required: false - :display: :hide - :data_type: :string - :owner_last_name: - :description: Last Name - :required: false - :display: :edit - :data_type: :string - :owner_manager_mail: - :description: E-Mail - :required: false - :display: :hide - :data_type: :string - :owner_city: - :description: City - :required: false - :display: :hide - :data_type: :string - :owner_department: - :description: Department - :required: false - :display: :hide - :data_type: :string - :owner_load_ldap: - :pressed: - :method: :retrieve_ldap - :description: Look Up LDAP Email - :required: false - :display: :show - :data_type: :button - :owner_manager_phone: - :description: Phone - :required: false - :display: :hide - :data_type: :string - :owner_state: - :description: State - :required: false - :display: :hide - :data_type: :string - :owner_office: - :description: Office - :required: false - :display: :hide - :data_type: :string - :owner_zip: - :description: Zip code - :required: false - :display: :hide - :data_type: :string - :owner_email: - :description: E-Mail - :required_method: :validate_regex - :required_regex: !ruby/regexp /\A[\w!#$\%&'*+\/=?`\{|\}~^-]+(?:\.[\w!#$\%&'*+\/=?`\{|\}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\Z/i - :required: true - :display: :edit - :data_type: :string - :request_notes: - :description: Notes - :required: false - :display: :edit - :data_type: :string - :display: :show - :field_order: - :purpose: - :description: Purpose - :fields: - :vm_tags: - :required_method: :validate_tags - :description: Tags - :required: false - :options: - :include: [] - - :order: [] - - :single_select: [] - - :exclude: [] - - :display: :edit - :required_tags: [] - - :data_type: :integer - :display: :show - :field_order: - :customize: - :description: Customize - :fields: - :dns_servers: - :description: DNS Server list - :required: false - :display: :edit - :data_type: :string - :dns_suffixes: - :description: DNS Suffix list - :required: false - :display: :edit - :data_type: :string - :root_password: - :description: Root Password - :required: false - :display: :edit - :data_type: :string - :customization_template_id: - :values_from: - :method: :allowed_customization_templates - :auto_select_single: false - :description: Script Name - :required: false - :display: :edit - :data_type: :integer - :addr_mode: - :values: - static: Static - dhcp: DHCP - :description: Address Mode - :required: false - :display: :hide - :default: static - :data_type: :string - :gateway: - :description: Gateway - :required: false - :display: :edit - :data_type: :string - :hostname: - :description: Host Name - :required: false - :display: :edit - :data_type: :string - :ip_addr: - :description: IP Address - :required: false - :notes: (Enter starting IP address) - :display: :edit - :data_type: :string - :notes_display: :hide - :customization_template_script: - :description: Script Text - :required: false - :display: :edit - :data_type: :string - :subnet_mask: - :description: Subnet Mask - :required: false - :display: :edit - :data_type: :string - :display: :show - :environment: - :description: Environment - :fields: - :placement_cluster_name: - :values_from: - :method: :allowed_clusters - :auto_select_single: false - :description: Name - :required: false - :display: :edit - :data_type: :integer - :placement_ems_name: - :values_from: - :method: :allowed_ems - :auto_select_single: false - :description: Name - :required: false - :display: :edit - :data_type: :integer - :attached_ds: - :values_from: - :method: :allowed_storages - :auto_select_single: false - :description: Name - :required: false - :display: :edit - :data_type: :integer - :display: :show - :service: - :description: Catalog - :fields: - :pxe_image_id: - :values_from: - :method: :allowed_images - :auto_select_single: false - :description: Image - :required: true - :display: :edit - :data_type: :string - :pxe_server_id: - :values_from: - :method: :allowed_pxe_servers - :auto_select_single: false - :description: Server - :required: true - :display: :edit - :data_type: :integer - :src_host_ids: - :values_from: - :method: :allowed_hosts - :description: Name - :required: true - :notes: - :display: :show - :data_type: :integer - :notes_display: :show - :display: :show - :schedule: - :description: Schedule - :fields: - :schedule_type: - :values: - schedule: Schedule - immediately: Immediately on Approval - :description: When to Provision - :required: false - :display: :edit - :default: immediately - :data_type: :string - :schedule_time: - :values_from: - :options: - :offset: 1.day - :method: :default_schedule_time - :description: Provision on - :required: false - :display: :edit - :data_type: :time - :stateless: - :values: - false: 0 - true: 1 - :description: Stateless - :required: false - :display: :edit - :default: false - :data_type: :boolean - :display: :show - :dialog_order: - - :requester - - :purpose - - :service - - :environment - - :customize - - :schedule diff --git a/spec/factories/miq_dialog.rb b/spec/factories/miq_dialog.rb index 489ba759efc..b6248b4dc3a 100644 --- a/spec/factories/miq_dialog.rb +++ b/spec/factories/miq_dialog.rb @@ -28,11 +28,6 @@ end end - factory :miq_dialog_host_provision, :parent => :miq_dialog do - name "miq_host_provision_dialogs" - dialog_type "MiqHostProvisionWorkflow" - end - factory :miq_provision_configured_system_foreman_dialog, :parent => :miq_dialog do name "miq_provision_configured_system_foreman_dialogs" dialog_type "MiqProvisionConfiguredSystemWorkflow" diff --git a/spec/factories/miq_request.rb b/spec/factories/miq_request.rb index f41b25e27a4..b65a4f1a32c 100644 --- a/spec/factories/miq_request.rb +++ b/spec/factories/miq_request.rb @@ -6,7 +6,6 @@ request_type "automation" end - factory :miq_host_provision_request, :class => "MiqHostProvisionRequest" factory :service_reconfigure_request, :class => "ServiceReconfigureRequest" factory :service_template_provision_request, :class => "ServiceTemplateProvisionRequest" do source { create(:service_template) } diff --git a/spec/factories/miq_request_task.rb b/spec/factories/miq_request_task.rb index de98dfb5698..d2e623e6b3e 100644 --- a/spec/factories/miq_request_task.rb +++ b/spec/factories/miq_request_task.rb @@ -7,9 +7,6 @@ factory :miq_provision_task, :parent => :miq_request_task, :class => "MiqProvisionTask" factory :miq_provision, :parent => :miq_provision_task, :class => "MiqProvision" - # Bare Metal - factory :miq_host_provision, :parent => :miq_request_task, :class => "MiqHostProvision" - # Infra factory :miq_provision_microsoft, :parent => :miq_provision, :class => "ManageIQ::Providers::Microsoft::InfraManager::Provision" factory :miq_provision_redhat, :parent => :miq_provision, :class => "ManageIQ::Providers::Redhat::InfraManager::Provision" diff --git a/spec/lib/rbac/filterer_spec.rb b/spec/lib/rbac/filterer_spec.rb index 81de983cf32..f5271c000a1 100644 --- a/spec/lib/rbac/filterer_spec.rb +++ b/spec/lib/rbac/filterer_spec.rb @@ -624,7 +624,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "with accessible_tenant_ids filtering (strategy = :descendants_id) through" do it "can see their own request in the same tenant" do - request = FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user) + request = FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :user => owner_user).first expect(results).to match_array [request] end @@ -635,7 +635,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt child_group.entitlement.set_belongsto_filters([]) child_group.save! - request = FactoryGirl.create(:miq_host_provision_request, :tenant => child_tenant, :requester => child_user) + request = FactoryGirl.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) results = described_class.search(:class => "MiqRequest", :user => child_user).first expect(results).to match_array [request] end @@ -644,19 +644,19 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt group = FactoryGirl.create(:miq_group, :tenant => owner_tenant) user = FactoryGirl.create(:user, :miq_groups => [group]) - request = FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user) + request = FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :user => user).first expect(results).to match_array [request] end it "can't see parent tenant's request" do - FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user) + FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :miq_group => child_group).first expect(results).to match_array [] end it "can see descendant tenant's request" do - request = FactoryGirl.create(:miq_host_provision_request, :tenant => child_tenant, :requester => child_user) + request = FactoryGirl.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) results = described_class.search(:class => "MiqRequest", :miq_group => owner_group).first expect(results).to match_array [request] end diff --git a/spec/models/miq_dialog_spec.rb b/spec/models/miq_dialog_spec.rb index 13810e0bb62..27b90852379 100644 --- a/spec/models/miq_dialog_spec.rb +++ b/spec/models/miq_dialog_spec.rb @@ -7,7 +7,7 @@ expect(described_class).to receive(:sync_from_file).at_least(:once).with(/^#{root}/, root).and_call_original expect(described_class).to receive(:find_by).once.with( - :name => "miq_host_provision_dialogs", :filename => "miq_host_provision_dialogs.yaml" + :name => "miq_provision_dialogs", :filename => "miq_provision_dialogs.yaml" ) described_class.seed diff --git a/spec/models/miq_host_provision_request_spec.rb b/spec/models/miq_host_provision_request_spec.rb deleted file mode 100644 index 380ca8de761..00000000000 --- a/spec/models/miq_host_provision_request_spec.rb +++ /dev/null @@ -1,208 +0,0 @@ -describe MiqHostProvisionRequest do - it "validates a requester is specified" do - expect { FactoryGirl.create(:miq_host_provision_request, :requester => nil) }.to raise_error(ActiveRecord::RecordInvalid) - end - - context "with a valid userid and host," do - before do - @user = FactoryGirl.create(:user, :role => "admin") - # approver is also an admin - @approver = FactoryGirl.create(:user_miq_request_approver, :miq_groups => @user.miq_groups) - - @pr = FactoryGirl.create(:miq_host_provision_request, :requester => @user) - end - - it "should create an MiqHostProvisionRequest" do - expect(MiqHostProvisionRequest.all).to eq([@pr]) - expect(@pr).to be_valid - expect(@pr).not_to be_approved - end - - it "should create a valid MiqRequest" do - expect(@pr.miq_request).to eq(MiqRequest.first) - expect(@pr.miq_request.valid?).to be_truthy - expect(@pr.miq_request.approval_state).to eq("pending_approval") - expect(@pr.miq_request.resource).to eq(@pr) - expect(@pr.miq_request.requester_userid).to eq(@user.userid) - expect(@pr.miq_request.stamped_on).to be_nil - - expect(@pr.miq_request).not_to be_approved - expect(MiqApproval.all).to eq([@pr.miq_request.first_approval]) - end - - it "should return a workflow class" do - expect(@pr.workflow_class).to eq(MiqHostProvisionWorkflow) - end - - context "when calling call_automate_event_queue" do - before do - EvmSpecHelper.local_miq_server(:zone => Zone.seed) - @pr.miq_request.call_automate_event_queue("request_created") - end - - it "should create proper MiqQueue item" do - expect(MiqQueue.count).to eq(1) - q = MiqQueue.first - expect(q.class_name).to eq(@pr.miq_request.class.name) - expect(q.instance_id).to eq(@pr.miq_request.id) - expect(q.method_name).to eq("call_automate_event") - expect(q.args).to eq(%w(request_created)) - expect(q.zone).to eq("default") - end - end - - context "after MiqRequest is deleted," do - before do - @pr.miq_request.destroy - end - - it "should delete MiqHostProvisionRequest" do - expect(MiqHostProvisionRequest.count).to eq(0) - end - - it "should delete MiqApproval" do - expect(MiqApproval.count).to eq(0) - end - - it "should not delete Approver" do - expect { @approver.reload }.not_to raise_error - end - end - - context "when processing tags" do - before do - FactoryGirl.create(:classification_department_with_tags) - end - - it "should add and delete tags from a request" do - expect(@pr.get_tags.length).to eq(0) - - t = Classification.where(:description => 'Department', :parent_id => 0).includes(:tag).first - @pr.add_tag(t.name, t.children.first.name) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(String) # Single tag returns as a String - expect(@pr.get_tags[t.name.to_sym]).to eq(t.children.first.name) - - # Adding the same tag again should not increase the tag count - @pr.add_tag(t.name, t.children.first.name) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(String) # Single tag returns as a String - expect(@pr.get_tags[t.name.to_sym]).to eq(t.children.first.name) - - # Verify that #get_tag with classification returns the single child tag name - expect(@pr.get_tags[t.name.to_sym]).to eq(@pr.get_tag(t.name)) - - t.children.each { |c| @pr.add_tag(t.name, c.name) } - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(Array) - expect(@pr.get_tags[t.name.to_sym].length).to eq(t.children.length) - - child_names = t.children.collect(&:name) - # Make sure each child name is yield from the tag method - @pr.tags { |tag_name, _classification| child_names.delete(tag_name) } - expect(child_names).to be_empty - - tags = @pr.get_classification(t.name) - expect(tags).to be_kind_of(Array) - classification = tags.first - expect(classification).to be_kind_of(Hash) - expect(classification.keys).to include(:name) - expect(classification.keys).to include(:description) - - child_names = t.children.collect(&:name) - - @pr.clear_tag(t.name, child_names[0]) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(Array) # Multiple tags return as an Array - expect(@pr.get_tags[t.name.to_sym].length).to eq(t.children.length - 1) - - @pr.clear_tag(t.name, child_names[1]) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(String) # Single tag returns as a String - expect(@pr.get_tags[t.name.to_sym]).to eq(child_names[2]) - - @pr.clear_tag(t.name) - expect(@pr.get_tags[t.name.to_sym]).to be_nil # No tags returns as nil - expect(@pr.get_tags.length).to eq(0) - end - - it "should return classifications for tags" do - expect(@pr.get_tags.length).to eq(0) - - t = Classification.where(:description => 'Department', :parent_id => 0).includes(:tag).first - @pr.add_tag(t.name, t.children.first.name) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(String) - - classification = @pr.get_classification(t.name) - expect(classification).to be_kind_of(Hash) - expect(classification.keys).to include(:name) - expect(classification.keys).to include(:description) - - @pr.add_tag(t.name, t.children[1].name) - expect(@pr.get_tags[t.name.to_sym]).to be_kind_of(Array) - - classification = @pr.get_classification(t.name) - expect(classification).to be_kind_of(Array) - first = classification.first - expect(first.keys).to include(:name) - expect(first.keys).to include(:description) - end - end - end - - context "#placement_ems" do - it "finds placement_ems" do - ems = FactoryGirl.create(:ext_management_system) - expect(request(:options => {:placement_ems_name => [ems.id, 'name']}).placement_ems).to eq(ems) - end - - it "handles nothing defined" do - expect(request.placement_ems).not_to be - end - end - - context "#placement_cluster" do - it "finds placement_cluster" do - cluster = FactoryGirl.create(:ems_cluster) - expect(request(:options => {:placement_cluster_name => [cluster.id, 'name']}).placement_cluster).to eq(cluster) - end - - it "handles nothing defined" do - expect(request.placement_cluster).not_to be - end - end - - context "#placement_folder" do - it "finds placement_folder" do - folder = FactoryGirl.create(:ems_folder) - expect(request(:options => {:placement_folder_name => [folder.id, 'name']}).placement_folder).to eq(folder) - end - - it "handles nothing defined" do - expect(request.placement_folder).not_to be - end - end - - context "#pxe_server" do - it "finds pxe_server" do - pxe_server = FactoryGirl.create(:pxe_server) - expect(request(:options => {:pxe_server_id => [pxe_server.id, 'name']}).pxe_server).to eq(pxe_server) - end - - it "handles nothing defined" do - expect(request.pxe_server).not_to be - end - end - - context "#pxe_image" do - it "finds pxe_image" do - pxe_image = FactoryGirl.create(:pxe_image) - expect(request(:options => {:pxe_image_id => [pxe_image.id, 'name']}).pxe_image).to eq(pxe_image) - end - - it "handles nothing defined" do - expect(request.pxe_image).not_to be - end - end - - private - - def request(params = {}) - FactoryGirl.create(:miq_host_provision_request, params.merge(:requester => FactoryGirl.create(:user))) - end -end diff --git a/spec/models/miq_host_provision_spec.rb b/spec/models/miq_host_provision_spec.rb deleted file mode 100644 index d880003f6ac..00000000000 --- a/spec/models/miq_host_provision_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -describe MiqHostProvision do - it "#host_name" do - host_name = "fred" - host = FactoryGirl.create(:host, :name => host_name) - mhp = MiqHostProvision.create(:host => host) - expect(mhp.host_name).to eq(host_name) - end - - it "#host_rediscovered?" do - pxe_image_type = FactoryGirl.create(:pxe_image_type, :name => 'esx') - pxe_image = FactoryGirl.create(:pxe_image, :pxe_image_type => pxe_image_type) - - mhp = MiqHostProvision.create - allow(mhp).to receive(:pxe_image).and_return(pxe_image) - expect(mhp.host_rediscovered?).to be_falsey - - mhp.host = FactoryGirl.create(:host, :vmm_vendor => 'unknown') - expect(mhp.host_rediscovered?).to be_falsey - - mhp.host.vmm_vendor = 'vmware' - expect(mhp.host_rediscovered?).to be_truthy - end - - context "with default server and zone" do - before do - @miq_server = EvmSpecHelper.local_miq_server - end - - context "with host and miq_host_provision" do - let(:host) { FactoryGirl.create(:host_vmware_esx, :name => 'fred') } - let(:mhp) { MiqHostProvision.create(:host => host) } - - it "#reset_host_credentials" do - password = 'secret' - allow(mhp).to receive(:get_option).with(:root_password).and_return(password) - expect(mhp).to receive(:signal).with(:create_pxe_configuration_files) - mhp.reset_host_credentials - expect(mhp.host.authentications.length).to eq(1) - expect(mhp.host.authentication_userid(:default)).to eq('root') - expect(mhp.host.authentication_password(:default)).to eq(password) - end - - it "#reset_host_in_vmdb" do - ipmi_userid = 'ipmi_user' - ipmi_password = 'ipmi_password' - default_userid = 'default_user' - default_password = 'default_password' - dialog_userid = 'root' - dialog_password = 'dialog_password' - ipmi_address = '123.211.21.1' - - host.update_attributes(:ipmi_address => ipmi_address, :operating_system => FactoryGirl.create(:operating_system)) - host.update_authentication(:ipmi => {:userid => ipmi_userid, :password => ipmi_password}) - host.update_authentication(:default => {:userid => default_userid, :password => default_password}) - - expect(mhp.host).to be_kind_of(ManageIQ::Providers::Vmware::InfraManager::HostEsx) - allow(mhp).to receive(:get_option).with(:root_password).and_return(dialog_password) - expect(mhp).to receive(:signal).with(:reset_host_credentials) - mhp.reset_host_in_vmdb - - expect(mhp.host).to be_kind_of(Host) - expect(mhp.host.operating_system).to be_nil - - expect(mhp.host.authentications.length).to eq(2) - expect(mhp.host.authentication_userid(:ipmi)).to eq(ipmi_userid) - expect(mhp.host.authentication_password(:ipmi)).to eq(ipmi_password) - - expect(mhp.host.authentication_userid(:default)).to eq(dialog_userid) - expect(mhp.host.authentication_password(:default)).to eq(dialog_password) - end - - it "#provision_completed" do - expect(mhp).to receive(:signal).with(:post_install_callback) - mhp.provision_completed - end - - it "#post_install_callback" do - expect(mhp).to receive(:update_and_notify_parent) - expect(mhp).to receive(:signal).with(:delete_pxe_configuration_files) - mhp.post_install_callback - end - end - end -end diff --git a/spec/models/miq_host_provision_workflow_spec.rb b/spec/models/miq_host_provision_workflow_spec.rb deleted file mode 100644 index 35a805fc56a..00000000000 --- a/spec/models/miq_host_provision_workflow_spec.rb +++ /dev/null @@ -1,104 +0,0 @@ -silence_warnings { MiqHostProvisionWorkflow.const_set("DIALOGS_VIA_AUTOMATE", false) } - -describe MiqHostProvisionWorkflow do - let(:user) { FactoryGirl.create(:user_with_group) } - include Spec::Support::WorkflowHelper - - context "seeded" do - context "After setup," do - before do - @server = EvmSpecHelper.local_miq_server - - FactoryGirl.create(:user_admin) - - @template_fields = {'mac_address' => 'aa:bb:cc:dd:ee:ff', 'ipmi_address' => '127.0.0.1'} - @requester = {'owner_email' => 'tester@miq.com', 'owner_first_name' => 'tester', 'owner_last_name' => 'tester'} - @host_fields = {'pxe_server_id' => '127.0.0.1', 'pxe_image_id' => 'ESXi 4.1-260247', - 'root_password' => 'smartvm', 'addr_mode' => 'dhcp'} - - FactoryGirl.create(:miq_dialog_host_provision) - end - - context "Without a Valid IPMI Host," do - it "should not create an MiqRequest when calling from_ws" do - lambda do - expect(MiqHostProvisionWorkflow.from_ws("1.1", user, @template_fields, @host_fields, @requester, false, nil, nil)) - .to raise_error(RuntimeError) - end - end - end - - context "With a Valid IPMI Host," do - before do - ems = FactoryGirl.create(:ems_vmware, :name => "Test EMS", :zone => @server.zone) - FactoryGirl.create(:host_with_ipmi, :ext_management_system => ems) - pxe_server = FactoryGirl.create(:pxe_server, - :name => 'PXE on 127.0.0.1', - :uri_prefix => 'nfs', - :uri => 'nfs://127.0.0.1/srv/tftpboot') - FactoryGirl.create(:pxe_image, - :name => 'VMware ESXi 4.1-260247', - :pxe_server => pxe_server - ) - end - - it "should create an MiqRequest when calling from_ws" do - request = MiqHostProvisionWorkflow.from_ws("1.1", user, - @template_fields, - @host_fields, - @requester, false, nil, nil) - expect(request).to be_a_kind_of(MiqRequest) - request.options - end - end - end - end - - describe "#make_request" do - let(:host) { FactoryGirl.create(:host) } - let(:admin) { FactoryGirl.create(:user_with_group) } - let(:alt_user) { FactoryGirl.create(:user_with_group) } - it "creates and update a request" do - EvmSpecHelper.local_miq_server - stub_dialog(:get_pre_dialogs) - stub_dialog(:get_dialogs) - - # if running_pre_dialog is set, it will run 'continue_request' - workflow = described_class.new(values = {:running_pre_dialog => false}, admin) - - expect(AuditEvent).to receive(:success).with( - :event => "host_provision_request_created", - :target_class => "Host", - :userid => admin.userid, - :message => "Host Provisioning requested by <#{admin.userid}> for Host:#{[host.id].inspect}" - ) - - # creates a request - - # the dialogs populate this - values.merge!(:src_host_ids => [host.id], :vm_tags => []) - - request = workflow.make_request(nil, values) - - expect(request).to be_valid - expect(request).to be_a_kind_of(MiqHostProvisionRequest) - expect(request.request_type).to eq("host_pxe_install") - expect(request.description).to eq("PXE install on [#{host.name}] from image []") - expect(request.requester).to eq(admin) - expect(request.userid).to eq(admin.userid) - expect(request.requester_name).to eq(admin.name) - - # updates a request - - workflow = described_class.new(values, alt_user) - - expect(AuditEvent).to receive(:success).with( - :event => "host_provision_request_updated", - :target_class => "Host", - :userid => alt_user.userid, - :message => "Host Provisioning request updated by <#{alt_user.userid}> for Host:#{[host.id].inspect}" - ) - workflow.make_request(request, values) - end - end -end diff --git a/spec/models/miq_request_spec.rb b/spec/models/miq_request_spec.rb index b643119bb42..226d547886f 100644 --- a/spec/models/miq_request_spec.rb +++ b/spec/models/miq_request_spec.rb @@ -7,7 +7,6 @@ expected_request_types = { :MiqProvisionRequest => {:template => "VM Provision", :clone_to_vm => "VM Clone", :clone_to_template => "VM Publish"}, :MiqProvisionRequestTemplate => {:template => "VM Provision Template"}, - :MiqHostProvisionRequest => {:host_pxe_install => "Host Provision"}, :MiqProvisionConfiguredSystemRequest => {:provision_via_foreman => "#{ui_lookup(:ui_title => 'foreman')} Provision"}, :VmReconfigureRequest => {:vm_reconfigure => "VM Reconfigure"}, :VmCloudReconfigureRequest => {:vm_cloud_reconfigure => "VM Cloud Reconfigure"}, @@ -28,7 +27,7 @@ context "A new request" do let(:event_name) { "hello" } - let(:host_request) { FactoryGirl.build(:miq_host_provision_request, :options => {:src_host_ids => [1]}) } + let(:miq_request) { FactoryGirl.build(:automation_request, :options => {:src_ids => [1]}) } let(:request) { FactoryGirl.create(:vm_migrate_request, :requester => fred) } let(:ems) { FactoryGirl.create(:ems_vmware) } let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => ems) } @@ -42,24 +41,24 @@ context "#set_description" do it "should set a description when nil" do - expect(host_request.description).to be_nil - expect(host_request).to receive(:update_attributes).with(:description => "PXE install on [] from image []") + expect(miq_request.description).to be_nil + expect(miq_request).to receive(:update_attributes).with(:description => "Automation Task") - host_request.set_description + miq_request.set_description end it "should not set description when one exists" do - host_request.description = "test description" - host_request.set_description + miq_request.description = "test description" + miq_request.set_description - expect(host_request.description).to eq("test description") + expect(miq_request.description).to eq("test description") end it "should set description when :force => true" do - host_request.description = "test description" - expect(host_request).to receive(:update_attributes).with(:description => "PXE install on [] from image []") + miq_request.description = "test description" + expect(miq_request).to receive(:update_attributes).with(:description => "Automation Task") - host_request.set_description(true) + miq_request.set_description(true) end end diff --git a/spec/models/miq_request_task/post_install_callback_spec.rb b/spec/models/miq_request_task/post_install_callback_spec.rb index 26ec7718fd5..aa8136fe7c9 100644 --- a/spec/models/miq_request_task/post_install_callback_spec.rb +++ b/spec/models/miq_request_task/post_install_callback_spec.rb @@ -1,5 +1,5 @@ describe MiqRequestTask::PostInstallCallback do - let(:miq_request) { FactoryGirl.build(:miq_host_provision_request, :requester => user) } + let(:miq_request) { FactoryGirl.build(:miq_provision_request, :requester => user) } let(:task) { FactoryGirl.create(:miq_request_task, :miq_request => miq_request) } let(:user) { FactoryGirl.build(:user) }