foreman_rescue 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55de93b62e157091d65fcab30cb1874ec5ac90a2f26ee581330942907c2a8b2f
4
- data.tar.gz: 13649843d4c4a7fe195c109851e839c627f205c8a12294a1837299f5daed79da
3
+ metadata.gz: 30d69cfe2978f5b7b6a4f3604151d8d83ab5fcee0a5245ce845798ada48ea10c
4
+ data.tar.gz: 37cbc08534f2b5cada7d57f8988a5f36a60ae38b244e1ee7c6c076487e51d9fc
5
5
  SHA512:
6
- metadata.gz: 535f2a6efd573bb1127a731eee765cfc233b9e37b41bbc8a63a9cb8cb99aaaef92e0ddc547b006aae92a9fd1a9892dad9924dfb459759033d27cb1d832f26bb4
7
- data.tar.gz: 8de3049f0f3634be135618fb79f109f1bf047c8e752f5519757d4ba682aa5280a91257d000afef65cee9cb702574d303ae0914fefb99f6e59f3fe959c833044a
6
+ metadata.gz: cf8c408b71e8d5369c027d11909369152f1ece087658579b3874b55d6e3306448597f17cadab4cba0ee47ae15da5acf8f854dcece077acdd1dcdabf84101bcdc
7
+ data.tar.gz: fc5b71b96991fd3f42b66bdb8dc2fac9b3173214420273c4d76f5b3bd3b6bbdb7f570a11540cbdca268305983799432656b3ada028fd04d838edbf7cc060124f
data/README.md CHANGED
@@ -12,6 +12,7 @@ This plugin allows a user to boot a Foreman host into a rescue system via PXE.
12
12
  | >= 1.17 | ~> 1.0 |
13
13
  | >= 1.20 | ~> 2.0 |
14
14
  | >= 1.21 | ~> 3.0 |
15
+ | >= 3.9 | ~> 4.0 |
15
16
 
16
17
  ## Installation
17
18
 
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
23
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
24
24
 
25
25
  Bundler::GemHelper.install_tasks
26
26
 
@@ -38,7 +38,7 @@ task default: :test
38
38
  begin
39
39
  require 'rubocop/rake_task'
40
40
  RuboCop::RakeTask.new
41
- rescue => _
41
+ rescue StandardError
42
42
  puts 'Rubocop not loaded.'
43
43
  end
44
44
 
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
4
  class HostsController < ::HostsController
3
5
  before_action :find_resource, :only => [:rescue, :set_rescue, :cancel_rescue]
4
6
  define_action_permission ['rescue', 'set_rescue', 'cancel_rescue'], :rescue
5
7
 
6
- def rescue; end
8
+ def rescue
9
+ end
7
10
 
8
11
  def set_rescue
9
12
  forward_url_options
@@ -16,10 +19,10 @@ module ForemanRescue
16
19
  _('Enabled %s for boot into rescue system on next boot, but failed to power cycle the host.')
17
20
  end
18
21
  process_success :success_msg => message % @host, :success_redirect => :back
19
- rescue StandardError => error
22
+ rescue StandardError => e
20
23
  message = _('Failed to reboot %s.') % @host
21
24
  warning(message)
22
- Foreman::Logging.exception(message, error)
25
+ Foreman::Logging.exception(message, e)
23
26
  process_success :success_msg => _('Enabled %s for rescue system on next boot.') % @host, :success_redirect => :back
24
27
  end
25
28
  else
@@ -35,8 +38,10 @@ module ForemanRescue
35
38
  process_success :success_msg => _('Canceled booting into rescue system for %s.') % @host.name, :success_redirect => :back
36
39
  else
37
40
  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
+ }
40
45
  end
41
46
  end
42
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
4
  module HostsHelperExtensions
3
5
  def host_title_actions(host)
@@ -5,15 +7,15 @@ module ForemanRescue
5
7
  button_group(
6
8
  if host.rescue_mode?
7
9
  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)
12
14
  else
13
15
  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')
17
19
  end
18
20
  )
19
21
  )
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
4
  module HostExtensions
3
5
  def self.prepended(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
4
  module Orchestration
3
5
  module TFTP
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanRescue
4
+ module ProvisioningTemplateExtensions
5
+ def self.templates_by_kind(kind)
6
+ template_kind = TemplateKind.find_by(name: kind)
7
+ ProvisioningTemplate.where(:template_kind => template_kind).pluck(:name, :name).to_h
8
+ end
9
+ end
10
+ end
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rails.application.routes.draw do
2
4
  constraints(:id => /[^\/]+/) do
3
5
  resources :hosts, controller: 'foreman_rescue/hosts', :only => [] do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddRescueModeToHost < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :hosts, :rescue_mode, :boolean, default: false, index: true
@@ -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
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  User.as_anonymous_admin do
2
4
  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') },
4
6
  ]
5
7
 
6
8
  templates.each do |template|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
4
  class Engine < ::Rails::Engine
3
5
  engine_name 'foreman_rescue'
@@ -12,20 +14,34 @@ module ForemanRescue
12
14
  end
13
15
  end
14
16
 
