Skip to content

Commit 7306b80

Browse files
committed
Support Foreman 3.9 and newer
- migrate to settings DSL - drop old Foreman version support - switch to upstream CI - switch to upstream rubocop
1 parent 55dc0de commit 7306b80

File tree

24 files changed

+149
-180
lines changed

24 files changed

+149
-180
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,34 @@
1-
name: CI
2-
on: [push, pull_request]
3-
env:
4-
RAILS_ENV: test
5-
DATABASE_URL: postgresql://postgres:@localhost/test
6-
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
1+
name: Ruby test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
concurrency:
10+
group: ${{ github.ref_name }}-${{ github.workflow }}
11+
cancel-in-progress: true
12+
713
jobs:
814
rubocop:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v2
12-
- name: Setup Ruby
13-
uses: ruby/setup-ruby@v1
14-
with:
15-
ruby-version: 2.4
16-
- name: Setup
17-
run: |
18-
gem install bundler
19-
bundle install --jobs=3 --retry=3
20-
- name: Run rubocop
21-
run: bundle exec rubocop
15+
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
16+
with:
17+
command: bundle exec rubocop --parallel --format github
18+
2219
test:
23-
runs-on: ubuntu-latest
20+
name: Ruby
2421
needs: rubocop
25-
services:
26-
postgres:
27-
image: postgres:12.1
28-
ports: ['5432:5432']
29-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
3022
strategy:
3123
fail-fast: false
3224
matrix:
33-
foreman-core-branch: [1.21-stable, 1.22-stable, 1.23-stable, 1.24-stable, 2.0-stable, 2.1-stable, 2.2-stable, develop]
34-
ruby-version: [2.4, 2.5, 2.6]
35-
node-version: [10]
36-
exclude:
37-
- foreman-core-branch: 2.0-stable
38-
ruby-version: 2.4
39-
- foreman-core-branch: 2.1-stable
40-
ruby-version: 2.4
41-
- foreman-core-branch: 2.2-stable
42-
ruby-version: 2.4
43-
- foreman-core-branch: develop
44-
ruby-version: 2.4
45-
steps:
46-
- name: Install dependencies
47-
run: |
48-
sudo apt-get update
49-
sudo apt-get install build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev
50-
- uses: actions/checkout@v2
51-
with:
52-
repository: theforeman/foreman
53-
ref: ${{ matrix.foreman-core-branch }}
54-
- uses: actions/checkout@v2
55-
with:
56-
path: foreman_rescue
57-
- name: Setup Ruby
58-
uses: ruby/setup-ruby@v1
59-
with:
60-
ruby-version: ${{ matrix.ruby-version }}
61-
- name: Setup Node
62-
uses: actions/setup-node@v1
63-
with:
64-
node-version: ${{ matrix.node-version }}
65-
- name: Setup Bundler
66-
run: |
67-
echo "gem 'foreman_rescue', path: './foreman_rescue'" > bundler.d/foreman_rescue.local.rb
68-
gem install bundler
69-
bundle config path vendor/bundle
70-
bundle config set without journald development console mysql2 sqlite
71-
bundle lock --update
72-
- name: Cache gems
73-
uses: actions/cache@v2
74-
with:
75-
path: vendor/bundle
76-
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
77-
restore-keys: |
78-
${{ runner.os }}-gems-
79-
- name: Setup Plugin
80-
run: |
81-
bundle install --jobs=3 --retry=3
82-
bundle exec rake db:create
83-
bundle exec rake db:migrate
84-
npm install
85-
bundle exec rake webpack:compile
86-
- name: Run plugin tests
87-
run: |
88-
bundle exec rake test:foreman_rescue
89-
bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb"
90-
- name: Precompile plugin assets
91-
run: bundle exec rake 'plugin:assets:precompile[foreman_rescue]'
92-
env:
93-
RAILS_ENV: production
25+
foreman:
26+
- "develop"
27+
- "3.10-stable"
28+
- "3.9-stable"
29+
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
30+
with:
31+
plugin: foreman_rescue
32+
foreman_version: ${{ matrix.foreman }}
33+
environment_variables: |
34+
FOREMAN_VERSION=${{ matrix.foreman }}

.rubocop.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
AllCops:
2-
TargetRubyVersion: 2.2
3-
TargetRailsVersion: 5.1
4-
Exclude:
5-
- '*.spec'
6-
- 'Rakefile'
1+
inherit_gem:
2+
theforeman-rubocop:
3+
- default.yml
74

