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

Prepare for rails 7 #41

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 8 additions & 32 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
require:
- rubocop-rails
inherit_gem:
theforeman-rubocop:
- lenient.yml
- minitest.yml

AllCops:
TargetRubyVersion: 2.7
TargetRailsVersion: 5.2
Exclude:
- '*.spec'
- 'extras/**/*'
- 'locale/**/*'
- 'node_modules/**/*'
- 'vendor/**/*'

Metrics/BlockLength:
Exclude:
- 'test/**/*' # context blocks can be long

# Just so it looks like core Foreman
Style/HashSyntax:
EnforcedStyle: hash_rockets
Metrics:
Enabled: false

Naming/FileName:
Exclude:
- 'db/seeds.d/*'

Rails/RakeEnvironment:
Enabled: false

Layout/DotPosition:
EnforcedStyle: 'trailing'

Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/LineLength:
Enabled: false

Rails/ActionFilter:
EnforcedStyle: action

Style/RaiseArgs:
EnforcedStyle: compact

Style/SymbolArray:
EnforcedStyle: brackets

Style/FormatStringToken:
EnforcedStyle: template

Style/FormatString:
EnforcedStyle: percent

Rails/SkipsModelValidations:
Enabled: false

Metrics:
Enabled: false

Rails:
Enabled: true
Exclude:
- 'app/models/foreman_acd/app_instance.rb'
5 changes: 3 additions & 2 deletions app/controllers/foreman_acd/ansible_playbooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def create
end
end

def edit; end
def edit
end

def update
# Move synced repo to new path if ansible_playbook name is changed
Expand Down Expand Up @@ -80,7 +81,7 @@ def sync_git_repo
if sync_params[:git_commit].empty?
if ForemanAcd.proxy_setting.present?
err_msg = _('Please set the Git Branch/Tag/Commit. This setting is necessary if a HTTP proxy is used!')
raise StandardError.new err_msg
raise StandardError, err_msg
else
commit = Git.ls_remote(sync_params[:git_url])['head'][:sha]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class AnsiblePlaybooksController < ::ForemanAcd::Api::V2::BaseController

api :GET, '/ansible_playbooks/:id', N_('Show ansible playbook')
param :id, :identifier, :required => true
def show; end
def show
end

api :GET, '/ansible_playbooks', N_('List ansible playbooks')
param_group :search_and_pagination, ::Api::V2::BaseController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class AppDefinitionsController < ::ForemanAcd::Api::V2::BaseController

api :GET, '/app_definitions/:id', N_('Show application definition')
param :id, :identifier, :required => true
def show; end
def show
end

api :GET, '/app_definitions', N_('List application definitions')
param_group :search_and_pagination, ::Api::V2::BaseController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class AppInstancesController < ::ForemanAcd::Api::V2::BaseController
param :id, :identifier, :required => true
param :organization_id, :identifier, :required => true
param :location_id, :identifier, :required => true
def show; end
def show
end

api :GET, '/app_instances', N_('List application instances')
param :organization_id, :identifier, :required => true
Expand Down
10 changes: 4 additions & 6 deletions app/controllers/foreman_acd/app_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ def create
process_error
end
rescue StandardError, ValidationError => e
if params[:foreman_acd_app_definition_import].present?
AnsiblePlaybook.find(params[:foreman_acd_app_definition][:acd_ansible_playbook_id]).delete if params[:foreman_acd_app_definition][:acd_ansible_playbook_id].present?
end
AnsiblePlaybook.find(params[:foreman_acd_app_definition][:acd_ansible_playbook_id]).delete if params[:foreman_acd_app_definition_import].present? && params[:foreman_acd_app_definition][:acd_ansible_playbook_id].present?
redirect_to new_app_definition_path, :flash => { :error => _(e.message) }
end
end

def edit; end
def edit
end

def update
if @app_definition.update(app_definition_params)
Expand Down Expand Up @@ -132,8 +131,7 @@ def create_ansible_playbook(dir, ansible_playbook, dir_path)
FileUtils.cp_r "#{dir}/#{ansible_playbook['path']}/.", dir_path
ansible_playbook['path'] = dir_path
ansible_playbook['name'] = File.basename(dir_path)
new_playbook = AnsiblePlaybook.create(ansible_playbook)
new_playbook
AnsiblePlaybook.create(ansible_playbook)
rescue StandardError => e
logger.info("Error while creating AnsiblePlaybook: #{e}")
end
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/foreman_acd/app_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def create
end
end

def edit; end
def edit
end

def update
if @app_instance.update(app_instance_params)
Expand Down Expand Up @@ -110,19 +111,19 @@ def app_instance_has_foreman_hosts

@app_instance.foreman_hosts.where(:hostname => h['hostname']).
update(:service => h['service'], :description => h['description'],
:foremanParameters => JSON.dump(h['foremanParameters']), :ansibleParameters => JSON.dump(h['ansibleParameters']))
:foremanParameters => JSON.dump(h['foremanParameters']), :ansibleParameters => JSON.dump(h['ansibleParameters']))

