Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #29991 - Enable Zeitwerk #10131

Merged
merged 25 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
287fdef
Fixes #33895 - Set up Zeitwerk inflector
ekohl Mar 4, 2024
6b3cd6f
Fixes #29991 - Enable Zeitwerk
ofedoren May 2, 2024
4b8cae5
Refs #29991 - Remove require_dependency calls
ofedoren May 2, 2024
7205c5b
Refs #29991 - More PuppetCA renaming
ofedoren May 2, 2024
9708eac
Refs #29991 - Fix rubocop
ofedoren May 2, 2024
5523d2f
Refs #29991 - Fix test
ofedoren May 2, 2024
80c5501
Refs #29991 - Clean up some requirements
ofedoren May 2, 2024
3f65263
Refs #29991 - Fix TelemetryHelper initialization warning
ofedoren May 2, 2024
2f60c60
Refs #29991 - Fix CsvExporter initialization warning
ofedoren May 2, 2024
4a98897
Refs #29991 - Move net into app/lib
ofedoren May 2, 2024
0736270
Refs #29991 - Fix deprecation warnings for Settings
ofedoren May 2, 2024
1b3b1df
Refs #29991 - Fix deprecation warnings for AuditAssociations
ofedoren May 2, 2024
f268711
Refs #29991 - Fix deprecation warnings for Foreman::Provision
ofedoren May 2, 2024
c9aa124
Refs #29991 - Fix deprecations warnings for MeduimProviders/ReportSca…
ofedoren May 2, 2024
864948b
Refs #29991 - Preload STI differently
ofedoren May 2, 2024
5325a41
Refs #29991 - Enable eager loading in test env
ofedoren May 2, 2024
fb9f37a
Refs #29991 - Move http_proxy to app/lib
ofedoren May 2, 2024
7394a0c
Refs #29991 - Fix tests
ofedoren May 2, 2024
6b3c8b0
Refs #29991 - Fix rubocop
ofedoren May 2, 2024
c1f7e3b
Refs #29991 - Fix empty resources in tests
ofedoren May 7, 2024
1198388
Refs #29991 - Fix ReportScanner warning with plugins in mind
ofedoren May 10, 2024
bac3bab
Refs #29991 - Apply review suggestions
ofedoren May 10, 2024
b90a590
Refs #29991 - Deal with Nic model by explicit preloading
ofedoren Jun 28, 2024
cbd60cb
Refs #29991 - Make VM an acronym
ofedoren Jul 8, 2024
9bc2128
Refs #29991 - Move settings into initializers
ofedoren Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/autosign_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/api/v2/interfaces_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency File.join(Rails.root, "app/models/nic/base")

module Api
module V2
class InterfacesController < V2::BaseController
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/bmc_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module BmcHelper
module BMCHelper
def power_status(s)
case s.try(:downcase)
when 'on'
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hosts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
6 changes: 1 addition & 5 deletions lib/foreman/http_proxy.rb → app/lib/foreman/http_proxy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Foreman
module HTTPProxy
module HttpProxy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps HTTP needs to be its own acronym as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you then update #10076? For some reason though, I didn't make this an acronym in my alternative. Maybe there are more pitfalls than it seems...

def http_proxy
ActiveRecord::Base.connection_pool.with_connection do
Setting[:http_proxy].presence
Expand Down Expand Up @@ -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__)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Foreman
module HttpProxy
class NetHttpExt < Net::HTTP
include Foreman::HTTPProxy
include Foreman::HttpProxy

def proxy?
!!proxy_uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/lib/net/dhcp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Net
module DHCP
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions lib/net/dns.rb → app/lib/net/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions lib/net.rb → app/lib/net/record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency "net/validations"

module Net
class Record
attr_accessor :hostname, :proxy, :logger
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'fog_extensions/vsphere/mini_servers'
require 'foreman/exception'

begin
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/dns_interface.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module DnsInterface
module DNSInterface
extend ActiveSupport::Concern

RECORD_TYPES = [:a, :aaaa, :ptr4, :ptr6]
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module Base
extend ActiveSupport::Concern
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/base_host_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module BaseHostExtensions
extend ActiveSupport::Concern
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/hostgroup_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module HostgroupExtensions
extend ActiveSupport::Concern
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/hostgroup_facet.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module HostgroupFacet
extend ActiveSupport::Concern
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/managed_host_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module ManagedHostExtensions
extend ActiveSupport::Concern
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/facets/model_extensions_base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'facets'

module Facets
module ModelExtensionsBase
extend ActiveSupport::Concern
Expand Down
8 changes: 2 additions & 6 deletions app/models/concerns/foreman/sti.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/foreman_register/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/host_template_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions app/models/concerns/orchestration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require_dependency "proxy_api"
require_dependency 'orchestration/queue'

module Orchestration
extend ActiveSupport::Concern
include Orchestration::ProgressReport
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/orchestration/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
14 changes: 7 additions & 7 deletions app/models/concerns/orchestration/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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
return true unless feasible.any?

results = {}

DnsInterface::RECORD_TYPES.each do |record_type|
DNSInterface::RECORD_TYPES.each do |record_type|
del_dns_record_safe(record_type)

begin
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Orchestration::Puppetca
module Orchestration::PuppetCA
extend ActiveSupport::Concern
include Orchestration::Common

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/orchestration/ssh_provision.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Orchestration::SSHProvision
module Orchestration::SshProvision
extend ActiveSupport::Concern

included do
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/url_validation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module UrlValidation
module URLValidation
extend ActiveSupport::Concern

def is_http_url?(url)
Expand Down
2 changes: 0 additions & 2 deletions app/models/host/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -645,5 +645,3 @@ def set_creator_id
end
end
end

require_dependency 'host/managed'
Loading
Loading