8-
Rails:
9-
Enabled: true
5+
AllCops:
6+
TargetRubyVersion: '2.7'
7+
Exclude:
8+
- 'vendor/bundle/**/*'
109

11-
Rails/ActionFilter:
12-
EnforcedStyle: action
10+
Style/FrozenStringLiteralComment:
11+
Exclude:
12+
- Rakefile
1313

1414
# Don't enforce documentation
1515
Style/Documentation:
@@ -22,10 +22,6 @@ Metrics/ClassLength:
2222
Exclude:
2323
- 'test/**/*'
2424

25-
Performance/FixedSize:
26-
Exclude:
27-
- 'test/**/*'
28-
2925
Metrics/BlockLength:
3026
Exclude:
3127
- 'test/**/*'
@@ -47,7 +43,7 @@ Style/HashSyntax:
4743
- ruby19
4844
- hash_rockets
4945

50-
Metrics/LineLength:
46+
Layout/LineLength:
5147
Max: 190
5248

5349
Style/SymbolArray:

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
2020
rdoc.rdoc_files.include('lib/**/*.rb')
2121
end
2222

23-
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
23+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
2424

2525
Bundler::GemHelper.install_tasks
2626

@@ -38,7 +38,7 @@ task default: :test
3838
begin
3939
require 'rubocop/rake_task'
4040
RuboCop::RakeTask.new
41-
rescue => _
41+
rescue StandardError => _e
4242
puts 'Rubocop not loaded.'
4343
end
4444

app/controllers/foreman_rescue/hosts_controller.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# frozen_string_literal: true
2+
13
module ForemanRescue
24
class HostsController < ::HostsController
35
before_action :find_resource, :only => [:rescue, :set_rescue, :cancel_rescue]
46
define_action_permission ['rescue', 'set_rescue', 'cancel_rescue'], :rescue
57

6-
def rescue; end
8+
def rescue
9+
end
710

811
def set_rescue
912
forward_url_options
@@ -16,10 +19,10 @@ def set_rescue
1619
_('Enabled %s for boot into rescue system on next boot, but failed to power cycle the host.')
1720
end
1821
process_success :success_msg => message % @host, :success_redirect => :back
19-
rescue StandardError => error
22+
rescue StandardError => e
2023
message = _('Failed to reboot %s.') % @host
2124
warning(message)
22-
Foreman::Logging.exception(message, error)
25+
Foreman::Logging.exception(message, e)
2326
process_success :success_msg => _('Enabled %s for rescue system on next boot.') % @host, :success_redirect => :back
2427
end
2528
else
@@ -35,8 +38,10 @@ def cancel_rescue
3538
process_success :success_msg => _('Canceled booting into rescue system for %s.') % @host.name, :success_redirect => :back
3639
else
3740
process_error :redirect => :back,
38-
:error_msg => _('Failed to cancel booting into rescue system for %{hostname} with the following errors: %{errors}') %
39-
{ :hostname => @host.name, :errors => @host.errors.full_messages.to_sentence }
41+
:error_msg => _('Failed to cancel booting into rescue system for %{hostname} with the following errors: %{errors}') % {
42+
:hostname => @host.name,
43+
:errors => @host.errors.full_messages.to_sentence,
44+
}
4045
end
4146
end
4247
end

app/helpers/concerns/foreman_rescue/hosts_helper_extensions.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
# frozen_string_literal: true
2+
13
module ForemanRescue
24
module HostsHelperExtensions
35
def host_title_actions(host)
46
title_actions(
57
button_group(
68
if host.rescue_mode?
79
link_to_if_authorized(_('Cancel rescue'), hash_for_cancel_rescue_host_path(:id => host).merge(:auth_object => host, :permission => 'rescue_hosts'),
8-
:disabled => host.can_be_rescued?,
9-
:title => _('Cancel rescue system for this host.'),
10-
:class => 'btn btn-default',
11-
:method => :put)
10+
:disabled => host.can_be_rescued?,
11+
:title => _('Cancel rescue system for this host.'),
12+
:class => 'btn btn-default',
13+
:method => :put)
1214
else
1315
link_to_if_authorized(_('Rescue'), hash_for_rescue_host_path(:id => host).merge(:auth_object => host, :permission => 'rescue_hosts'),
14-
:disabled => !host.can_be_rescued?,
15-
:title => _('Activate rescue mode for this host.'),
16-
:class => 'btn btn-default')
16+
:disabled => !host.can_be_rescued?,
17+
:title => _('Activate rescue mode for this host.'),
18+
:class => 'btn btn-default')
1719
end
1820
)
1921
)