updated_host = @app_instance.foreman_hosts.find_by(:hostname => h['hostname'])

# Store hosts if updated for safe deploy
session[:remember_hosts] << updated_host.id if updated_host.updated_at != old_host.updated_at
else
@app_instance.foreman_hosts.create(:hostname => h['hostname'],
:service => h['service'],
:description => h['description'],
:is_existing_host => h['isExistingHost'],
:foremanParameters => JSON.dump(h['foremanParameters']),
:ansibleParameters => JSON.dump(h['ansibleParameters']))
:service => h['service'],
:description => h['description'],
:is_existing_host => h['isExistingHost'],
:foremanParameters => JSON.dump(h['foremanParameters']),
:ansibleParameters => JSON.dump(h['ansibleParameters']))
# Store new hosts for safe deploy
session[:remember_hosts] << @app_instance.foreman_hosts.find_by(:hostname => h['hostname']).id
end
Expand All @@ -143,7 +144,7 @@ def collect_hosts_data
:description => h.description,
:isExistingHost => h.is_existing_host,
:foremanParameters => JSON.parse(h.foremanParameters),
:ansibleParameters => JSON.parse(h.ansibleParameters)
:ansibleParameters => JSON.parse(h.ansibleParameters),
}
end
hosts_data
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/foreman_acd/concerns/app_instance_mixins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def collect_host_report_data(app_instance)
:name => foreman_host.hostname,
:build => nil,
:hostUrl => nil,
:progress_report => foreman_host.last_progress_report.empty? ? [] : JSON.parse(foreman_host.last_progress_report)
:progress_report => foreman_host.last_progress_report.empty? ? [] : JSON.parse(foreman_host.last_progress_report),
}

if foreman_host.host.present?
a_host.update({
:id => foreman_host.host.id,
:build => foreman_host.host.build,
:hostUrl => host_path(foreman_host.host),
:isExistingHost => foreman_host.is_existing_host,
:powerStatusUrl => power_api_host_path(foreman_host.host)
})
:id => foreman_host.host.id,
:build => foreman_host.host.build,
:hostUrl => host_path(foreman_host.host),
:isExistingHost => foreman_host.is_existing_host,
:powerStatusUrl => power_api_host_path(foreman_host.host),
})
end
report_data << OpenStruct.new(a_host)
end
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/ui_acd_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def collect_report_data(app_instance_id)
report_data = {
:hosts => collect_host_report_data(app_instance),
:deploymentState => app_instance.deployment_state.to_s,
:initialConfigureState => app_instance.initial_configure_state.to_s
:initialConfigureState => app_instance.initial_configure_state.to_s,
}
report_data['initialConfigureJobUrl'] = job_invocation_path(app_instance.initial_configure_job) unless app_instance.initial_configure_job.nil?

Expand All @@ -71,15 +71,14 @@ def collect_report_data(app_instance_id)

def hostname_duplicate?(app_def_id, service_id, hostname)
app_definition = ForemanAcd::AppDefinition.find(app_def_id)
service_data = JSON.parse(app_definition.services).select { |k| k['id'] == service_id }.first
service_data = JSON.parse(app_definition.services).find { |k| k['id'] == service_id }
domain_name = Hostgroup.find(service_data['hostgroup']).domain.name
validation_hostname = "#{hostname}.#{domain_name}"