15
- initializer 'foreman_monitoring.load_default_settings',
16
- :before => :load_config_initializers do |_app|
17
- if begin
18
- Setting.table_exists?
19
- rescue StandardError
20
- false
21
- end
22
- require_dependency File.expand_path('../../../app/models/setting/rescue.rb', __FILE__)
23
- end
24
- end
17
+ initializer 'foreman_rescue.register_plugin', :before => :finisher_hook do |_app| # rubocop:disable Metrics/BlockLength
18
+ Foreman::Plugin.register :foreman_rescue do # rubocop:disable Metrics/BlockLength
19
+ requires_foreman '>= 3.9'
25
20
 
26
- initializer 'foreman_rescue.register_plugin', :before => :finisher_hook do |_app|
27
- Foreman::Plugin.register :foreman_rescue do
28
- requires_foreman '>= 1.21'
21
+ settings do
22
+ category :rescue, N_('Rescue') do
23
+ setting('rescue_pxelinux_tftp_template',
24
+ type: :string,
25
+ default: 'Kickstart rescue PXELinux',
26
+ full_name: N_('PXELinux rescue template'),
27
+ description: N_('PXELinux template used when booting rescue system'),
28
+ collection: proc { ProvisioningTemplate.templates_by_kind('PXELinux') })
29
+
30
+ setting('rescue_pxegrub_tftp_template',
31
+ type: :string,
32
+ default: '',
33
+ full_name: N_('PXEGrub rescue template'),
34
+ description: N_('PXEGrub template used when booting rescue system'),
35
+ collection: proc { ProvisioningTemplate.templates_by_kind('PXEGrub') })
36
+
37
+ setting('rescue_pxegrub2_tftp_template',
38
+ type: :string,
39
+ default: '',
40
+ full_name: N_('PXEGrub2 rescue template'),
41
+ description: N_('PXEGrub2 template used when booting rescue system'),
42
+ collection: proc { ProvisioningTemplate.templates_by_kind('PXEGrub2') })
43
+ end
44
+ end
29
45
 
30
46
  # Add permissions
31
47
  security_block :foreman_rescue do
@@ -35,13 +51,12 @@ module ForemanRescue
35
51
  end
36
52
 
37
53
  config.to_prepare do
38
- begin
39
- Host::Managed.send(:prepend, ForemanRescue::HostExtensions)
40
- HostsHelper.send(:prepend, ForemanRescue::HostsHelperExtensions)
41
- Nic::Managed.send(:prepend, ForemanRescue::Orchestration::TFTP)
42
- rescue StandardError => e
43
- Rails.logger.warn "ForemanRescue: skipping engine hook (#{e})"
44
- end
54
+ Host::Managed.prepend ForemanRescue::HostExtensions
55
+ HostsHelper.prepend ForemanRescue::HostsHelperExtensions
56
+ Nic::Managed.prepend ForemanRescue::Orchestration::TFTP
57
+ ProvisioningTemplate.prepend ForemanRescue::ProvisioningTemplateExtensions
58
+ rescue StandardError => e
59
+ Rails.logger.warn "ForemanRescue: skipping engine hook (#{e})"
45
60
  end
46
61
 
47
62
  rake_tasks do
@@ -51,7 +66,7 @@ module ForemanRescue
51
66
  end
52
67
 
53
68
  initializer 'foreman_rescue.register_gettext', after: :load_config_initializers do |_app|
54
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
69
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
55
70
  locale_domain = 'foreman_rescue'
56
71
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
57
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanRescue
2
- VERSION = '3.0.0'.freeze
4
+ VERSION = '4.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_rescue/engine'
2
4
 
3
5
  module ForemanRescue
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/testtask'
2
4
 
3
5
  # Tests
@@ -12,24 +14,4 @@ namespace :test do
12
14
  end
13
15
  end
14
16
 
15
- namespace :foreman_rescue do
16
- task :rubocop do
17
- begin
18
- require 'rubocop/rake_task'
19
- RuboCop::RakeTask.new(:rubocop_foreman_rescue) do |task|
20
- task.patterns = ["#{ForemanRescue::Engine.root}/app/**/*.rb",
21
- "#{ForemanRescue::Engine.root}/lib/**/*.rb",
22
- "#{ForemanRescue::Engine.root}/test/**/*.rb"]
23
- end
24
- rescue StandardError
25
- puts 'Rubocop not loaded.'
26
- end
27
-
28
- Rake::Task['rubocop_foreman_rescue'].invoke
29
- end
30
- end
31
-
32
17
  Rake::Task[:test].enhance ['test:foreman_rescue']