app/models/concerns/foreman_rescue/host_extensions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ForemanRescue
24
module HostExtensions
35
def self.prepended(base)

app/models/concerns/foreman_rescue/orchestration/tftp.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ForemanRescue
24
module Orchestration
35
module TFTP

app/models/setting/rescue.rb

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,13 @@
1+
# frozen_string_literal: true
2+
13
class Setting
24
class Rescue < ::Setting
3-
BLANK_ATTRS.concat ['rescue_pxegrub_tftp_template', 'rescue_pxegrub2_tftp_template']
4-
5-
def self.default_settings
6-
[
7-
set('rescue_pxelinux_tftp_template',
8-
N_('PXELinux template used when booting rescue system'),
9-
'Kickstart rescue PXELinux', N_('PXELinux rescue template'), nil,
10-
:collection => proc { Setting::Rescue.templates('PXELinux') }),
11-
set('rescue_pxegrub_tftp_template',
12-
N_('PXEGrub template used when booting rescue system'),
13-
'', N_('PXEGrub rescue template'), nil,
14-
:collection => proc { Setting::Rescue.templates('PXEGrub') }),
15-
set('rescue_pxegrub2_tftp_template',
16-
N_('PXEGrub2 template used when booting rescue system'),
17-
'', N_('PXEGrub2 rescue template'), nil,
18-
:collection => proc { Setting::Rescue.templates('PXEGrub2') })
19-
]
20-
end
21-
22-
def self.load_defaults
23-
# Check the table exists
24-
return unless super
25-
26-
transaction do
27-
default_settings.each { |s| create! s.update(:category => 'Setting::Rescue') }
28-
end
29-
30-
true
31-
end
32-
335
def self.templates(kind)
346
template_kind = TemplateKind.find_by(name: kind)
357
templates = ProvisioningTemplate.where(:template_kind => template_kind)
368
templates.each_with_object({}) do |template, hsh|
379
hsh[template.name] = template.name
3810
end
3911
end
40-
41-
def self.humanized_category
42-
N_('Rescue System')
43-
end
4412
end
4513
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
Rails.application.routes.draw do
24
constraints(:id => /[^\/]+/) do
35
resources :hosts, controller: 'foreman_rescue/hosts', :only => [] do

db/migrate/20170901131321_add_rescue_mode_to_host.foreman_rescue.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class AddRescueModeToHost < ActiveRecord::Migration[4.2]
24
def change
35
add_column :hosts, :rescue_mode, :boolean, default: false, index: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class MigrateRescueSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4+
class MigrationSettings < ApplicationRecord
5+
self.table_name = :settings
6+
end
7+
8+
def up
9+
MigrationSettings.where(category: 'Setting::Rescue').update_all(category: 'Setting') if column_exists?(
10+
:settings, :category
11+
)
12+
end
13+
end

db/seeds.d/103-provisioning_templates.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
User.as_anonymous_admin do
24
templates = [
3-
{ :name => 'Kickstart rescue PXELinux', :source => 'PXELinux/kickstart_rescue_pxelinux.erb', :template_kind => TemplateKind.find_by(:name => 'PXELinux') }
5+
{ :name => 'Kickstart rescue PXELinux', :source => 'PXELinux/kickstart_rescue_pxelinux.erb', :template_kind => TemplateKind.find_by(:name => 'PXELinux') },
46
]
57

68
templates.each do |template|

foreman_rescue.gemspec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
require File.expand_path('../lib/foreman_rescue/version', __FILE__)
1+
# frozen_string_literal: true
2+
3+
require File.expand_path('lib/foreman_rescue/version', __dir__)
24

35
Gem::Specification.new do |s|
46
s.name = 'foreman_rescue'
@@ -11,9 +13,11 @@ Gem::Specification.new do |s|
1113
# also update locale/gemspec.rb
1214
s.description = 'Foreman Plugin to provide the ability to boot a host into a rescue system.'
1315

16+
s.required_ruby_version = '>= 2.7', '< 4'
17+
1418
s.files = Dir['{app,config,db,lib,locale}/**/*'] + ['LICENSE', 'Rakefile', 'README.md']
1519
s.test_files = Dir['test/**/*']
1620

1721
s.add_development_dependency 'rdoc'
18-
s.add_development_dependency 'rubocop', '0.52.0'
22+
s.add_development_dependency 'theforeman-rubocop', '~> 0.1.2'
1923
end

lib/foreman_rescue.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'foreman_rescue/engine'
24

35
module ForemanRescue

0 commit comments

Comments
 (0)