vdata = OpenStruct.new(
OpenStruct.new(
:hostname => hostname,
:fqdn => validation_hostname,
:result => Host.find_by(:name => validation_hostname).nil?
)
vdata
end
end
3 changes: 2 additions & 1 deletion app/lib/actions/foreman_acd/deploy_all_hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def run
end
end

def finalize; end
def finalize
end

def rescue_strategy
Dynflow::Action::Rescue::Fail
Expand Down
3 changes: 2 additions & 1 deletion app/lib/actions/foreman_acd/run_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def run
end
end

def finalize; end
def finalize
end

def rescue_strategy
Dynflow::Action::Rescue::Fail
Expand Down
12 changes: 6 additions & 6 deletions app/models/concerns/foreman_acd/host_managed_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def self.prepended(base)
has_many :app_instances, :through => :foreman_hosts, :class_name => 'ForemanAcd::AppInstance'

scoped_search :relation => :app_instances,
:on => :name,
:rename => :acd_app_instance,
:only_explicit => true,
:complete_value => true,
:operators => ['= '],
:ext_method => :find_by_acd_app_instance_name
:on => :name,
:rename => :acd_app_instance,
:only_explicit => true,
:complete_value => true,
:operators => ['= '],
:ext_method => :find_by_acd_app_instance_name
end

base.singleton_class.prepend ClassMethods
Expand Down
9 changes: 6 additions & 3 deletions app/models/foreman_acd/acd_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def proxy_command_options(template_invocation, host)
super(template_invocation, host).merge(:name => host.name)
end

def ssh_password(_host); end
def ssh_password(_host)
end

def ssh_key_passphrase(_host); end
def ssh_key_passphrase(_host)
end

def sudo_password(_host); end
def sudo_password(_host)
end

# Workaround till infrastructure jobs on proxies are possible. See
# configure in services/foreman_acd/app_configurator.rb for more details.
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_acd/ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def content
when 'directory' || 'git'
File.read(File.join(path, playfile))
else
raise NotImplementedError.new "scm_type #{scm_type.inspect} not supported!"
raise NotImplementedError, "scm_type #{scm_type.inspect} not supported!"
end
end

Expand Down
15 changes: 7 additions & 8 deletions app/models/foreman_acd/app_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ def deployment_state
return :new if last_deploy_task.nil?
return :initiated if !last_deploy_task.nil? && last_deploy_task.ended_at.nil?

state = if all_hosts_deployed?
:finished
elsif last_deploy_task.ended_at? && last_deploy_task.result != 'success'
:failed
else
:pending
end
state
if all_hosts_deployed?
:finished
elsif last_deploy_task.ended_at? && last_deploy_task.result != 'success'
:failed
else
:pending
end
end

def initial_configure_job
Expand Down
4 changes: 3 additions & 1 deletion app/services/foreman_acd/app_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module ForemanAcd
class AppConfigurator
delegate :logger, :to => :Rails

PROXY_NOT_SUPPORTED_LABELS = [:not_available, :not_defined].freeze

def initialize(app_instance)
@app_instance = app_instance
end
Expand Down Expand Up @@ -42,7 +44,7 @@ def configure
return [result, job]
end
proxy = proxy_selector.determine_proxy(h.host, 'ACD')
raise StandardError.new('Proxy without ACD feature') if proxy.nil? || [:not_available, :not_defined].include?(proxy)
raise StandardError, 'Proxy without ACD feature' if proxy.nil? || PROXY_NOT_SUPPORTED_LABELS.include?(proxy)
proxy_hosts[proxy.name] = [] unless proxy_hosts.key?(proxy.name)
proxy_hosts[proxy.name] << h
result.success = true
Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman_acd/app_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def deploy(safe_deploy)
end

foreman_hosts.each do |foreman_host|
service_data = services.select { |k| k['id'] == foreman_host.service.to_i }.first
service_data = services.find { |k| k['id'] == foreman_host.service.to_i }

# Handle already deployed hosts
if foreman_host.existing_host?
Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman_acd/inventory_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create_inventory
end

service_id = foreman_host.service.to_i
host_service = services.select { |s| s['id'] == service_id }.first
host_service = services.find { |s| s['id'] == service_id }
ansible_group = host_service['ansibleGroup']

children[ansible_group] = { 'hosts' => {} } unless children.key?(host_service['ansibleGroup'])
Expand Down
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@

match '/remote_execution', :controller => 'foreman_acd/remote_execution', :action => 'create', :via => [:post]

get 'ui_acd_app/:id', :to => 'ui_acd#app', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_app
get 'ui_acd_foreman_data/:id', :to => 'ui_acd#foreman_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_foreman_data
get 'ui_acd_ansible_data/:id', :to => 'ui_acd#ansible_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_ansible_data
get 'ui_acd_report_data/:id', :to => 'ui_acd#report_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_report_data
get 'ui_acd_app/:id', :to => 'ui_acd#app', :constraints => { :id => /[\w.-]+/ }, :as => :ui_acd_app
get 'ui_acd_foreman_data/:id', :to => 'ui_acd#foreman_data', :constraints => { :id => /[\w.-]+/ }, :as => :ui_acd_foreman_data
get 'ui_acd_ansible_data/:id', :to => 'ui_acd#ansible_data', :constraints => { :id => /[\w.-]+/ }, :as => :ui_acd_ansible_data
get 'ui_acd_report_data/:id', :to => 'ui_acd#report_data', :constraints => { :id => /[\w.-]+/ }, :as => :ui_acd_report_data
get 'ui_acd_validate_hostname', :to => 'ui_acd#validate_hostname', :as => :ui_acd_validate_hostname

scope :api, :path => '/api', :defaults => { :format => 'json' } do
scope '(:apiv)', :defaults => { :apiv => 'v2' },
:apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2) do
constraints(:id => /[\w\.-]+/) do
constraints(:id => /[\w.-]+/) do
resources :app_definitions, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_definitions', :as => :acd_api_v2_app_definitions
resources :app_instances, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_instances', :as => :api_v2_foreman_acd_app_instances
resources :ansible_playbooks, :only => [:show, :index], :controller => 'foreman_acd/api/v2/ansible_playbooks', :as => :api_v2_foreman_acd_ansible_playbooks do
Expand Down
Loading
Loading