33
-
34
- load 'tasks/jenkins.rake'
35
- Rake::Task['jenkins:unit'].enhance ['test:foreman_rescue', 'foreman_rescue:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
data/locale/gemspec.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Matches foreman_rescue.gemspec
2
- _('TODO: Description of ForemanRescue.')
4
+ _('Foreman Plugin to provide the ability to boot a host into a rescue system.')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanRescue
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :host do
3
5
  trait :rescue_mode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanRescue
@@ -27,7 +29,7 @@ module ForemanRescue
27
29
  def seed
28
30
  User.current = FactoryBot.build(:user, :admin => true,
29
31
  :organizations => [], :locations => [])
30
- load Rails.root.join('db', 'seeds.rb')
32
+ load Rails.root.join('db/seeds.rb')
31
33
  end
32
34
  end
33
35
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostTest < ActiveSupport::TestCase
4
6
  setup do
5
7
  User.current = FactoryBot.build(:user, :admin)
6
- setup_settings
7
8
  disable_orchestration
8
9
  end
9
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
  require 'database_cleaner'
@@ -9,10 +11,6 @@ FactoryBot.reload
9
11
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
10
12
  DatabaseCleaner.strategy = :transaction
11
13
 
12
- def setup_settings
13
- Setting::Rescue.load_defaults
14
- end
15
-
16
14
  module Minitest
17
15
  class Spec
18
16
  before :each do
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+ require 'unit/shared/access_permissions_test_base'
5
+
6
+ # Permissions are added in AccessPermissions with lists of controllers and
7
+ # actions that they enable access to. For non-admin users, we need to test
8
+ # that there are permissions available that cover every controller action, else
9
+ # it can't be delegated and this will lead to parts of the application that
10
+ # aren't functional for non-admin users.
11
+ #
12
+ # In particular, it's important that actions for AJAX requests are added to
13
+ # an appropriate permission so views using those requests function.
14
+ class AccessPermissionsTest < ActiveSupport::TestCase
15
+ include AccessPermissionsTestBase
16
+
17
+ check_routes(ForemanRescue::Engine.routes, [])
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rescue
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-03 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rubocop
28
+ name: theforeman-rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.52.0
33
+ version: 0.1.2
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.52.0
40
+ version: 0.1.2
41
41
  description: Foreman Plugin to provide the ability to boot a host into a rescue system.
42
42
  email:
43
43
  - timo.goebel@dm.de
@@ -52,11 +52,12 @@ files:
52
52
  - app/helpers/concerns/foreman_rescue/hosts_helper_extensions.rb
53
53
  - app/models/concerns/foreman_rescue/host_extensions.rb
54
54
  - app/models/concerns/foreman_rescue/orchestration/tftp.rb
55
- - app/models/setting/rescue.rb
55
+ - app/models/concerns/foreman_rescue/provisioning_template_extensions.rb
56
56
  - app/views/foreman/unattended/provisioning_templates/PXELinux/kickstart_rescue_pxelinux.erb
57
57
  - app/views/foreman_rescue/hosts/rescue.html.erb
58
58
  - config/routes.rb
59
59
  - db/migrate/20170901131321_add_rescue_mode_to_host.foreman_rescue.rb
60
+ - db/migrate/20240506132712_migrate_rescue_settings_category_to_dsl.rb
60
61
  - db/seeds.d/103-provisioning_templates.rb
61
62
  - lib/foreman_rescue.rb
62
63
  - lib/foreman_rescue/engine.rb
@@ -71,11 +72,12 @@ files:
71
72
  - test/lib/tasks/seeds_test.rb
72
73
  - test/models/host_test.rb
73
74
  - test/test_plugin_helper.rb
75
+ - test/unit/foreman_rescue/access_permissions_test.rb
74
76
  homepage: https://github.com/dm-drogeriemarkt/foreman_rescue
75
77
  licenses:
76
78
  - GPL-3.0
77
79
  metadata: {}
78
- post_install_message:
80
+ post_install_message:
79
81
  rdoc_options: []
80
82
  require_paths:
81
83
  - lib
@@ -83,21 +85,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
85
  requirements:
84
86
  - - ">="
85
87
  - !ruby/object:Gem::Version
86
- version: '0'
88
+ version: '2.7'
89
+ - - "<"
90
+ - !ruby/object:Gem::Version
91
+ version: '4'
87
92
  required_rubygems_version: !ruby/object:Gem::Requirement
88
93
  requirements:
89
94
  - - ">="
90
95
  - !ruby/object:Gem::Version
91
96
  version: '0'
92
97
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.7.6.2
95
- signing_key:
98
+ rubygems_version: 3.4.1
99
+ signing_key:
96
100
  specification_version: 4
97
101
  summary: Provides the ability to boot a host into a rescue system.
98
102
  test_files:
99
- - test/models/host_test.rb
103
+ - test/controllers/hosts_controller_test.rb
100
104
  - test/factories/host.rb
101
105
  - test/lib/tasks/seeds_test.rb
106
+ - test/models/host_test.rb
102
107
  - test/test_plugin_helper.rb
103
- - test/controllers/hosts_controller_test.rb
108
+ - test/unit/foreman_rescue/access_permissions_test.rb
@@ -1,45 +0,0 @@
1
- class Setting
2
- 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
-
33
- def self.templates(kind)
34
- template_kind = TemplateKind.find_by(name: kind)
35
- templates = ProvisioningTemplate.where(:template_kind => template_kind)
36
- templates.each_with_object({}) do |template, hsh|
37
- hsh[template.name] = template.name
38
- end
39
- end
40
-
41
- def self.humanized_category
42
- N_('Rescue System')
43
- end
44
- end
45
- end