diff --git a/.rubocop.yml b/.rubocop.yml index 8afd7c0b..c71ff248 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,10 @@ -require: - - rubocop-rails +inherit_gem: + theforeman-rubocop: + - lenient.yml + - minitest.yml AllCops: TargetRubyVersion: 2.7 - TargetRailsVersion: 5.2 Exclude: - '*.spec' - 'extras/**/*' @@ -11,39 +12,19 @@ AllCops: - '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 @@ -51,10 +32,5 @@ Style/FormatString: EnforcedStyle: percent Rails/SkipsModelValidations: - Enabled: false - -Metrics: - Enabled: false - -Rails: - Enabled: true + Exclude: + - 'app/models/foreman_acd/app_instance.rb' diff --git a/app/controllers/foreman_acd/ansible_playbooks_controller.rb b/app/controllers/foreman_acd/ansible_playbooks_controller.rb index 3528c189..479b3e15 100644 --- a/app/controllers/foreman_acd/ansible_playbooks_controller.rb +++ b/app/controllers/foreman_acd/ansible_playbooks_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb b/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb index d0155f85..8d54e5fe 100644 --- a/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +++ b/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb @@ -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 diff --git a/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb b/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb index 4c23d551..fdc218d0 100644 --- a/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +++ b/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb @@ -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 diff --git a/app/controllers/foreman_acd/api/v2/app_instances_controller.rb b/app/controllers/foreman_acd/api/v2/app_instances_controller.rb index 33e671e0..5347e8a0 100644 --- a/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +++ b/app/controllers/foreman_acd/api/v2/app_instances_controller.rb @@ -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 diff --git a/app/controllers/foreman_acd/app_definitions_controller.rb b/app/controllers/foreman_acd/app_definitions_controller.rb index 599d8c68..ea434acf 100644 --- a/app/controllers/foreman_acd/app_definitions_controller.rb +++ b/app/controllers/foreman_acd/app_definitions_controller.rb @@ -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) @@ -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 diff --git a/app/controllers/foreman_acd/app_instances_controller.rb b/app/controllers/foreman_acd/app_instances_controller.rb index a9b705b2..2923b43a 100644 --- a/app/controllers/foreman_acd/app_instances_controller.rb +++ b/app/controllers/foreman_acd/app_instances_controller.rb @@ -38,7 +38,8 @@ def create end end - def edit; end + def edit + end def update if @app_instance.update(app_instance_params) @@ -110,7 +111,7 @@ 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']) @@ -118,11 +119,11 @@ def app_instance_has_foreman_hosts 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 @@ -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 diff --git a/app/controllers/foreman_acd/concerns/app_instance_mixins.rb b/app/controllers/foreman_acd/concerns/app_instance_mixins.rb index 4a4810f7..8613dda1 100644 --- a/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +++ b/app/controllers/foreman_acd/concerns/app_instance_mixins.rb @@ -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 diff --git a/app/controllers/ui_acd_controller.rb b/app/controllers/ui_acd_controller.rb index 97fc6eba..85dff9b3 100644 --- a/app/controllers/ui_acd_controller.rb +++ b/app/controllers/ui_acd_controller.rb @@ -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? @@ -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 diff --git a/app/lib/actions/foreman_acd/deploy_all_hosts.rb b/app/lib/actions/foreman_acd/deploy_all_hosts.rb index c61de052..3e5971df 100644 --- a/app/lib/actions/foreman_acd/deploy_all_hosts.rb +++ b/app/lib/actions/foreman_acd/deploy_all_hosts.rb @@ -32,7 +32,8 @@ def run end end - def finalize; end + def finalize + end def rescue_strategy Dynflow::Action::Rescue::Fail diff --git a/app/lib/actions/foreman_acd/run_configurator.rb b/app/lib/actions/foreman_acd/run_configurator.rb index 6ce2aefc..eeed5efc 100644 --- a/app/lib/actions/foreman_acd/run_configurator.rb +++ b/app/lib/actions/foreman_acd/run_configurator.rb @@ -31,7 +31,8 @@ def run end end - def finalize; end + def finalize + end def rescue_strategy Dynflow::Action::Rescue::Fail diff --git a/app/models/concerns/foreman_acd/host_managed_extensions.rb b/app/models/concerns/foreman_acd/host_managed_extensions.rb index f5890e3a..963ba743 100644 --- a/app/models/concerns/foreman_acd/host_managed_extensions.rb +++ b/app/models/concerns/foreman_acd/host_managed_extensions.rb @@ -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 diff --git a/app/models/foreman_acd/acd_provider.rb b/app/models/foreman_acd/acd_provider.rb index 424a81d6..7b9930ac 100644 --- a/app/models/foreman_acd/acd_provider.rb +++ b/app/models/foreman_acd/acd_provider.rb @@ -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. diff --git a/app/models/foreman_acd/ansible_playbook.rb b/app/models/foreman_acd/ansible_playbook.rb index 8e1aa2cc..b98bd4c6 100644 --- a/app/models/foreman_acd/ansible_playbook.rb +++ b/app/models/foreman_acd/ansible_playbook.rb @@ -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 diff --git a/app/models/foreman_acd/app_instance.rb b/app/models/foreman_acd/app_instance.rb index 2d386ac8..9624aab8 100644 --- a/app/models/foreman_acd/app_instance.rb +++ b/app/models/foreman_acd/app_instance.rb @@ -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 diff --git a/app/services/foreman_acd/app_configurator.rb b/app/services/foreman_acd/app_configurator.rb index cbc9ee36..df7c2674 100644 --- a/app/services/foreman_acd/app_configurator.rb +++ b/app/services/foreman_acd/app_configurator.rb @@ -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 @@ -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 diff --git a/app/services/foreman_acd/app_deployer.rb b/app/services/foreman_acd/app_deployer.rb index 79577dd4..1865eada 100644 --- a/app/services/foreman_acd/app_deployer.rb +++ b/app/services/foreman_acd/app_deployer.rb @@ -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? diff --git a/app/services/foreman_acd/inventory_creator.rb b/app/services/foreman_acd/inventory_creator.rb index c7db0606..fca541f2 100644 --- a/app/services/foreman_acd/inventory_creator.rb +++ b/app/services/foreman_acd/inventory_creator.rb @@ -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']) diff --git a/config/routes.rb b/config/routes.rb index 25c4d3a1..6ccf8d8e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/foreman_acd.gemspec b/foreman_acd.gemspec index 28ee73ad..d52db9b7 100644 --- a/foreman_acd.gemspec +++ b/foreman_acd.gemspec @@ -18,9 +18,9 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib,locale,webpack}/**/*'] + ['LICENSE', 'Rakefile', 'README.md', 'package.json'] s.test_files = Dir['test/**/*'] - s.add_development_dependency 'rubocop', '~> 0.89.0' - s.add_development_dependency 'rubocop-rails', '~> 2.8.1' s.add_dependency 'foreman_remote_execution', '>= 8.0' s.add_dependency 'foreman-tasks', '>= 7.0' s.add_dependency 'git' + + s.add_development_dependency 'theforeman-rubocop', '~> 0.1.0' end diff --git a/lib/foreman_acd.rb b/lib/foreman_acd.rb index 697be8e5..be8c83f0 100644 --- a/lib/foreman_acd.rb +++ b/lib/foreman_acd.rb @@ -29,8 +29,8 @@ def initiate_acd_app_configurator(app_instance) def start_acd_app_configurator(app_instance) task = ForemanTasks.delay(::Actions::ForemanAcd::RunConfigurator, - { :start_at => Time.zone.now + RUN_CONFIGURATOR_DELAY }, - app_instance) + { :start_at => Time.zone.now + RUN_CONFIGURATOR_DELAY }, + app_instance) app_instance.update(:initial_configure_task_id => task.id) end end diff --git a/lib/foreman_acd/engine.rb b/lib/foreman_acd/engine.rb index cc456645..42d846e2 100644 --- a/lib/foreman_acd/engine.rb +++ b/lib/foreman_acd/engine.rb @@ -70,7 +70,7 @@ def self.register_rex_feature N_('Run playbook for ACD'), { :description => N_('Run an Ansible playbook to configure ACD application'), - :provided_inputs => %w[application_name playbook_name playbook_path inventory_path] + :provided_inputs => %w[application_name playbook_name playbook_path inventory_path], } ) end diff --git a/lib/foreman_acd/plugin.rb b/lib/foreman_acd/plugin.rb index 64ae5e86..66af7ba9 100644 --- a/lib/foreman_acd/plugin.rb +++ b/lib/foreman_acd/plugin.rb @@ -8,123 +8,123 @@ # Menus sub_menu :top_menu, :application, :caption => N_('Applications'), :after => :hosts_menu, :icon => 'pficon pficon-integration' do menu :top_menu, :ansible_playbooks, - :url_hash => { :controller => :'foreman_acd/ansible_playbooks', :action => :index }, - :caption => 'Ansible Playbooks' + :url_hash => { :controller => :'foreman_acd/ansible_playbooks', :action => :index }, + :caption => 'Ansible Playbooks' menu :top_menu, :app_definitions, - :url_hash => { :controller => :'foreman_acd/app_definitions', :action => :index }, - :caption => 'App Definitions' + :url_hash => { :controller => :'foreman_acd/app_definitions', :action => :index }, + :caption => 'App Definitions' menu :top_menu, :app_instances, - :url_hash => { :controller => :'foreman_acd/app_instances', :action => :index }, - :caption => 'App Instances' + :url_hash => { :controller => :'foreman_acd/app_instances', :action => :index }, + :caption => 'App Instances' end # Add permissions security_block :foreman_acd do permission :create_ansible_playbooks, - { :'foreman_acd/ansible_playbooks' => [:new, :create], - :'foreman_acd/api/v2/ansible_playbooks' => [:create] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/ansible_playbooks' => [:new, :create], + :'foreman_acd/api/v2/ansible_playbooks' => [:create] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :view_ansible_playbooks, - { :'foreman_acd/ansible_playbooks' => [:index, :show, :auto_complete_search], - :'foreman_acd/api/v2/ansible_playbooks' => [:index, :show] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/ansible_playbooks' => [:index, :show, :auto_complete_search], + :'foreman_acd/api/v2/ansible_playbooks' => [:index, :show] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :edit_ansible_playbooks, - { :'foreman_acd/ansible_playbooks' => [:update, :edit, :sync_git_repo], - :'foreman_acd/api/v2/ansible_playbooks' => [:update] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/ansible_playbooks' => [:update, :edit, :sync_git_repo], + :'foreman_acd/api/v2/ansible_playbooks' => [:update] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :destroy_ansible_playbooks, - { :'foreman_acd/ansible_playbooks' => [:destroy], - :'foreman_acd/api/v2/ansible_playbooks' => [:destroy] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/ansible_playbooks' => [:destroy], + :'foreman_acd/api/v2/ansible_playbooks' => [:destroy] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :import_vars_ansible_playbooks, - { :'foreman_acd/ansible_playbooks' => [:import_vars], - :'foreman_acd/api/v2/ansible_playbooks' => [:import_vars] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/ansible_playbooks' => [:import_vars], + :'foreman_acd/api/v2/ansible_playbooks' => [:import_vars] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :grab_ansible_playbooks, - { :'foreman_acd/api/v2/ansible_playbooks' => [:grab] }, - :resource_type => 'ForemanAcd::AnsiblePlaybook' + { :'foreman_acd/api/v2/ansible_playbooks' => [:grab] }, + :resource_type => 'ForemanAcd::AnsiblePlaybook' permission :create_app_definitions, - { :'foreman_acd/app_definitions' => [:new, :create], - :'foreman_acd/api/v2/app_definitions' => [:create] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:new, :create], + :'foreman_acd/api/v2/app_definitions' => [:create] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :view_app_definitions, - { :'foreman_acd/app_definitions' => [:index, :show, :auto_complete_search], - :'foreman_acd/api/v2/app_definitions' => [:index, :show] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:index, :show, :auto_complete_search], + :'foreman_acd/api/v2/app_definitions' => [:index, :show] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :edit_app_definitions, - { :'foreman_acd/app_definitions' => [:update, :edit], - :'foreman_acd/api/v2/app_definitions' => [:update] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:update, :edit], + :'foreman_acd/api/v2/app_definitions' => [:update] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :destroy_app_definitions, - { :'foreman_acd/app_definitions' => [:destroy], - :'foreman_acd/api/v2/app_definitions' => [:destroy] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:destroy], + :'foreman_acd/api/v2/app_definitions' => [:destroy] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :export_app_definitions, - { :'foreman_acd/app_definitions' => [:export, :handle_file_upload], - :'foreman_acd/api/v2/app_definitions' => [:export] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:export, :handle_file_upload], + :'foreman_acd/api/v2/app_definitions' => [:export] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :import_app_definitions, - { :'foreman_acd/app_definitions' => [:import], - :'foreman_acd/api/v2/app_definitions' => [:import] }, - :resource_type => 'ForemanAcd::AppDefinition' + { :'foreman_acd/app_definitions' => [:import], + :'foreman_acd/api/v2/app_definitions' => [:import] }, + :resource_type => 'ForemanAcd::AppDefinition' permission :create_app_instances, - { :'foreman_acd/app_instances' => [:new, :create], - :'foreman_acd/api/v2/app_instances' => [:create] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:new, :create], + :'foreman_acd/api/v2/app_instances' => [:create] }, + :resource_type => 'ForemanAcd::AppInstance' permission :view_app_instances, - { :'foreman_acd/app_instances' => [:index, :show, :auto_complete_search], - :'foreman_acd/api/v2/app_instances' => [:index, :show] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:index, :show, :auto_complete_search], + :'foreman_acd/api/v2/app_instances' => [:index, :show] }, + :resource_type => 'ForemanAcd::AppInstance' permission :edit_app_instances, - { :'foreman_acd/app_instances' => [:update, :edit], - :'foreman_acd/api/v2/app_instances' => [:update] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:update, :edit], + :'foreman_acd/api/v2/app_instances' => [:update] }, + :resource_type => 'ForemanAcd::AppInstance' permission :destroy_app_instances, - { :'foreman_acd/app_instances' => [:destroy, :destroy_with_hosts], - :'foreman_acd/api/v2/app_instances' => [:destroy, :destroy_with_hosts] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:destroy, :destroy_with_hosts], + :'foreman_acd/api/v2/app_instances' => [:destroy, :destroy_with_hosts] }, + :resource_type => 'ForemanAcd::AppInstance' permission :deploy_app_instances, - { :'foreman_acd/app_instances' => [:deploy], - :'foreman_acd/api/v2/app_instances' => [:deploy] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:deploy], + :'foreman_acd/api/v2/app_instances' => [:deploy] }, + :resource_type => 'ForemanAcd::AppInstance' permission :report_app_instances, - { :'foreman_acd/app_instances' => [:report], - :'foreman_acd/api/v2/app_instances' => [:report] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/app_instances' => [:report], + :'foreman_acd/api/v2/app_instances' => [:report] }, + :resource_type => 'ForemanAcd::AppInstance' permission :new_acd_configure_job, - { :'foreman_acd/remote_execution' => [:new] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/remote_execution' => [:new] }, + :resource_type => 'ForemanAcd::AppInstance' permission :create_acd_configure_job, - { :'foreman_acd/remote_execution' => [:create] }, - :resource_type => 'ForemanAcd::AppInstance' + { :'foreman_acd/remote_execution' => [:create] }, + :resource_type => 'ForemanAcd::AppInstance' permission :view_ui_acd, - { :ui_acd => [:app, :foreman_data, :ansible_data, :validate_hostname, :report_data] } + { :ui_acd => [:app, :foreman_data, :ansible_data, :validate_hostname, :report_data] } permission :acd_foreman_hosts, - { :'foreman_acd/app_instances' => [:create, :edit, :update, :deploy, :destroy_with_hosts, :destroy] }, - :resource_type => 'ForemanAcd::ForemanHost' + { :'foreman_acd/app_instances' => [:create, :edit, :update, :deploy, :destroy_with_hosts, :destroy] }, + :resource_type => 'ForemanAcd::ForemanHost' end # Manager Role diff --git a/lib/tasks/foreman_acd_tasks.rake b/lib/tasks/foreman_acd_tasks.rake index 86d690a8..43e21e52 100644 --- a/lib/tasks/foreman_acd_tasks.rake +++ b/lib/tasks/foreman_acd_tasks.rake @@ -13,20 +13,13 @@ namespace :test do end namespace :foreman_acd do - task :rubocop do - begin - require 'rubocop/rake_task' - RuboCop::RakeTask.new(:rubocop_foreman_acd) do |task| - task.patterns = ["#{ForemanAcd::Engine.root}/app/**/*.rb", - "#{ForemanAcd::Engine.root}/lib/**/*.rb", - "#{ForemanAcd::Engine.root}/test/**/*.rb"] - end - rescue StandardError - puts 'Rubocop not loaded.' - end - - Rake::Task['rubocop_foreman_acd'].invoke + require 'rubocop/rake_task' + RuboCop::RakeTask.new(:rubocop) do |task| + task.options = ['--force-exclusion'] + task.patterns = [ForemanAcd::Engine.root.to_s] end +rescue LoadError + puts 'Rubocop not loaded.' end Rake::Task[:test].enhance ['test:foreman_acd'] diff --git a/test/controllers/ansible_playbooks_controller_test.rb b/test/controllers/ansible_playbooks_controller_test.rb index d11c0786..d830fbbf 100644 --- a/test/controllers/ansible_playbooks_controller_test.rb +++ b/test/controllers/ansible_playbooks_controller_test.rb @@ -18,8 +18,8 @@ class AnsiblePlaybooksControllerTest < ActionController::TestCase test 'should destroy ansible playbook' do assert_difference('AnsiblePlaybook.count', -1) do delete :destroy, - :params => { :id => @model.id }, - :session => set_session_user + :params => { :id => @model.id }, + :session => set_session_user end assert_redirected_to ansible_playbooks_url end diff --git a/test/controllers/app_definitions_controller_test.rb b/test/controllers/app_definitions_controller_test.rb index c57fb20d..90ab606a 100644 --- a/test/controllers/app_definitions_controller_test.rb +++ b/test/controllers/app_definitions_controller_test.rb @@ -18,8 +18,8 @@ class AppDefinitionsControllerTest < ActionController::TestCase test 'should destroy app definition' do assert_difference('AppDefinition.count', -1) do delete :destroy, - :params => { :id => @model.id }, - :session => set_session_user + :params => { :id => @model.id }, + :session => set_session_user end assert_redirected_to app_definitions_url end diff --git a/test/controllers/app_instances_controller_test.rb b/test/controllers/app_instances_controller_test.rb index 4304223c..16329232 100644 --- a/test/controllers/app_instances_controller_test.rb +++ b/test/controllers/app_instances_controller_test.rb @@ -24,8 +24,8 @@ def set_session_user test 'should destroy app instance' do assert_difference('AppInstance.count', -1) do delete :destroy_with_hosts, - :params => { :id => @model.id }, - :session => set_session_user + :params => { :id => @model.id }, + :session => set_session_user end end end diff --git a/test/models/acd_provider_test.rb b/test/models/acd_provider_test.rb index ef72c1c0..3a3d04b8 100644 --- a/test/models/acd_provider_test.rb +++ b/test/models/acd_provider_test.rb @@ -10,13 +10,13 @@ class AcdProviderTest < ActiveSupport::TestCase it 'returns only strings' do provider_names.each do |name| - _(name).must_be_kind_of String + expect(name).must_be_kind_of String end end context 'provider is registetered under :custom symbol' do before { AcdProvider.register(:ACD, String) } - it { _(provider_names).must_include 'ACD' } + it { expect(provider_names).must_include 'ACD' } end end diff --git a/test/models/concerns/host_extensions_test.rb b/test/models/concerns/host_extensions_test.rb index 1a93ca2f..e3dc2887 100644 --- a/test/models/concerns/host_extensions_test.rb +++ b/test/models/concerns/host_extensions_test.rb @@ -14,10 +14,10 @@ class HostExtensionsTest < ActiveSupport::TestCase app = FactoryBot.create :app_instance foreman_host = app.foreman_hosts.create(:hostname => host.name, - :service => 'DB', - :description => 'Description', - :foremanParameters => nil, - :ansibleParameters => nil) + :service => 'DB', + :description => 'Description', + :foremanParameters => nil, + :ansibleParameters => nil) foreman_host.host = host foreman_host.save assert host.deployed_via_acd?