diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cc287e6429e..78fce182fa2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -275,14 +275,14 @@ Naming/MethodName: - 'app/controllers/hosts_controller.rb' - 'app/helpers/form_helper.rb' - 'app/models/concerns/orchestration/compute.rb' - - 'app/models/concerns/orchestration/puppetca.rb' + - 'app/models/concerns/orchestration/puppet_ca.rb' - 'app/models/concerns/orchestration/ssh_provision.rb' - 'app/models/concerns/orchestration/tftp.rb' - 'app/models/environment.rb' - 'app/models/host/managed.rb' - 'app/models/hostgroup.rb' - 'app/services/proxy_api/tftp.rb' - - 'lib/net/dhcp/record.rb' + - 'app/lib/net/dhcp/record.rb' - 'test/controllers/api/v2/table_preferences_controller_test.rb' - 'test/helpers/fact_values_helper_test.rb' - 'test/models/orchestration_test.rb' @@ -434,7 +434,7 @@ Rails/IndexBy: Rails/IndexWith: Exclude: - 'app/controllers/hosts_controller.rb' - - 'app/models/concerns/audit_associations.rb' + - 'lib/audit_associations/associations_changes.rb' - 'app/models/smart_proxy.rb' - 'test/active_support_test_case_helper.rb' - 'test/factories/smart_proxy.rb' diff --git a/app/controllers/api/v2/autosign_controller.rb b/app/controllers/api/v2/autosign_controller.rb index 144f3b15b27..b5036e0bf69 100644 --- a/app/controllers/api/v2/autosign_controller.rb +++ b/app/controllers/api/v2/autosign_controller.rb @@ -33,7 +33,7 @@ def destroy private def setup_proxy - @api = ProxyAPI::Puppetca.new({:url => @nested_obj.url}) + @api = ProxyAPI::PuppetCA.new({:url => @nested_obj.url}) end def allowed_nested_id diff --git a/app/controllers/api/v2/interfaces_controller.rb b/app/controllers/api/v2/interfaces_controller.rb index 48ed3a2e16f..1cb0820c288 100644 --- a/app/controllers/api/v2/interfaces_controller.rb +++ b/app/controllers/api/v2/interfaces_controller.rb @@ -1,5 +1,3 @@ -require_dependency File.join(Rails.root, "app/models/nic/base") - module Api module V2 class InterfacesController < V2::BaseController diff --git a/app/helpers/bmc_helper.rb b/app/helpers/bmc_helper.rb index b714fc60c88..56f384ddfad 100644 --- a/app/helpers/bmc_helper.rb +++ b/app/helpers/bmc_helper.rb @@ -1,4 +1,4 @@ -module BmcHelper +module BMCHelper def power_status(s) case s.try(:downcase) when 'on' diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb index 65b3052c657..ef2ab6ad642 100644 --- a/app/helpers/hosts_helper.rb +++ b/app/helpers/hosts_helper.rb @@ -3,7 +3,7 @@ module HostsHelper include HostsAndHostgroupsHelper include ComputeResourcesVmsHelper include HostsNicHelper - include BmcHelper + include BMCHelper include AuthorizeHelper def provider_partial_exist?(compute_resource, partial) diff --git a/app/models/concerns/audit_associations.rb b/app/lib/audit_associations/associations_definitions.rb similarity index 54% rename from app/models/concerns/audit_associations.rb rename to app/lib/audit_associations/associations_definitions.rb index 0b88a940ac6..e41ae5fc462 100644 --- a/app/models/concerns/audit_associations.rb +++ b/app/lib/audit_associations/associations_definitions.rb @@ -1,38 +1,4 @@ module AuditAssociations - module AssociationsChanges - def changes_to_save - super.merge(associated_changes) - end - - def audited_attributes - super.merge(associated_attributes) - end - - protected - - # Prevent associations from being set when looking at revisions since - # otherwise they will update the original object rather then the revision - def revision_with(attrs) - super(attrs.reject { |k, v| k.to_s.ends_with?('_ids') }) - end - - private - - def associated_changes - audited_options[:associations].each_with_object({}) do |association, changes| - if public_send("#{association}_changed?") - changes[association] = public_send("#{association}_change") - end - end - end - - def associated_attributes - audited_options[:associations].each_with_object({}) do |association, attributes| - attributes[association] = public_send(association) - end - end - end - module AssociationsDefinitions def audited(options = {}) options[:associations] = normalize_associations(options[:associations]) diff --git a/lib/foreman/http_proxy.rb b/app/lib/foreman/http_proxy.rb similarity index 86% rename from lib/foreman/http_proxy.rb rename to app/lib/foreman/http_proxy.rb index 2514c2b6d8a..9e6ee57524d 100644 --- a/lib/foreman/http_proxy.rb +++ b/app/lib/foreman/http_proxy.rb @@ -1,5 +1,5 @@ module Foreman - module HTTPProxy + module HttpProxy def http_proxy ActiveRecord::Base.connection_pool.with_connection do Setting[:http_proxy].presence @@ -64,7 +64,3 @@ def http_host_excepted?(host) end end end - -require_dependency File.expand_path('http_proxy/excon_connection_extension', __dir__) -require_dependency File.expand_path('http_proxy/net_http_ext', __dir__) -require_dependency File.expand_path('http_proxy/rest_client_extension', __dir__) diff --git a/lib/foreman/http_proxy/excon_connection_extension.rb b/app/lib/foreman/http_proxy/excon_connection_extension.rb similarity index 95% rename from lib/foreman/http_proxy/excon_connection_extension.rb rename to app/lib/foreman/http_proxy/excon_connection_extension.rb index 1338318f82b..209c00b117f 100644 --- a/lib/foreman/http_proxy/excon_connection_extension.rb +++ b/app/lib/foreman/http_proxy/excon_connection_extension.rb @@ -18,6 +18,6 @@ def request(params, &block) end Excon::Connection.class_eval do - include Foreman::HTTPProxy + include Foreman::HttpProxy prepend Foreman::HttpProxy::ExconConnectionExtension end diff --git a/lib/foreman/http_proxy/net_http_ext.rb b/app/lib/foreman/http_proxy/net_http_ext.rb similarity index 93% rename from lib/foreman/http_proxy/net_http_ext.rb rename to app/lib/foreman/http_proxy/net_http_ext.rb index 7f27b4695ab..bc1fe980849 100644 --- a/lib/foreman/http_proxy/net_http_ext.rb +++ b/app/lib/foreman/http_proxy/net_http_ext.rb @@ -1,7 +1,7 @@ module Foreman module HttpProxy class NetHttpExt < Net::HTTP - include Foreman::HTTPProxy + include Foreman::HttpProxy def proxy? !!proxy_uri diff --git a/lib/foreman/http_proxy/rest_client_extension.rb b/app/lib/foreman/http_proxy/rest_client_extension.rb similarity index 96% rename from lib/foreman/http_proxy/rest_client_extension.rb rename to app/lib/foreman/http_proxy/rest_client_extension.rb index c5751210f5b..141945fa2d5 100644 --- a/lib/foreman/http_proxy/rest_client_extension.rb +++ b/app/lib/foreman/http_proxy/rest_client_extension.rb @@ -26,6 +26,6 @@ def net_http_object(hostname, port) end RestClient::Request.class_eval do - include Foreman::HTTPProxy + include Foreman::HttpProxy prepend Foreman::HttpProxy::RestClientExtension end diff --git a/app/lib/net/dhcp.rb b/app/lib/net/dhcp.rb new file mode 100644 index 00000000000..ddbd0054a5b --- /dev/null +++ b/app/lib/net/dhcp.rb @@ -0,0 +1,4 @@ +module Net + module DHCP + end +end diff --git a/lib/net/dhcp/record.rb b/app/lib/net/dhcp/record.rb similarity index 100% rename from lib/net/dhcp/record.rb rename to app/lib/net/dhcp/record.rb diff --git a/lib/net/dhcp/sparc_record.rb b/app/lib/net/dhcp/sparc_record.rb similarity index 100% rename from lib/net/dhcp/sparc_record.rb rename to app/lib/net/dhcp/sparc_record.rb diff --git a/lib/net/dhcp/ztp_record.rb b/app/lib/net/dhcp/ztp_record.rb similarity index 100% rename from lib/net/dhcp/ztp_record.rb rename to app/lib/net/dhcp/ztp_record.rb diff --git a/lib/net/dns.rb b/app/lib/net/dns.rb similarity index 89% rename from lib/net/dns.rb rename to app/lib/net/dns.rb index ca0a1a95e5e..6627bd2f16e 100644 --- a/lib/net/dns.rb +++ b/app/lib/net/dns.rb @@ -4,13 +4,6 @@ module Net module DNS - autoload :ForwardRecord, "net/dns/forward_record.rb" - autoload :ARecord, "net/dns/a_record.rb" - autoload :AAAARecord, "net/dns/aaaa_record.rb" - autoload :ReverseRecord, "net/dns/reverse_record.rb" - autoload :PTR4Record, "net/dns/ptr4_record.rb" - autoload :PTR6Record, "net/dns/ptr6_record.rb" - # Looks up the IP or MAC address. Handles the conversion of a DNS miss # exception into nil # [+query+]: IP or hostname diff --git a/lib/net/dns/a_record.rb b/app/lib/net/dns/a_record.rb similarity index 100% rename from lib/net/dns/a_record.rb rename to app/lib/net/dns/a_record.rb diff --git a/lib/net/dns/aaaa_record.rb b/app/lib/net/dns/aaaa_record.rb similarity index 100% rename from lib/net/dns/aaaa_record.rb rename to app/lib/net/dns/aaaa_record.rb diff --git a/lib/net/dns/forward_record.rb b/app/lib/net/dns/forward_record.rb similarity index 100% rename from lib/net/dns/forward_record.rb rename to app/lib/net/dns/forward_record.rb diff --git a/lib/net/dns/ptr4_record.rb b/app/lib/net/dns/ptr_4_record.rb similarity index 100% rename from lib/net/dns/ptr4_record.rb rename to app/lib/net/dns/ptr_4_record.rb diff --git a/lib/net/dns/ptr6_record.rb b/app/lib/net/dns/ptr_6_record.rb similarity index 100% rename from lib/net/dns/ptr6_record.rb rename to app/lib/net/dns/ptr_6_record.rb diff --git a/lib/net/dns/reverse_record.rb b/app/lib/net/dns/reverse_record.rb similarity index 100% rename from lib/net/dns/reverse_record.rb rename to app/lib/net/dns/reverse_record.rb diff --git a/lib/net.rb b/app/lib/net/record.rb similarity index 95% rename from lib/net.rb rename to app/lib/net/record.rb index 6ba08d337f4..49629ff5c23 100644 --- a/lib/net.rb +++ b/app/lib/net/record.rb @@ -1,5 +1,3 @@ -require_dependency "net/validations" - module Net class Record attr_accessor :hostname, :proxy, :logger diff --git a/lib/net/validations.rb b/app/lib/net/validations.rb similarity index 100% rename from lib/net/validations.rb rename to app/lib/net/validations.rb diff --git a/app/models/compute_resources/foreman/model/vmware.rb b/app/models/compute_resources/foreman/model/vmware.rb index bea826c8aa6..967af05d0d9 100644 --- a/app/models/compute_resources/foreman/model/vmware.rb +++ b/app/models/compute_resources/foreman/model/vmware.rb @@ -1,4 +1,3 @@ -require 'fog_extensions/vsphere/mini_servers' require 'foreman/exception' begin diff --git a/app/models/concerns/dns_interface.rb b/app/models/concerns/dns_interface.rb index bd53e3c7197..f6dc9b0098e 100644 --- a/app/models/concerns/dns_interface.rb +++ b/app/models/concerns/dns_interface.rb @@ -1,4 +1,4 @@ -module DnsInterface +module DNSInterface extend ActiveSupport::Concern RECORD_TYPES = [:a, :aaaa, :ptr4, :ptr6] diff --git a/app/models/concerns/facets/base.rb b/app/models/concerns/facets/base.rb index 52fc73b9ce9..0b1af2109f2 100644 --- a/app/models/concerns/facets/base.rb +++ b/app/models/concerns/facets/base.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module Base extend ActiveSupport::Concern diff --git a/app/models/concerns/facets/base_host_extensions.rb b/app/models/concerns/facets/base_host_extensions.rb index a3cc77a2f89..121c97f2119 100644 --- a/app/models/concerns/facets/base_host_extensions.rb +++ b/app/models/concerns/facets/base_host_extensions.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module BaseHostExtensions extend ActiveSupport::Concern diff --git a/app/models/concerns/facets/hostgroup_extensions.rb b/app/models/concerns/facets/hostgroup_extensions.rb index 2442b06574e..aec6875fe70 100644 --- a/app/models/concerns/facets/hostgroup_extensions.rb +++ b/app/models/concerns/facets/hostgroup_extensions.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module HostgroupExtensions extend ActiveSupport::Concern diff --git a/app/models/concerns/facets/hostgroup_facet.rb b/app/models/concerns/facets/hostgroup_facet.rb index b7de486ac56..9ddb0670b57 100644 --- a/app/models/concerns/facets/hostgroup_facet.rb +++ b/app/models/concerns/facets/hostgroup_facet.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module HostgroupFacet extend ActiveSupport::Concern diff --git a/app/models/concerns/facets/managed_host_extensions.rb b/app/models/concerns/facets/managed_host_extensions.rb index 8c3b81a27af..fd7f28e7249 100644 --- a/app/models/concerns/facets/managed_host_extensions.rb +++ b/app/models/concerns/facets/managed_host_extensions.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module ManagedHostExtensions extend ActiveSupport::Concern diff --git a/app/models/concerns/facets/model_extensions_base.rb b/app/models/concerns/facets/model_extensions_base.rb index f34aac04cc6..5389115010b 100644 --- a/app/models/concerns/facets/model_extensions_base.rb +++ b/app/models/concerns/facets/model_extensions_base.rb @@ -1,5 +1,3 @@ -require_dependency 'facets' - module Facets module ModelExtensionsBase extend ActiveSupport::Concern diff --git a/app/models/concerns/foreman/sti.rb b/app/models/concerns/foreman/sti.rb index c1926215f86..94560866813 100644 --- a/app/models/concerns/foreman/sti.rb +++ b/app/models/concerns/foreman/sti.rb @@ -1,12 +1,8 @@ module Foreman module STI - def self.prepended(base) - class << base - prepend ClassMethods - end - end + extend ActiveSupport::Concern - module ClassMethods + class_methods do # ensures that the correct STI object is created when :type is passed. def new(attributes = nil, &block) if attributes.is_a?(Hash) && (type = attributes.with_indifferent_access.delete(:type)) && !type.empty? diff --git a/app/models/concerns/foreman_register/host_extensions.rb b/app/models/concerns/foreman_register/host_extensions.rb index 62fef197c56..dd19a9304ed 100644 --- a/app/models/concerns/foreman_register/host_extensions.rb +++ b/app/models/concerns/foreman_register/host_extensions.rb @@ -14,7 +14,7 @@ def registration_token end def registration_url - ForemanRegister::RegistrationUrl.new(host: self).url + ForemanRegister::RegistrationURL.new(host: self).url end def initial_configuration_template diff --git a/app/models/concerns/host_template_helpers.rb b/app/models/concerns/host_template_helpers.rb index 6241a38f2d0..fe1d1560465 100644 --- a/app/models/concerns/host_template_helpers.rb +++ b/app/models/concerns/host_template_helpers.rb @@ -2,7 +2,7 @@ # and are mixed in to Host module HostTemplateHelpers extend ActiveSupport::Concern - include ::Foreman::ForemanUrlRenderer + include ::Foreman::ForemanURLRenderer delegate :medium_uri, to: :medium_provider diff --git a/app/models/concerns/hostext/puppetca.rb b/app/models/concerns/hostext/puppet_ca.rb similarity index 89% rename from app/models/concerns/hostext/puppetca.rb rename to app/models/concerns/hostext/puppet_ca.rb index 03f3dfd6e0c..0baedb85622 100644 --- a/app/models/concerns/hostext/puppetca.rb +++ b/app/models/concerns/hostext/puppet_ca.rb @@ -1,9 +1,9 @@ module Hostext - module Puppetca + module PuppetCA extend ActiveSupport::Concern included do - has_one :puppetca_token, :foreign_key => :host_id, :dependent => :destroy, :inverse_of => :host, :class_name => 'Token::Puppetca' + has_one :puppetca_token, :foreign_key => :host_id, :dependent => :destroy, :inverse_of => :host, :class_name => 'Token::PuppetCA' end end end diff --git a/app/models/concerns/orchestration.rb b/app/models/concerns/orchestration.rb index 68cfca69cf2..f7fb14630b1 100644 --- a/app/models/concerns/orchestration.rb +++ b/app/models/concerns/orchestration.rb @@ -1,6 +1,3 @@ -require_dependency "proxy_api" -require_dependency 'orchestration/queue' - module Orchestration extend ActiveSupport::Concern include Orchestration::ProgressReport diff --git a/app/models/concerns/orchestration/compute.rb b/app/models/concerns/orchestration/compute.rb index ee7f9f01738..8f24ff7ce17 100644 --- a/app/models/concerns/orchestration/compute.rb +++ b/app/models/concerns/orchestration/compute.rb @@ -140,7 +140,7 @@ def setUserData end def delUserData - # Mostly copied from SSHProvision, should probably refactor to have both use a common set of PuppetCA actions + # Mostly copied from SshProvision, should probably refactor to have both use a common set of PuppetCA actions compute_attributes.except!(:user_data) # Unset any badly formatted data # since we enable certificates/autosign via here, we also need to make sure we clean it up in case of an error if puppetca? diff --git a/app/models/concerns/orchestration/dns.rb b/app/models/concerns/orchestration/dns.rb index fdd8dff965d..068c3f0e635 100644 --- a/app/models/concerns/orchestration/dns.rb +++ b/app/models/concerns/orchestration/dns.rb @@ -33,7 +33,7 @@ def reverse_dns6? def rebuild_dns feasible = {} - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| feasible[record_type] = dns_feasible?(record_type) logger.info "DNS record type #{record_type} not supported for #{name}, skipping orchestration rebuild" unless feasible[record_type] end @@ -41,7 +41,7 @@ def rebuild_dns results = {} - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| del_dns_record_safe(record_type) begin @@ -62,7 +62,7 @@ def queue_dns def queue_dns_create logger.debug "Scheduling new DNS entries" - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| if dns_feasible?(record_type) queue.create(:name => _("Create %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 10, :action => [self, :set_dns_record, record_type]) @@ -72,7 +72,7 @@ def queue_dns_create def queue_dns_update return unless pending_dns_record_changes? - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| if old.dns_feasible?(record_type) queue.create(:name => _("Remove %{type} for %{host}") % {:host => old, :type => dns_class(record_type).human }, :priority => 9, :action => [old, :del_dns_record, record_type]) @@ -83,7 +83,7 @@ def queue_dns_update def queue_dns_destroy return unless errors.empty? - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| if dns_feasible?(record_type) queue.create(:name => _("Remove %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 1, :action => [self, :del_dns_record, record_type]) @@ -95,7 +95,7 @@ def queue_remove_dns_conflicts return unless errors.empty? return unless overwrite? logger.debug "Scheduling DNS conflict removal" - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting? queue.create(:name => _("Remove conflicting %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 0, :action => [self, :del_conflicting_dns_record, record_type]) @@ -115,7 +115,7 @@ def dns_conflict_detected? return false if overwrite? status = true - DnsInterface::RECORD_TYPES.each do |record_type| + DNSInterface::RECORD_TYPES.each do |record_type| if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting? conflicts = dns_record(record_type).conflicts status = failure(_("%{type} %{conflicts} already exists") % {:conflicts => conflicts.to_sentence, :type => dns_class(record_type).human(conflicts.count)}, nil, :conflict) diff --git a/app/models/concerns/orchestration/puppetca.rb b/app/models/concerns/orchestration/puppet_ca.rb similarity index 97% rename from app/models/concerns/orchestration/puppetca.rb rename to app/models/concerns/orchestration/puppet_ca.rb index de0f262b8aa..28de7246b11 100644 --- a/app/models/concerns/orchestration/puppetca.rb +++ b/app/models/concerns/orchestration/puppet_ca.rb @@ -1,4 +1,4 @@ -module Orchestration::Puppetca +module Orchestration::PuppetCA extend ActiveSupport::Concern include Orchestration::Common @@ -14,7 +14,7 @@ module Orchestration::Puppetca def initialize_puppetca return unless puppetca? return unless Setting[:manage_puppetca] - @puppetca = ProxyAPI::Puppetca.new :url => puppet_ca_proxy.url + @puppetca = ProxyAPI::PuppetCA.new :url => puppet_ca_proxy.url true rescue => e failure _("Failed to initialize the PuppetCA proxy: %s") % e, e diff --git a/app/models/concerns/orchestration/ssh_provision.rb b/app/models/concerns/orchestration/ssh_provision.rb index 305b832f920..828effb2f2a 100644 --- a/app/models/concerns/orchestration/ssh_provision.rb +++ b/app/models/concerns/orchestration/ssh_provision.rb @@ -1,4 +1,4 @@ -module Orchestration::SSHProvision +module Orchestration::SshProvision extend ActiveSupport::Concern included do @@ -51,7 +51,7 @@ def setSSHWaitForResponse else raise ::Foreman::Exception.new(N_('Unable to find proper authentication method')) end - self.client = Foreman::Provision::SSH.new provision_host, image.try(:username), { :template => template_file.path, :uuid => uuid }.merge(credentials) + self.client = Foreman::Provision::Ssh.new provision_host, image.try(:username), { :template => template_file.path, :uuid => uuid }.merge(credentials) rescue => e failure _("Failed to login via SSH to %{name}: %{e}") % { :name => name, :e => e }, e end diff --git a/app/models/concerns/url_validation.rb b/app/models/concerns/url_validation.rb index ee9f70c1f0f..2deffc136b7 100644 --- a/app/models/concerns/url_validation.rb +++ b/app/models/concerns/url_validation.rb @@ -1,4 +1,4 @@ -module UrlValidation +module URLValidation extend ActiveSupport::Concern def is_http_url?(url) diff --git a/app/models/host/base.rb b/app/models/host/base.rb index ec9b6f2e931..35c890c63aa 100644 --- a/app/models/host/base.rb +++ b/app/models/host/base.rb @@ -645,5 +645,3 @@ def set_creator_id end end end - -require_dependency 'host/managed' diff --git a/app/models/host/managed.rb b/app/models/host/managed.rb index c3268d4488a..7e2565e4f13 100644 --- a/app/models/host/managed.rb +++ b/app/models/host/managed.rb @@ -16,7 +16,7 @@ class Host::Managed < Host::Base include Hostext::SmartProxy include Hostext::Token include Hostext::OperatingSystem - include Hostext::Puppetca + include Hostext::PuppetCA include SelectiveClone include HostInfoExtensions include HostParams @@ -150,7 +150,7 @@ def build_hooks property :global_status, Integer, desc: 'Returns numerical representation of the host status' property :multiboot, String, desc: 'Returns path to multiboot loader' property :miniroot, String, desc: 'Returns path to the initial RAM disk for this host' - property :puppetca_token, 'Token::Puppetca', desc: 'Returns Puppet CA token for this host' + property :puppetca_token, 'Token::PuppetCA', desc: 'Returns Puppet CA token for this host' property :last_report, 'ActiveSupport::TimeWithZone', desc: 'Returns date object representing time when the last report was made by this host' property :smart_proxies, array_of: ['SmartProxy'], desc: 'Returns Smart Proxies attached to the host' property :virtual, one_of: [true, false], desc: 'Returns true if the host is virtual, false otherwise' @@ -306,8 +306,8 @@ class Jail < ::Safemode::Jail include Rails.application.routes.url_helpers # TFTP orchestration delegation delegate :tftp?, :tftp6?, :tftp, :tftp6, :generate_pxe_template, :to => :provision_interface - include Orchestration::Puppetca - include Orchestration::SSHProvision + include Orchestration::PuppetCA + include Orchestration::SshProvision include Orchestration::Realm include HostTemplateHelpers delegate :require_ip4_validation?, :require_ip6_validation?, :to => :provision_interface diff --git a/app/models/host_status.rb b/app/models/host_status.rb index 45e071dda00..ab7b2861dcb 100644 --- a/app/models/host_status.rb +++ b/app/models/host_status.rb @@ -16,5 +16,3 @@ def self.find_status_by_humanized_name(name) status_registry.find { |s| s.humanized_name == name } end end - -require_dependency 'host_status/status' diff --git a/app/models/host_status/status.rb b/app/models/host_status/status.rb index 83201987fe4..b16446abaeb 100644 --- a/app/models/host_status/status.rb +++ b/app/models/host_status/status.rb @@ -84,6 +84,3 @@ def update_status end end end - -require_dependency 'host_status/configuration_status' -require_dependency 'host_status/build_status' diff --git a/app/models/nic/base.rb b/app/models/nic/base.rb index 70bef808a53..ce303ca46c9 100644 --- a/app/models/nic/base.rb +++ b/app/models/nic/base.rb @@ -370,5 +370,3 @@ def check_blank_mac_for_virtual_resources end end end - -require_dependency 'nic/interface' diff --git a/app/models/nic/bmc.rb b/app/models/nic/bmc.rb index e9c054c09d6..58d63447fe7 100644 --- a/app/models/nic/bmc.rb +++ b/app/models/nic/bmc.rb @@ -64,6 +64,4 @@ def validate_bmc_proxy errors.add(:type, e.message) end end - - Base.register_type(BMC) end diff --git a/app/models/nic/bond.rb b/app/models/nic/bond.rb index 153e5d2e5c8..0e1bac1f979 100644 --- a/app/models/nic/bond.rb +++ b/app/models/nic/bond.rb @@ -19,6 +19,4 @@ def self.humanized_name N_('Bond') end end - - Base.register_type(Bond) end diff --git a/app/models/nic/bridge.rb b/app/models/nic/bridge.rb index f797559856a..026fb587f46 100644 --- a/app/models/nic/bridge.rb +++ b/app/models/nic/bridge.rb @@ -6,6 +6,4 @@ def self.humanized_name N_('Bridge') end end - - Base.register_type(Bridge) end diff --git a/app/models/nic/interface.rb b/app/models/nic/interface.rb index 4c8fa312404..2f4bf7421f3 100644 --- a/app/models/nic/interface.rb +++ b/app/models/nic/interface.rb @@ -143,5 +143,3 @@ def normalize_name end end end - -require_dependency 'nic/managed' diff --git a/app/models/nic/managed.rb b/app/models/nic/managed.rb index 4bcdcda407e..b9fa49db468 100644 --- a/app/models/nic/managed.rb +++ b/app/models/nic/managed.rb @@ -5,7 +5,7 @@ class Managed < Interface include Orchestration::DNS include Orchestration::TFTP include Orchestration::ExternalIPAM - include DnsInterface + include DNSInterface include InterfaceCloning include Exportable @@ -119,10 +119,4 @@ def setup_clone @old end end - - Base.register_type(Managed) end - -require_dependency 'nic/bmc' -require_dependency 'nic/bond' -require_dependency 'nic/bridge' diff --git a/app/models/parameter.rb b/app/models/parameter.rb index 434c17b30c3..d2cbc8e911f 100644 --- a/app/models/parameter.rb +++ b/app/models/parameter.rb @@ -94,12 +94,3 @@ def skip_strip_attrs ['value'] end end - -require_dependency 'common_parameter' -require_dependency 'domain_parameter' -require_dependency 'group_parameter' -require_dependency 'host_parameter' -require_dependency 'location_parameter' -require_dependency 'organization_parameter' -require_dependency 'os_parameter' -require_dependency 'subnet_parameter' diff --git a/app/models/permission.rb b/app/models/permission.rb index 8a3703fef34..b5264d23ae7 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -12,7 +12,11 @@ class Permission < ApplicationRecord scoped_search :on => :resource_type def self.resources - @all_resources ||= Permission.distinct.order(:resource_type).pluck(:resource_type).compact + # We don't run seeds.rb initializer in test environment, so at the first call of this method in TemplateInputsController + # during code loading @all_resources will be an empty array, and don't get populated with the actual resources from db later + # In dev and prod environments, the seeds.rb initializer is run, so @all_resources will be populated with the actual resources + @all_resources = Permission.distinct.order(:resource_type).pluck(:resource_type).compact if @all_resources.empty? + @all_resources end def self.resources_with_translations diff --git a/app/models/subnet.rb b/app/models/subnet.rb index 6922ea986c2..0fd06080f6e 100644 --- a/app/models/subnet.rb +++ b/app/models/subnet.rb @@ -269,7 +269,7 @@ def external_ipam? end def external_ipam_proxy(attrs = {}) - @external_ipam_proxy ||= ProxyAPI::ExternalIpam.new({:url => externalipam.url}.merge(attrs)) if external_ipam? + @external_ipam_proxy ||= ProxyAPI::ExternalIPAM.new({:url => externalipam.url}.merge(attrs)) if external_ipam? end def ipam? diff --git a/app/models/template.rb b/app/models/template.rb index 5a1218f6b51..67b61c51e3d 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -339,6 +339,3 @@ def inputs_unchanged_when_locked end end end - -require_dependency 'provisioning_template' -require_dependency 'ptable' diff --git a/app/models/token/puppetca.rb b/app/models/token/puppet_ca.rb similarity index 56% rename from app/models/token/puppetca.rb rename to app/models/token/puppet_ca.rb index 085b978e266..1dd8bc2cfdb 100644 --- a/app/models/token/puppetca.rb +++ b/app/models/token/puppet_ca.rb @@ -1,3 +1,3 @@ -class Token::Puppetca < ::Token +class Token::PuppetCA < ::Token validates :value, uniqueness: true end diff --git a/app/registries/foreman/plugin.rb b/app/registries/foreman/plugin.rb index e8ba44f2e48..07530497574 100644 --- a/app/registries/foreman/plugin.rb +++ b/app/registries/foreman/plugin.rb @@ -14,13 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -require_dependency 'foreman/plugin/logging' -require_dependency 'foreman/plugin/report_scanner_registry' -require_dependency 'foreman/plugin/report_origin_registry' -require_dependency 'foreman/plugin/medium_providers_registry' -require_dependency 'foreman/plugin/fact_importer_registry' - module Foreman #:nodoc: class PluginNotFound < Foreman::Exception; end class PluginRequirementError < Foreman::Exception; end diff --git a/app/registries/foreman/plugin/report_scanner_registry.rb b/app/registries/foreman/plugin/report_scanner_registry.rb index f6d23479d88..a93d77e8918 100644 --- a/app/registries/foreman/plugin/report_scanner_registry.rb +++ b/app/registries/foreman/plugin/report_scanner_registry.rb @@ -1,17 +1,10 @@ -require_dependency File.expand_path('../../../services/report_scanner/puppet_report_scanner', __dir__) - module Foreman class Plugin class ReportScannerRegistry - DEFAULT_REPORT_SCANNERS = [ - ::Foreman::PuppetReportScanner, - ].freeze - attr_accessor :report_scanners def initialize @report_scanners = [] - register_default_scanner end def report_scanners @@ -25,14 +18,6 @@ def register_report_scanner(scanner) def unregister_report_scanner(scanner) @report_scanners -= [scanner] end - - private - - def register_default_scanner - DEFAULT_REPORT_SCANNERS.each do |default_scanner| - register_report_scanner default_scanner - end - end end end end diff --git a/app/registries/foreman/settings.rb b/app/registries/foreman/settings.rb deleted file mode 100644 index 8f811b0842c..00000000000 --- a/app/registries/foreman/settings.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_dependency 'foreman/setting_manager' - -require_dependency 'foreman/settings/general' -require_dependency 'foreman/settings/auth' -require_dependency 'foreman/settings/email' -require_dependency 'foreman/settings/notification' -require_dependency 'foreman/settings/provisioning' -require_dependency 'foreman/settings/facts' -require_dependency 'foreman/settings/cfgmgmt' diff --git a/app/registries/menu/loader.rb b/app/registries/menu/loader.rb index 6cc122201e1..c538a56727a 100644 --- a/app/registries/menu/loader.rb +++ b/app/registries/menu/loader.rb @@ -1,9 +1,3 @@ -require_dependency 'menu/node' -require_dependency 'menu/item' -require_dependency 'menu/divider' -require_dependency 'menu/toggle' -require_dependency 'menu/manager' - module Menu class Loader def self.load diff --git a/app/services/setting_registry.rb b/app/registries/setting_registry.rb similarity index 100% rename from app/services/setting_registry.rb rename to app/registries/setting_registry.rb diff --git a/app/services/foreman/foreman_url_renderer.rb b/app/services/foreman/foreman_url_renderer.rb index 4c224fb0efa..190b40edbb6 100644 --- a/app/services/foreman/foreman_url_renderer.rb +++ b/app/services/foreman/foreman_url_renderer.rb @@ -1,12 +1,12 @@ module Foreman - module ForemanUrlRenderer + module ForemanURLRenderer # foreman_url macro uses url_for, therefore we need url helpers and fake default_url_options # if it's not defined in class the we mix into include Rails.application.routes.url_helpers extend ApipieDSL::Module apipie :class, 'Foreman URL macro class' do - name 'ForemanUrlRenderer' + name 'ForemanURLRenderer' sections only: %w[all reports provisioning jobs partition_tables] end diff --git a/app/services/foreman/provision/ssh.rb b/app/services/foreman/provision/ssh.rb index 4844d6883f3..f91972d3e6a 100644 --- a/app/services/foreman/provision/ssh.rb +++ b/app/services/foreman/provision/ssh.rb @@ -1,6 +1,6 @@ require 'timeout' -class Foreman::Provision::SSH +class Foreman::Provision::Ssh attr_reader :template, :uuid, :results, :address, :username, :options def initialize(address, username = "root", options = { }) diff --git a/app/services/foreman/renderer/scope/macros/base.rb b/app/services/foreman/renderer/scope/macros/base.rb index b222c54595c..5ff29ec5d6f 100644 --- a/app/services/foreman/renderer/scope/macros/base.rb +++ b/app/services/foreman/renderer/scope/macros/base.rb @@ -5,7 +5,7 @@ module Macros module Base extend ApipieDSL::Module include Foreman::Renderer::Errors - include ::Foreman::ForemanUrlRenderer + include ::Foreman::ForemanURLRenderer include ActiveSupport::NumberHelper attr_reader :template_name, :medium_provider diff --git a/app/services/foreman_register/registration_url.rb b/app/services/foreman_register/registration_url.rb index 0c3d55fb1ac..488dc125a74 100644 --- a/app/services/foreman_register/registration_url.rb +++ b/app/services/foreman_register/registration_url.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ForemanRegister - class RegistrationUrl + class RegistrationURL attr_reader :host delegate :registration_token, to: :host diff --git a/app/services/ipam.rb b/app/services/ipam.rb index c5ce22a53b8..36dd6fc52c3 100644 --- a/app/services/ipam.rb +++ b/app/services/ipam.rb @@ -6,7 +6,7 @@ def self.new(type, *args) when IPAM::MODES[:none] IPAM::None.new(*args) when IPAM::MODES[:dhcp] - IPAM::Dhcp.new(*args) + IPAM::DHCP.new(*args) when IPAM::MODES[:db] IPAM::Db.new(*args) when IPAM::MODES[:random_db] @@ -14,7 +14,7 @@ def self.new(type, *args) when IPAM::MODES[:eui64] IPAM::Eui64.new(*args) when IPAM::MODES[:external_ipam] - IPAM::ExternalIpam.new(*args) + IPAM::ExternalIPAM.new(*args) else raise ::Foreman::Exception.new(N_("Unknown IPAM type - can't continue")) end diff --git a/app/services/ipam/dhcp.rb b/app/services/ipam/dhcp.rb index 8fd08d5d8a5..9f30533eba0 100644 --- a/app/services/ipam/dhcp.rb +++ b/app/services/ipam/dhcp.rb @@ -1,5 +1,5 @@ module IPAM - class Dhcp < Base + class DHCP < Base delegate :dhcp, :dhcp_proxy, :to => :subnet def suggest_ip unless subnet.dhcp? diff --git a/app/services/ipam/external_ipam.rb b/app/services/ipam/external_ipam.rb index bc24b71133f..708d57744c8 100644 --- a/app/services/ipam/external_ipam.rb +++ b/app/services/ipam/external_ipam.rb @@ -1,5 +1,5 @@ module IPAM - class ExternalIpam < Base + class ExternalIPAM < Base delegate :external_ipam_proxy, :to => :subnet def suggest_ip diff --git a/app/services/orchestration/queue.rb b/app/services/orchestration/queue.rb index 49905f7a047..1aa324ac2b1 100644 --- a/app/services/orchestration/queue.rb +++ b/app/services/orchestration/queue.rb @@ -1,5 +1,3 @@ -require_dependency 'orchestration/task' - module Orchestration # Represents tasks queue for orchestration class Queue diff --git a/app/services/proxy_api/external_ipam.rb b/app/services/proxy_api/external_ipam.rb index f67431e2da7..22cf637bdd5 100644 --- a/app/services/proxy_api/external_ipam.rb +++ b/app/services/proxy_api/external_ipam.rb @@ -1,7 +1,7 @@ require 'uri' module ProxyAPI - class ExternalIpam < ProxyAPI::Resource + class ExternalIPAM < ProxyAPI::Resource def initialize(args) @url = args[:url] + "/ipam" super args diff --git a/app/services/proxy_api/puppetca.rb b/app/services/proxy_api/puppet_ca.rb similarity index 97% rename from app/services/proxy_api/puppetca.rb rename to app/services/proxy_api/puppet_ca.rb index b97ee8a87ea..7f8c2e14c21 100644 --- a/app/services/proxy_api/puppetca.rb +++ b/app/services/proxy_api/puppet_ca.rb @@ -1,5 +1,5 @@ module ProxyAPI - class Puppetca < ProxyAPI::Resource + class PuppetCA < ProxyAPI::Resource def initialize(args) @url = args[:url] + "/puppet/ca" super args diff --git a/app/services/proxy_status.rb b/app/services/proxy_status.rb index aa81b6d9518..78a17ba6d54 100644 --- a/app/services/proxy_status.rb +++ b/app/services/proxy_status.rb @@ -10,7 +10,3 @@ def self.find_status_by_humanized_name(name) status_registry.find { |s| s.humanized_name == name } end end -require_dependency('proxy_status/version') -require_dependency('proxy_status/tftp') -require_dependency('proxy_status/puppetca') -require_dependency('proxy_status/logs') diff --git a/app/services/proxy_status/puppetca.rb b/app/services/proxy_status/puppet_ca.rb similarity index 98% rename from app/services/proxy_status/puppetca.rb rename to app/services/proxy_status/puppet_ca.rb index c6d6336ffcc..4b65e7f0328 100644 --- a/app/services/proxy_status/puppetca.rb +++ b/app/services/proxy_status/puppet_ca.rb @@ -67,7 +67,7 @@ def self.humanized_name protected def api_class - ProxyAPI::Puppetca + ProxyAPI::PuppetCA end end end diff --git a/app/services/report_scanner/puppet_report_scanner.rb b/app/services/report_scanner/puppet_report_scanner.rb index 57b75a95d4d..b0cb646698a 100644 --- a/app/services/report_scanner/puppet_report_scanner.rb +++ b/app/services/report_scanner/puppet_report_scanner.rb @@ -1,4 +1,4 @@ -module Foreman +module ReportScanner class PuppetReportScanner class << self def identify_origin(report_data) diff --git a/app/validators/http_url_validator.rb b/app/validators/http_url_validator.rb index 3fc5b242dc9..60af01fa56e 100644 --- a/app/validators/http_url_validator.rb +++ b/app/validators/http_url_validator.rb @@ -1,5 +1,5 @@ -class HttpUrlValidator < ActiveModel::EachValidator - include UrlValidation +class HttpURLValidator < ActiveModel::EachValidator + include URLValidation def validate_each(record, attribute, value) return if options[:allow_blank] && value.empty? diff --git a/app/validators/url_schema_validator.rb b/app/validators/url_schema_validator.rb index 6d406ac038c..2d612a8b747 100644 --- a/app/validators/url_schema_validator.rb +++ b/app/validators/url_schema_validator.rb @@ -1,4 +1,4 @@ -class UrlSchemaValidator < ActiveModel::EachValidator +class URLSchemaValidator < ActiveModel::EachValidator def initialize(args) @schemas = args[:in] super diff --git a/config/application.rb b/config/application.rb index 7ab2ac3b6fb..11344ec4841 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,7 +24,6 @@ end require File.expand_path('../config/settings', __dir__) -require File.expand_path('../lib/foreman/dynflow', __dir__) if File.exist?(File.expand_path('../Gemfile.in', __dir__)) # If there is a Gemfile.in file, we will not use Bundler but BundlerExt @@ -65,29 +64,11 @@ class Foreman::Consoletie < Rails::Railtie end end -# CRs in fog core with extra dependencies will have those deps loaded, so then -# load the corresponding bit of fog -require 'fog/ovirt' if defined?(::OVIRT) - -require File.expand_path('../lib/foreman', __dir__) -require File.expand_path('../lib/foreman/exception', __dir__) -require File.expand_path('../lib/core_extensions', __dir__) -require File.expand_path('../lib/foreman/force_ssl', __dir__) -require File.expand_path('../lib/foreman/logging', __dir__) -require File.expand_path('../lib/foreman/http_proxy', __dir__) -require File.expand_path('../lib/foreman/middleware/logging_context_request', __dir__) -require File.expand_path('../lib/foreman/middleware/logging_context_session', __dir__) -require File.expand_path('../lib/foreman/middleware/telemetry', __dir__) -require File.expand_path('../lib/foreman/middleware/libvirt_connection_cleaner', __dir__) - -# Ensure ApplicationRecord is loaded early and can be used inside migrations. -# Can probably be removed once we migrate to Zeitwerk. -require File.expand_path('../app/models/concerns/host_mix', __dir__) -require File.expand_path('../app/models/concerns/has_many_common', __dir__) -require File.expand_path('../app/models/concerns/strip_whitespace', __dir__) -require File.expand_path('../app/models/concerns/parameterizable', __dir__) -require File.expand_path('../app/models/concerns/audit_associations', __dir__) -require File.expand_path('../app/models/application_record', __dir__) +# Content of these files is being used before Zeitwerk does auto/eager loading +# We need to call either require with the full path or require_relative with relative path since /lib is not in $LOAD_PATH yet here +# $LOAD_PATH is available in config/initializers though +require_relative '../lib/foreman' +require_relative '../lib/foreman/dynflow' if SETTINGS[:support_jsonp] if File.exist?(File.expand_path('../Gemfile.in', __dir__)) @@ -119,7 +100,7 @@ class Application < Rails::Application config.action_dispatch.use_authenticated_cookie_encryption = false # Rails 6.0 changed this to :zeitwerk - config.autoloader = :classic + config.autoloader = :zeitwerk # Rails 6.1 changed this to true, but apparently our codebase is not ready for bidirectional associations config.active_record.has_many_inversing = false @@ -137,7 +118,6 @@ class Application < Rails::Application config.autoload_paths += %W(#{config.root}/app/models/compute_resources) config.autoload_paths += %W(#{config.root}/app/models/fact_names) config.autoload_paths += %W(#{config.root}/app/models/lookup_keys) - config.autoload_paths += %W(#{config.root}/app/models/host_status) config.autoload_paths += %W(#{config.root}/app/models/operatingsystems) config.autoload_paths += %W(#{config.root}/app/models/parameters) config.autoload_paths += %W(#{config.root}/app/models/taxonomies) @@ -149,6 +129,7 @@ class Application < Rails::Application # Eager load all classes under lib directory config.eager_load_paths += ["#{config.root}/lib"] + config.eager_load_paths += ["#{config.root}/app/lib"] # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/config/environments/test.rb b/config/environments/test.rb index 5ed9ce61c2f..ae8cf0bd621 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,8 +12,7 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Eager load currently cannot be set due to: https://projects.theforeman.org/issues/31977 - config.eager_load = false + config.eager_load = true # Configure static asset server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/config/initializers/6_zeitwerk.rb b/config/initializers/6_zeitwerk.rb new file mode 100644 index 00000000000..f3b31717463 --- /dev/null +++ b/config/initializers/6_zeitwerk.rb @@ -0,0 +1,4 @@ +Rails.autoloaders.main.ignore( + Rails.root.join('lib/generators'), + Rails.root.join('lib/tasks') +) diff --git a/config/initializers/audit.rb b/config/initializers/audit.rb index c8e5f660c0d..1355f3d48aa 100644 --- a/config/initializers/audit.rb +++ b/config/initializers/audit.rb @@ -1,6 +1,7 @@ # The audit class is part of audited plugin # we reopen here to add search functionality require 'audited' +require 'audit_associations/associations_changes' # Re-opened AuditorInstanceMethods to audit 1-0-* associations Audited::Auditor::AuditedInstanceMethods.prepend AuditAssociations::AssociationsChanges diff --git a/lib/core_extensions.rb b/config/initializers/core_extensions.rb similarity index 100% rename from lib/core_extensions.rb rename to config/initializers/core_extensions.rb diff --git a/app/registries/foreman/access_permissions.rb b/config/initializers/f_foreman_permissions.rb similarity index 99% rename from app/registries/foreman/access_permissions.rb rename to config/initializers/f_foreman_permissions.rb index 16b21a02bba..4f9146c7b23 100644 --- a/app/registries/foreman/access_permissions.rb +++ b/config/initializers/f_foreman_permissions.rb @@ -1,5 +1,3 @@ -require_dependency 'foreman/access_control' - # Permissions Foreman::AccessControl.map do |permission_set| permission_set.security_block :public do |map| diff --git a/app/registries/foreman/settings/auth.rb b/config/initializers/f_foreman_settings_auth.rb similarity index 99% rename from app/registries/foreman/settings/auth.rb rename to config/initializers/f_foreman_settings_auth.rb index 0db7b257041..2d6a76f95b1 100644 --- a/app/registries/foreman/settings/auth.rb +++ b/config/initializers/f_foreman_settings_auth.rb @@ -87,7 +87,7 @@ setting('websockets_encrypt', type: :boolean, description: N_("VNC/SPICE websocket proxy console access encryption (websockets_ssl_key/cert setting required)"), - default: !!SETTINGS[:require_ssl], + default: !!SETTINGS[:require_ssl], # rubocop:disable Style/DoubleNegation full_name: N_('Websockets encryption')) validates('websockets_encrypt', ->(value) { !value || !(Setting["websockets_ssl_key"].empty? || Setting["websockets_ssl_cert"].empty?) }, message: N_("Unable to turn on websockets_encrypt, either websockets_ssl_key or websockets_ssl_cert is missing")) validates('websockets_ssl_key', ->(value) { !Setting["websockets_encrypt"] || !value.empty? }, message: N_("Unable to unset websockets_ssl_key when websockets_encrypt is on")) diff --git a/app/registries/foreman/settings/cfgmgmt.rb b/config/initializers/f_foreman_settings_cfgmgmt.rb similarity index 100% rename from app/registries/foreman/settings/cfgmgmt.rb rename to config/initializers/f_foreman_settings_cfgmgmt.rb diff --git a/app/registries/foreman/settings/email.rb b/config/initializers/f_foreman_settings_email.rb similarity index 100% rename from app/registries/foreman/settings/email.rb rename to config/initializers/f_foreman_settings_email.rb diff --git a/app/registries/foreman/settings/facts.rb b/config/initializers/f_foreman_settings_facts.rb similarity index 100% rename from app/registries/foreman/settings/facts.rb rename to config/initializers/f_foreman_settings_facts.rb diff --git a/app/registries/foreman/settings/general.rb b/config/initializers/f_foreman_settings_general.rb similarity index 100% rename from app/registries/foreman/settings/general.rb rename to config/initializers/f_foreman_settings_general.rb diff --git a/app/registries/foreman/settings/notification.rb b/config/initializers/f_foreman_settings_notification.rb similarity index 100% rename from app/registries/foreman/settings/notification.rb rename to config/initializers/f_foreman_settings_notification.rb diff --git a/app/registries/foreman/settings/provisioning.rb b/config/initializers/f_foreman_settings_provisioning.rb similarity index 99% rename from app/registries/foreman/settings/provisioning.rb rename to config/initializers/f_foreman_settings_provisioning.rb index caf4d10f7a4..a40c755a2e4 100644 --- a/app/registries/foreman/settings/provisioning.rb +++ b/config/initializers/f_foreman_settings_provisioning.rb @@ -1,5 +1,3 @@ -require 'foreman/provision' - Foreman::SettingManager.define(:foreman) do category(:provisioning, N_('Provisioning')) do CT_LOCATIONS = %w(/usr/bin/ct /usr/local/bin/ct) diff --git a/config/initializers/foreman.rb b/config/initializers/foreman.rb index bc7f953fb84..868b00deaf4 100644 --- a/config/initializers/foreman.rb +++ b/config/initializers/foreman.rb @@ -1,31 +1,20 @@ # stdlib dependencies require 'English' -# Registries from app/registries/ -# All are loaded and populated early but are loaded only once -require_dependency 'foreman/access_permissions' -require_dependency 'foreman/plugin' -require_dependency 'foreman/settings' - -# Other internal dependencies, may be autoloaded -require 'net' -require 'foreman/provision' - Rails.application.config.before_initialize do # load topbar Menu::Loader.load end -Foreman.settings.load_definitions - Foreman::Plugin.initialize_default_registries -Foreman::Plugin.medium_providers_registry.register MediumProviders::Default Rails.application.config.after_initialize do Foreman.settings.load_values unless Foreman.in_setup_db_rake? || !(Setting.table_exists? rescue false) end Rails.application.config.to_prepare do + Foreman::Plugin.report_scanner_registry.register_report_scanner ReportScanner::PuppetReportScanner + Foreman::Plugin.medium_providers_registry.register MediumProviders::Default # clear our users topbar cache # The users table may not be exist during initial migration of the database TopbarSweeper.expire_cache_all_users if (User.table_exists? rescue false) @@ -58,3 +47,14 @@ ReportImporter.register_smart_proxy_feature("Puppet") end + +# Preload here all classes which use Foreman::STI and using registration methods +# E.g. Base.register_type(BMC) +# Some constants that use such classes may be defined before all the related classes/models are loaded and registered +# E.g. InterfaceTypeMapper::ALLOWED_TYPE_NAMES +Rails.application.reloader.to_prepare do + Nic::Base.register_type(Nic::Managed) + Nic::Base.register_type(Nic::BMC) + Nic::Base.register_type(Nic::Bond) + Nic::Base.register_type(Nic::Bridge) +end diff --git a/config/initializers/foreman_register.rb b/config/initializers/foreman_register.rb index 829df319107..629454ad392 100644 --- a/config/initializers/foreman_register.rb +++ b/config/initializers/foreman_register.rb @@ -5,6 +5,8 @@ priority: 100 end +require 'csv_exporter' # Ugly place to put it, but this is the first usage of CsvExporter + Pagelets::Manager.with_key 'hosts/_list' do |ctx| ctx.with_profile :general, N_('General'), default: true do common_class = 'hidden-tablet hidden-xs ellipsis' diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 56a4af4d3d3..7f8860134e1 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,8 +1,39 @@ # Be sure to restart your server when you modify this file. +Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + 'proxy_api' => 'ProxyAPI' + ) +end + # Add new inflection rules using the following format # (all these examples are active by default): ActiveSupport::Inflector.inflections do |inflect| + inflect.acronym 'AAAA' # DNS IPv6 record + inflect.acronym 'AIX' # IBM AIX + # Requires our entire Api namespace to be rewritten + # inflect.acronym 'API' # Application Programmer Interface + inflect.acronym 'AWS' # Amazon Web Services + inflect.acronym 'BMC' # Baseboard Management Controller + inflect.acronym 'CA' # Certificate Authority + inflect.acronym 'DHCP' # Dynamic Host Configuration Protocol + inflect.acronym 'DNS' # Domain Name System + inflect.acronym 'EC2' # Amazon Elastic Compute Cloud + inflect.acronym 'GCE' # Google Compute Engine + inflect.acronym 'IPAM' # IP Address Management + inflect.acronym 'NXOS' # Cisco NX-OS + inflect.acronym 'PTR' # DNS reverse DNS record + # Causes an overlap between ::SSHKey and the SshKey model + # inflect.acronym 'SSH' # Secure SHell + inflect.acronym 'SSO' # Single Sign On + inflect.acronym 'STI' # Single Table Inheritance + inflect.acronym 'TFTP' # Trivial File Transfer Protocol + inflect.acronym 'UI' # User Interface + inflect.acronym 'URL' # Uniform Resource Locator + inflect.acronym 'VM' # Virtual Machine + inflect.acronym 'VRP' # Huawei VRP + inflect.acronym 'ZTP' # Zero Touch Provisioning + # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' diff --git a/db/migrate/20110801090318_add_vm_defaults_to_hostgroup.rb b/db/migrate/20110801090318_add_vm_defaults_to_hostgroup.rb index eb8d92cd2eb..bc092d7e549 100644 --- a/db/migrate/20110801090318_add_vm_defaults_to_hostgroup.rb +++ b/db/migrate/20110801090318_add_vm_defaults_to_hostgroup.rb @@ -1,4 +1,4 @@ -class AddVmDefaultsToHostgroup < ActiveRecord::Migration[4.2] +class AddVMDefaultsToHostgroup < ActiveRecord::Migration[4.2] def up add_column :hostgroups, :vm_defaults, :text end diff --git a/db/migrate/20111205231500_add_gateway_and_dns_to_subnets.rb b/db/migrate/20111205231500_add_gateway_and_dns_to_subnets.rb index 80367f939dd..81665ee7b32 100644 --- a/db/migrate/20111205231500_add_gateway_and_dns_to_subnets.rb +++ b/db/migrate/20111205231500_add_gateway_and_dns_to_subnets.rb @@ -1,4 +1,4 @@ -class AddGatewayAndDnsToSubnets < ActiveRecord::Migration[4.2] +class AddGatewayAndDNSToSubnets < ActiveRecord::Migration[4.2] def up add_column :subnets, :gateway, :string, :limit => 255 add_column :subnets, :dns_primary, :string, :limit => 255 diff --git a/db/migrate/20120521142924_add_dns_id_to_subnet.rb b/db/migrate/20120521142924_add_dns_id_to_subnet.rb index e3f53d4a2d5..541d44f9495 100644 --- a/db/migrate/20120521142924_add_dns_id_to_subnet.rb +++ b/db/migrate/20120521142924_add_dns_id_to_subnet.rb @@ -1,4 +1,4 @@ -class AddDnsIdToSubnet < ActiveRecord::Migration[4.2] +class AddDNSIdToSubnet < ActiveRecord::Migration[4.2] def up add_column :subnets, :dns_id, :integer end diff --git a/db/migrate/20130211160200_add_sti_to_hosts.rb b/db/migrate/20130211160200_add_sti_to_hosts.rb index dfe4a24bc7b..75b483ceb40 100644 --- a/db/migrate/20130211160200_add_sti_to_hosts.rb +++ b/db/migrate/20130211160200_add_sti_to_hosts.rb @@ -1,4 +1,4 @@ -class AddStiToHosts < ActiveRecord::Migration[4.2] +class AddSTIToHosts < ActiveRecord::Migration[4.2] def up add_column :hosts, :type, :string, :limit => 255 add_index :hosts, :type diff --git a/db/migrate/20130417110127_add_sti_to_settings.rb b/db/migrate/20130417110127_add_sti_to_settings.rb index 08bce03eb95..faa80e27c77 100644 --- a/db/migrate/20130417110127_add_sti_to_settings.rb +++ b/db/migrate/20130417110127_add_sti_to_settings.rb @@ -1,4 +1,4 @@ -class AddStiToSettings < ActiveRecord::Migration[4.2] +class AddSTIToSettings < ActiveRecord::Migration[4.2] def up add_index :settings, :category end diff --git a/db/migrate/20140902102858_convert_ipam_to_string.rb b/db/migrate/20140902102858_convert_ipam_to_string.rb index 881cb82c9d1..fec6c722133 100644 --- a/db/migrate/20140902102858_convert_ipam_to_string.rb +++ b/db/migrate/20140902102858_convert_ipam_to_string.rb @@ -1,4 +1,4 @@ -class ConvertIpamToString < ActiveRecord::Migration[4.2] +class ConvertIPAMToString < ActiveRecord::Migration[4.2] def up change_column :subnets, :ipam, :string, :default => IPAM::MODES[:dhcp], :null => false, :limit => 255 end diff --git a/db/migrate/20150606065713_add_sti_to_lookup_keys.rb b/db/migrate/20150606065713_add_sti_to_lookup_keys.rb index cb6f879fbac..95d0ea9c4e4 100644 --- a/db/migrate/20150606065713_add_sti_to_lookup_keys.rb +++ b/db/migrate/20150606065713_add_sti_to_lookup_keys.rb @@ -1,4 +1,4 @@ -class AddStiToLookupKeys < ActiveRecord::Migration[4.2] +class AddSTIToLookupKeys < ActiveRecord::Migration[4.2] def up add_column :lookup_keys, :type, :string, limit: 255 add_index :lookup_keys, :type diff --git a/db/migrate/20160414063050_add_sti_to_subnets.rb b/db/migrate/20160414063050_add_sti_to_subnets.rb index 98a9a208f2b..7867a102d92 100644 --- a/db/migrate/20160414063050_add_sti_to_subnets.rb +++ b/db/migrate/20160414063050_add_sti_to_subnets.rb @@ -1,4 +1,4 @@ -class AddStiToSubnets < ActiveRecord::Migration[4.2] +class AddSTIToSubnets < ActiveRecord::Migration[4.2] def self.up add_column :subnets, :type, :string, :default => 'Subnet::Ipv4', :null => false add_index :subnets, :type diff --git a/db/migrate/20191017151119_add_external_ipam_id_to_subnets.rb b/db/migrate/20191017151119_add_external_ipam_id_to_subnets.rb index a385cb91704..ae120e59918 100644 --- a/db/migrate/20191017151119_add_external_ipam_id_to_subnets.rb +++ b/db/migrate/20191017151119_add_external_ipam_id_to_subnets.rb @@ -1,4 +1,4 @@ -class AddExternalIpamIdToSubnets < ActiveRecord::Migration[5.2] +class AddExternalIPAMIdToSubnets < ActiveRecord::Migration[5.2] def up add_column :subnets, :externalipam_id, :integer add_column :subnets, :externalipam_group, :text diff --git a/db/migrate/20200615071719_add_bmc_to_subnet.rb b/db/migrate/20200615071719_add_bmc_to_subnet.rb index 1a5e3f9a0dd..f4ca8dde6b7 100644 --- a/db/migrate/20200615071719_add_bmc_to_subnet.rb +++ b/db/migrate/20200615071719_add_bmc_to_subnet.rb @@ -1,4 +1,4 @@ -class AddBmcToSubnet < ActiveRecord::Migration[6.0] +class AddBMCToSubnet < ActiveRecord::Migration[6.0] def change add_column :subnets, :bmc_id, :integer diff --git a/db/migrate/20220809191656_add_ssl_ca_to_http_proxy.rb b/db/migrate/20220809191656_add_ssl_ca_to_http_proxy.rb index a783f80c804..6cd461c8cd5 100644 --- a/db/migrate/20220809191656_add_ssl_ca_to_http_proxy.rb +++ b/db/migrate/20220809191656_add_ssl_ca_to_http_proxy.rb @@ -1,4 +1,4 @@ -class AddSslCaToHttpProxy < ActiveRecord::Migration[6.1] +class AddSslCAToHttpProxy < ActiveRecord::Migration[6.1] def change add_column :http_proxies, :cacert, :text end diff --git a/lib/audit_associations/associations_changes.rb b/lib/audit_associations/associations_changes.rb new file mode 100644 index 00000000000..6c5882ccf56 --- /dev/null +++ b/lib/audit_associations/associations_changes.rb @@ -0,0 +1,35 @@ +module AuditAssociations + module AssociationsChanges + def changes_to_save + super.merge(associated_changes) + end + + def audited_attributes + super.merge(associated_attributes) + end + + protected + + # Prevent associations from being set when looking at revisions since + # otherwise they will update the original object rather then the revision + def revision_with(attrs) + super(attrs.reject { |k, v| k.to_s.ends_with?('_ids') }) + end + + private + + def associated_changes + audited_options[:associations].each_with_object({}) do |association, changes| + if public_send("#{association}_changed?") + changes[association] = public_send("#{association}_change") + end + end + end + + def associated_attributes + audited_options[:associations].each_with_object({}) do |association, attributes| + attributes[association] = public_send(association) + end + end + end +end diff --git a/app/services/csv_exporter.rb b/lib/csv_exporter.rb similarity index 100% rename from app/services/csv_exporter.rb rename to lib/csv_exporter.rb diff --git a/app/models/concerns/fog_extensions.rb b/lib/fog_extensions.rb similarity index 100% rename from app/models/concerns/fog_extensions.rb rename to lib/fog_extensions.rb diff --git a/lib/fog_extensions/vsphere/mini_servers.rb b/lib/fog_extensions/vsphere/mini_servers.rb index 0975acd2cd8..4d7b4c736b4 100644 --- a/lib/fog_extensions/vsphere/mini_servers.rb +++ b/lib/fog_extensions/vsphere/mini_servers.rb @@ -1,5 +1,3 @@ -require 'fog_extensions/vsphere/mini_server' - module FogExtensions module Vsphere class MiniServers diff --git a/lib/foreman.rb b/lib/foreman.rb index ccb5e65b270..2ea28a384f7 100644 --- a/lib/foreman.rb +++ b/lib/foreman.rb @@ -46,3 +46,11 @@ def self.settings SettingRegistry.instance end end + +# Consider moving these to config.autoload_lib_once in Rails 7.1 +require_relative 'foreman/exception' # This could be extracted into separate files and get autoloaded +require_relative 'foreman/force_ssl' +require_relative 'foreman/logging' +require_relative 'foreman/middleware' +require_relative 'foreman/telemetry_helper' +require_relative 'foreman/provision' diff --git a/lib/foreman/logging.rb b/lib/foreman/logging.rb index 6849bd4f5e8..0be65dbd67d 100644 --- a/lib/foreman/logging.rb +++ b/lib/foreman/logging.rb @@ -25,7 +25,7 @@ def configure(options = {}) # we need to postpone loading of the silenced logger # to the time the Logging::LEVELS is initialized - require_dependency File.expand_path('silenced_logger', __dir__) + require File.expand_path('silenced_logger', __dir__) end def add_loggers(loggers = {}) diff --git a/lib/foreman/middleware.rb b/lib/foreman/middleware.rb new file mode 100644 index 00000000000..64bfc1e7a55 --- /dev/null +++ b/lib/foreman/middleware.rb @@ -0,0 +1,4 @@ +require_relative 'middleware/logging_context_request' +require_relative 'middleware/logging_context_session' +require_relative 'middleware/telemetry' +require_relative 'middleware/libvirt_connection_cleaner' diff --git a/lib/foreman/provision.rb b/lib/foreman/provision.rb index 18dcbc9d5a9..2df75f1a464 100644 --- a/lib/foreman/provision.rb +++ b/lib/foreman/provision.rb @@ -8,6 +8,4 @@ def self.local_boot_default_name(kind) def self.global_default_name(kind) "#{kind} global default" end - - autoload :SSH, 'foreman/provision/ssh' end diff --git a/app/services/foreman/telemetry_helper.rb b/lib/foreman/telemetry_helper.rb similarity index 100% rename from app/services/foreman/telemetry_helper.rb rename to lib/foreman/telemetry_helper.rb diff --git a/lib/net/dhcp.rb b/lib/net/dhcp.rb deleted file mode 100644 index e238f024ed9..00000000000 --- a/lib/net/dhcp.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Net - module DHCP - autoload :Record, "net/dhcp/record.rb" - autoload :SparcRecord, "net/dhcp/sparc_record.rb" - autoload :ZTPRecord, "net/dhcp/ztp_record.rb" - end -end diff --git a/lib/tasks/encrypt.rake b/lib/tasks/encrypt.rake index 8aa17772463..84d7aefa813 100644 --- a/lib/tasks/encrypt.rake +++ b/lib/tasks/encrypt.rake @@ -1,4 +1,4 @@ -require_dependency 'foreman/util' +require 'foreman/util' namespace :security do desc 'Generate new encryption key' diff --git a/lib/tasks/security.rake b/lib/tasks/security.rake index a7aa711cb8c..5014272601d 100644 --- a/lib/tasks/security.rake +++ b/lib/tasks/security.rake @@ -1,4 +1,4 @@ -require_dependency 'foreman/util' +require 'foreman/util' namespace :security do desc 'Generate new security token' diff --git a/test/controllers/api/v2/autosign_controller_test.rb b/test/controllers/api/v2/autosign_controller_test.rb index c1fe551fa28..55f9ca95012 100644 --- a/test/controllers/api/v2/autosign_controller_test.rb +++ b/test/controllers/api/v2/autosign_controller_test.rb @@ -2,7 +2,7 @@ class Api::V2::AutosignControllerTest < ActionController::TestCase setup do - ProxyAPI::Puppetca.any_instance.stubs(:autosign).returns(["a5809524-82fe-a8a4f3d6ebf4", "5eed0cb7-9aa-00b7b9780f20"]) + ProxyAPI::PuppetCA.any_instance.stubs(:autosign).returns(["a5809524-82fe-a8a4f3d6ebf4", "5eed0cb7-9aa-00b7b9780f20"]) @msg = "Test exception" @proxy_error = ProxyAPI::ProxyException.new(smart_proxies(:puppetmaster).url, RuntimeError.new, @msg) end @@ -10,13 +10,13 @@ class Api::V2::AutosignControllerTest < ActionController::TestCase test "should get index and return json" do get :index, params: { :smart_proxy_id => smart_proxies(:puppetmaster).id } assert_response :success - assert_equal 'http://else.where:4567/puppet/ca', ProxyAPI::Puppetca.new(:url => smart_proxies(:puppetmaster).url).url + assert_equal 'http://else.where:4567/puppet/ca', ProxyAPI::PuppetCA.new(:url => smart_proxies(:puppetmaster).url).url results = ActiveSupport::JSON.decode(@response.body) assert_equal 2, results['results'].length end test "should create autosign entry" do - ProxyAPI::Puppetca.any_instance.stubs(:set_autosign).returns(true) + ProxyAPI::PuppetCA.any_instance.stubs(:set_autosign).returns(true) post :create, params: { :smart_proxy_id => smart_proxies(:puppetmaster).id, :id => "test" } assert_response :success response = ActiveSupport::JSON.decode(@response.body) @@ -24,7 +24,7 @@ class Api::V2::AutosignControllerTest < ActionController::TestCase end test "should not create autosign entry" do - ProxyAPI::Puppetca.any_instance.stubs(:set_autosign).raises(@proxy_error) + ProxyAPI::PuppetCA.any_instance.stubs(:set_autosign).raises(@proxy_error) post :create, params: { :smart_proxy_id => smart_proxies(:puppetmaster).id, :id => "test" } assert_response :internal_server_error response = ActiveSupport::JSON.decode(@response.body) @@ -32,7 +32,7 @@ class Api::V2::AutosignControllerTest < ActionController::TestCase end test "should delete autosign entry" do - ProxyAPI::Puppetca.any_instance.stubs(:del_autosign).returns(true) + ProxyAPI::PuppetCA.any_instance.stubs(:del_autosign).returns(true) post :destroy, params: { :smart_proxy_id => smart_proxies(:puppetmaster).id, :id => "test" } assert_response :success response = ActiveSupport::JSON.decode(@response.body) @@ -40,7 +40,7 @@ class Api::V2::AutosignControllerTest < ActionController::TestCase end test "should not delete autosign entry" do - ProxyAPI::Puppetca.any_instance.stubs(:del_autosign).raises(@proxy_error) + ProxyAPI::PuppetCA.any_instance.stubs(:del_autosign).raises(@proxy_error) post :destroy, params: { :smart_proxy_id => smart_proxies(:puppetmaster).id, :id => "test" } assert_response :internal_server_error response = ActiveSupport::JSON.decode(@response.body) diff --git a/test/controllers/api/v2/domains_controller_test.rb b/test/controllers/api/v2/domains_controller_test.rb index 7fb0aec78e0..2d509089482 100644 --- a/test/controllers/api/v2/domains_controller_test.rb +++ b/test/controllers/api/v2/domains_controller_test.rb @@ -30,7 +30,7 @@ class Api::V2::DomainsControllerTest < ActionController::TestCase invalid_proxy_id = SmartProxy.last.id + 100 post :create, params: { :domain => { :name => "doma.in", :dns_id => invalid_proxy_id } } show_response = ActiveSupport::JSON.decode(@response.body) - assert_includes(show_response["error"]["full_messages"], "Dns Invalid smart-proxy id") + assert_includes(show_response["error"]["full_messages"], "DNS Invalid smart-proxy id") assert_response :unprocessable_entity end @@ -49,7 +49,7 @@ class Api::V2::DomainsControllerTest < ActionController::TestCase invalid_proxy_id = -1 post :update, params: { :id => Domain.first.to_param, :domain => { :name => "domain.new", :dns_id => invalid_proxy_id } } show_response = ActiveSupport::JSON.decode(@response.body) - assert_includes(show_response["error"]["full_messages"], "Dns Invalid smart-proxy id") + assert_includes(show_response["error"]["full_messages"], "DNS Invalid smart-proxy id") assert_response :unprocessable_entity end diff --git a/test/models/nics/dns_interface_test.rb b/test/models/nics/dns_interface_test.rb index b0703800401..1d4a48b2722 100644 --- a/test/models/nics/dns_interface_test.rb +++ b/test/models/nics/dns_interface_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class NicDnsInterfaceTest < ActiveSupport::TestCase +class NicDNSInterfaceTest < ActiveSupport::TestCase setup do disable_orchestration end diff --git a/test/models/orchestration/dhcp_test.rb b/test/models/orchestration/dhcp_test.rb index feb7cad8e52..fe73700a9a6 100644 --- a/test/models/orchestration/dhcp_test.rb +++ b/test/models/orchestration/dhcp_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class DhcpOrchestrationTest < ActiveSupport::TestCase +class DHCPOrchestrationTest < ActiveSupport::TestCase def setup disable_orchestration end diff --git a/test/models/orchestration/dns_test.rb b/test/models/orchestration/dns_test.rb index 56b294b96c1..c3bfdfe5334 100644 --- a/test/models/orchestration/dns_test.rb +++ b/test/models/orchestration/dns_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class DnsOrchestrationTest < ActiveSupport::TestCase +class DNSOrchestrationTest < ActiveSupport::TestCase def setup disable_orchestration end diff --git a/test/models/subnet/external_ipam_test.rb b/test/models/subnet/external_ipam_test.rb index 4130fc618d3..d471ec50b7a 100644 --- a/test/models/subnet/external_ipam_test.rb +++ b/test/models/subnet/external_ipam_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Subnet::ExternalIpamTest < ActiveSupport::TestCase +class Subnet::ExternalIPAMTest < ActiveSupport::TestCase test 'external ipam is supported for IPv4' do subnet = FactoryBot.build(:subnet_ipv4) assert subnet.supports_ipam_mode?(:external_ipam) diff --git a/test/models/token/puppetca_test.rb b/test/models/token/puppetca_test.rb index b0e1d7b9119..78efb2baf78 100644 --- a/test/models/token/puppetca_test.rb +++ b/test/models/token/puppetca_test.rb @@ -1,14 +1,14 @@ require 'test_helper' -class Token::PuppetcaTest < ActiveSupport::TestCase +class Token::PuppetCATest < ActiveSupport::TestCase should validate_uniqueness_of(:value) let(:host) { FactoryBot.create(:host) } test "a host can create a puppetca-token" do host.create_puppetca_token value: 'foo.bar.baz' - assert_instance_of Token::Puppetca, host.puppetca_token - assert_equal Token::Puppetca.first.host_id, host.id + assert_instance_of Token::PuppetCA, host.puppetca_token + assert_equal Token::PuppetCA.first.host_id, host.id assert_equal 'foo.bar.baz', host.puppetca_token.value end @@ -17,6 +17,6 @@ class Token::PuppetcaTest < ActiveSupport::TestCase assert_equal host.puppetca_token.value, 'aaaa' host.puppetca_token = nil assert_nil host.puppetca_token - assert_equal Token::Puppetca.all, [] + assert_equal Token::PuppetCA.all, [] end end diff --git a/test/unit/foreman/http_proxy_test.rb b/test/unit/foreman/http_proxy_test.rb index 9c147d537b4..eadc797684d 100644 --- a/test/unit/foreman/http_proxy_test.rb +++ b/test/unit/foreman/http_proxy_test.rb @@ -1,11 +1,11 @@ require 'test_helper' -class HTTPProxyTest < ActiveSupport::TestCase - class DummyHTTPAdapter - include Foreman::HTTPProxy +class Foreman::HttpProxyTest < ActiveSupport::TestCase + class DummyHttpAdapter + include Foreman::HttpProxy end - let(:adapter) { DummyHTTPAdapter.new } + let(:adapter) { DummyHttpAdapter.new } let(:http_proxy) { 'http://dummyproxy.theforeman.org:3218' } let(:excepted_hosts) { [] } let(:request_host) { 'dummyproxy.theforeman.org' } @@ -106,10 +106,10 @@ class DummyHTTPAdapter end describe 'Excon::Connection extension' do - let(:excon_connection) { Excon::Connection.new } + let(:excon_connection) { ::Excon::Connection.new } setup do - Excon::Connection.class_eval { prepend Foreman::HttpProxy::ExconConnectionExtension } if Excon::Connection.ancestors.first != Foreman::HttpProxy::ExconConnectionExtension + ::Excon::Connection.class_eval { prepend Foreman::HttpProxy::ExconConnectionExtension } if ::Excon::Connection.ancestors.first != Foreman::HttpProxy::ExconConnectionExtension excon_connection.stubs(:http_proxy).returns(http_proxy) excon_connection.stubs(:setup_proxy).returns excon_connection.stubs(:proxy_http_request?).returns(true) @@ -123,7 +123,7 @@ class DummyHTTPAdapter test 'rescues requests and mentions proxy' do stub_request(:get, "http://#{request_host}/features").to_raise("AnException") - assert_raises_with_message Excon::Error::Socket, "AnException" do + assert_raises_with_message ::Excon::Error::Socket, "AnException" do excon_connection.request({host: request_host, path: "/features", headers: {}}) end end @@ -145,7 +145,7 @@ class DummyHTTPAdapter test 'rescues requests and mentions proxy' do stub_request(:get, "http://#{request_host}/features") assert_raises_with_message StandardError.new, "Failed to open TCP connection" do - net_http.request(Net::HTTP::Get.new("/features")) + net_http.request(::Net::HTTP::Get.new("/features")) end end end diff --git a/test/unit/foreman_url_renderer_test.rb b/test/unit/foreman_url_renderer_test.rb index d3d76c2eb56..8a307c5ffc9 100644 --- a/test/unit/foreman_url_renderer_test.rb +++ b/test/unit/foreman_url_renderer_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class ForemanUrlRendererTest < ActiveSupport::TestCase +class ForemanURLRendererTest < ActiveSupport::TestCase setup do disable_orchestration end @@ -8,7 +8,7 @@ class ForemanUrlRendererTest < ActiveSupport::TestCase class Renderer include ActionView::Helpers include ActionDispatch::Routing - include ::Foreman::ForemanUrlRenderer + include ::Foreman::ForemanURLRenderer attr_accessor :host, :template_url end diff --git a/test/unit/ipam_test.rb b/test/unit/ipam_test.rb index 21f13916766..7a3a813aab8 100644 --- a/test/unit/ipam_test.rb +++ b/test/unit/ipam_test.rb @@ -9,7 +9,7 @@ class IPAMTest < ActiveSupport::TestCase fake_proxy = mock("dhcp_proxy") fake_proxy.stubs(:unused_ip => {'ip' => '192.168.1.25'}) subnet.stubs(:dhcp_proxy => fake_proxy) - ipam = IPAM::Dhcp.new(:subnet => subnet, :mac => '00:11:22:33:44:55') + ipam = IPAM::DHCP.new(:subnet => subnet, :mac => '00:11:22:33:44:55') assert_equal '192.168.1.25', ipam.suggest_ip end end diff --git a/test/unit/net/dhcp_test.rb b/test/unit/net/dhcp_test.rb index bca53732c79..e9170995b59 100644 --- a/test/unit/net/dhcp_test.rb +++ b/test/unit/net/dhcp_test.rb @@ -1,7 +1,6 @@ require 'test_helper' -require 'net' -class DhcpTest < ActiveSupport::TestCase +class DHCPTest < ActiveSupport::TestCase setup do @lease1 = setup_lease('{ "starts": "2014-05-09 11:55:21 UTC", diff --git a/test/unit/net/dns_test.rb b/test/unit/net/dns_test.rb index eb2eb10da55..d6ffcbaf39f 100644 --- a/test/unit/net/dns_test.rb +++ b/test/unit/net/dns_test.rb @@ -1,8 +1,6 @@ require 'test_helper' -require 'net' -require 'net/dns' -class DnsTest < ActiveSupport::TestCase +class DNSTest < ActiveSupport::TestCase setup do @proxy = smart_proxies(:one) end diff --git a/test/unit/net/net_test.rb b/test/unit/net/net_test.rb index f55b912e020..79e5fc70083 100644 --- a/test/unit/net/net_test.rb +++ b/test/unit/net/net_test.rb @@ -1,5 +1,4 @@ require 'test_helper' -require 'net' class NetTest < ActiveSupport::TestCase test "Net record should auto assign attributes" do diff --git a/test/unit/net/validations_test.rb b/test/unit/net/validations_test.rb index 7715044f181..706d7436249 100644 --- a/test/unit/net/validations_test.rb +++ b/test/unit/net/validations_test.rb @@ -1,5 +1,4 @@ require 'test_helper' -require 'net' class ValidationsTest < ActiveSupport::TestCase describe "validate_mac" do diff --git a/test/unit/proxy_api/bmc_test.rb b/test/unit/proxy_api/bmc_test.rb index 34a348f6951..f99f30902e5 100644 --- a/test/unit/proxy_api/bmc_test.rb +++ b/test/unit/proxy_api/bmc_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ProxyApiBmcTest < ActiveSupport::TestCase +class ProxyApiBMCTest < ActiveSupport::TestCase def setup @url = "http://dummyproxy.theforeman.org:8443" @options = {:username => "testuser", :password => "fakepass"} diff --git a/test/unit/proxy_api/dhcp_test.rb b/test/unit/proxy_api/dhcp_test.rb index d9e34d306e5..86d18d33e96 100644 --- a/test/unit/proxy_api/dhcp_test.rb +++ b/test/unit/proxy_api/dhcp_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ProxyApiDhcpTest < ActiveSupport::TestCase +class ProxyApiDHCPTest < ActiveSupport::TestCase let(:url) { 'http://dummyproxy.theforeman.org:8443' } let(:proxy_dhcp) { ProxyAPI::DHCP.new(:url => url) } diff --git a/test/unit/proxy_statuses/proxy_status_puppetca_test.rb b/test/unit/proxy_statuses/proxy_status_puppetca_test.rb index 7b31667bebf..8da00abe624 100644 --- a/test/unit/proxy_statuses/proxy_status_puppetca_test.rb +++ b/test/unit/proxy_statuses/proxy_status_puppetca_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ProxyStatusPuppetcaTest < ActiveSupport::TestCase +class ProxyStatusPuppetCATest < ActiveSupport::TestCase setup do @proxy = FactoryBot.build_stubbed(:smart_proxy, :url => 'https://secure.proxy:4568') # don't cache because the mock breaks when trying to cache the array of certs @@ -15,7 +15,7 @@ class ProxyStatusPuppetcaTest < ActiveSupport::TestCase "proxy.host.with_no_dates" => {"state" => "valid", "fingerprint" => "SHA256", "serial" => 5, "not_before" => nil, "not_after" => nil}, "refuted.host" => {"state" => "refuted", "fingerprint" => "SHA256", "serial" => 4, "not_before" => "2015-12-22T14:33:10UTC", "not_after" => "2020-12-22T14:33:10UTC"}, "pending.host" => {"state" => "pending", "fingerprint" => "SHA256", "serial" => 6}} - ProxyAPI::Puppetca.any_instance.stubs(:all).returns(certificates) + ProxyAPI::PuppetCA.any_instance.stubs(:all).returns(certificates) end test 'it returns all certificates' do @@ -42,7 +42,7 @@ class ProxyStatusPuppetcaTest < ActiveSupport::TestCase context 'CA has no certificates' do setup do - ProxyAPI::Puppetca.any_instance.stubs(:all).returns({}) + ProxyAPI::PuppetCA.any_instance.stubs(:all).returns({}) end test 'it returns no certificates' do @@ -57,27 +57,27 @@ class ProxyStatusPuppetcaTest < ActiveSupport::TestCase end test 'it allows signing a certificate' do - ProxyAPI::Puppetca.any_instance.expects(:sign_certificate).with('certificate_name').returns(true) + ProxyAPI::PuppetCA.any_instance.expects(:sign_certificate).with('certificate_name').returns(true) @proxy_status.sign('certificate_name') end test 'it allows revoking a certificate' do - ProxyAPI::Puppetca.any_instance.expects(:del_certificate).with('certificate_name').returns(true) + ProxyAPI::PuppetCA.any_instance.expects(:del_certificate).with('certificate_name').returns(true) @proxy_status.destroy('certificate_name') end test 'it returns autosign entries' do - ProxyAPI::Puppetca.any_instance.expects(:autosign).returns(['autosigned.com']) + ProxyAPI::PuppetCA.any_instance.expects(:autosign).returns(['autosigned.com']) assert_equal('autosigned.com', @proxy_status.autosign[0]) end test 'it allows adding an autosign entry' do - ProxyAPI::Puppetca.any_instance.expects(:set_autosign).with('host.name').returns(true) + ProxyAPI::PuppetCA.any_instance.expects(:set_autosign).with('host.name').returns(true) @proxy_status.set_autosign('host.name') end test 'it allows removing an autosign entry' do - ProxyAPI::Puppetca.any_instance.expects(:del_autosign).with('host.name').returns(true) + ProxyAPI::PuppetCA.any_instance.expects(:del_autosign).with('host.name').returns(true) @proxy_status.del_autosign('host.name') end end diff --git a/test/unit/report_scanner/puppet_report_scanner_test.rb b/test/unit/report_scanner/puppet_report_scanner_test.rb index 07fd06ca915..3b782c30de6 100644 --- a/test/unit/report_scanner/puppet_report_scanner_test.rb +++ b/test/unit/report_scanner/puppet_report_scanner_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class PuppetReportScannerTest < ActiveSupport::TestCase - subject { Foreman::PuppetReportScanner } + subject { ReportScanner::PuppetReportScanner } describe '.identify_origin' do it 'returns Puppet if puppet_report' do diff --git a/test/unit/shared/access_permissions_test_base.rb b/test/unit/shared/access_permissions_test_base.rb index 319ea2dead3..5f697389ae8 100644 --- a/test/unit/shared/access_permissions_test_base.rb +++ b/test/unit/shared/access_permissions_test_base.rb @@ -1,5 +1,4 @@ require 'foreman/access_control' -require 'foreman/access_permissions' module AccessPermissionsTestBase extend ActiveSupport::Concern diff --git a/test/unit/validators/url_schema_validator_test.rb b/test/unit/validators/url_schema_validator_test.rb index 1c59800f284..82a7df8352c 100644 --- a/test/unit/validators/url_schema_validator_test.rb +++ b/test/unit/validators/url_schema_validator_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class UrlSchemaValidatorTest < ActiveSupport::TestCase +class URLSchemaValidatorTest < ActiveSupport::TestCase class Validatable include ActiveModel::Validations validates :url, :url_schema => ['http', 'https', 'nfs', 'ftp']