foreman_rescue 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4b36eae38108425515c2cd0edec9e271e47e64d63218e1fec50e3a8647874f0
4
- data.tar.gz: 3ca946dec5e74624ae8305ded907c5b5e902eb35cb97e97a44bbb327eb9daf3c
3
+ metadata.gz: fed912b0085c3e6ab01cca79cc2e8df1986b71b8be95449caefa27a461d0ae50
4
+ data.tar.gz: 4f9c97ca7d406a58492bc8ac00f4b813dd009faddd857940abdda9275cce0942
5
5
  SHA512:
6
- metadata.gz: 8122c629af1c8cf6a2a3f413b452ac1250eba7ed67cc0e76c026698efc41a3a8cce2cd98c30b3a769063662346b23f77bc5c1431ac4e0c92aa2f0d6e26f9a968
7
- data.tar.gz: fb6aa2ed0a71b8d369d410c34d5f0d20c029c269b0cb9a97356e011b4a629be74dc389b5366c18625ef46cc591f12ad295cb05d8969849df83c898317d9772c3
6
+ metadata.gz: 589d947221c47ccca4d6d5ff1e7ad2f9beba1472a597c91017512ea3b82f97b7ba59e15e45eb6cf4aea3c884ff0df01510cd822ec1ed7fde423e5c6861b34ce6
7
+ data.tar.gz: 74308ab3113c2586326fac9e818c2f5a8871e1d0ad1354a21e8ecb88e2aa4c012360ce4c8b1645dac4ec86d9a59d771763c741b1eaecaee39f2f396663a43d78
data/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This plugin allows a user to boot a Foreman host into a rescue system via PXE.
4
4
 
5
+ ## Compatibility
6
+
7
+ | Foreman Version | Plugin Version |
8
+ | --------------- | -------------- |
9
+ | >= 1.15 | ~> 0.1 |
10
+ | >= 1.17 | ~> 1.0 |
11
+
5
12
  ## Installation
6
13
 
7
14
  See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
@@ -16,7 +16,7 @@ module ForemanRescue
16
16
  _('Enabled %s for boot into rescue system on next boot, but failed to power cycle the host.')
17
17
  end
18
18
  process_success :success_msg => message % @host, :success_redirect => :back
19
- rescue => error
19
+ rescue StandardError => error
20
20
  message = _('Failed to reboot %s.') % @host
21
21
  warning(message)
22
22
  Foreman::Logging.exception(message, error)
@@ -35,10 +35,10 @@ module ForemanRescue
35
35
 
36
36
  def rescue_mode_pxe_render(kind)
37
37
  template_name = Setting["rescue_#{kind.downcase}_tftp_template"]
38
- template = ::ProvisioningTemplate.find_by_name(template_name)
39
- return unless template.present?
38
+ template = ::ProvisioningTemplate.find_by(name: template_name)
39
+ return if template.blank?
40
40
  unattended_render template
41
- rescue => e
41
+ rescue StandardError => e
42
42
  failure _("Unable to render %{kind} rescue template '%{name}' for TFTP: %{e}") % { :kind => kind, :name => template.try(:name), :e => e }, e
43
43
  end
44
44
 
@@ -5,15 +5,15 @@ class Setting
5
5
  set('rescue_pxelinux_tftp_template',
6
6
  N_('PXELinux template used when booting rescue system'),
7
7
  'create', N_('PXELinux rescue template'), nil,
8
- { :collection => proc { Setting::Rescue.templates('PXELinux') } }),
8
+ :collection => proc { Setting::Rescue.templates('PXELinux') }),
9
9
  set('rescue_pxegrub_tftp_template',
10
10
  N_('PXEGrub template used when booting rescue system'),
11
11
  'create', N_('PXEGrub rescue template'), nil,
12
- { :collection => proc { Setting::Rescue.templates('PXEGrub') } }),
12
+ :collection => proc { Setting::Rescue.templates('PXEGrub') }),
13
13
  set('rescue_pxegrub2_tftp_template',
14
14
  N_('PXEGrub2 template used when booting rescue system'),
15
15
  'create', N_('PXEGrub2 rescue template'), nil,
16
- { :collection => proc { Setting::Rescue.templates('PXEGrub 2') } })
16
+ :collection => proc { Setting::Rescue.templates('PXEGrub 2') })
17
17
  ]
18
18
  end
19
19
 
@@ -21,15 +21,15 @@ class Setting
21
21
  # Check the table exists
22
22
  return unless super
23
23
 
24
- self.transaction do
25
- default_settings.each { |s| self.create! s.update(:category => 'Setting::Rescue') }
24
+ transaction do
25
+ default_settings.each { |s| create! s.update(:category => 'Setting::Rescue') }
26
26
  end
27
27
 
28
28
  true
29
29
  end
30
30
 
31
31
  def self.templates(kind)
32
- template_kind = TemplateKind.find_by_name(kind)
32
+ template_kind = TemplateKind.find_by(name: kind)
33
33
  templates = ProvisioningTemplate.where(:template_kind => template_kind)
34
34
  templates.each_with_object({}) do |template, hsh|
35
35
  hsh[template.name] = template.name
@@ -1,4 +1,4 @@
1
- class AddRescueModeToHost < ActiveRecord::Migration
1
+ class AddRescueModeToHost < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :hosts, :rescue_mode, :boolean, default: false, index: true
4
4
  end
@@ -16,7 +16,7 @@ module ForemanRescue
16
16
  :before => :load_config_initializers do |_app|
17
17
  if begin
18
18
  Setting.table_exists?
19
- rescue
19
+ rescue StandardError
20
20
  false
21
21
  end
22
22
  require_dependency File.expand_path('../../../app/models/setting/rescue.rb', __FILE__)
@@ -25,7 +25,7 @@ module ForemanRescue
25
25
 
26
26
  initializer 'foreman_rescue.register_plugin', :before => :finisher_hook do |_app|
27
27
  Foreman::Plugin.register :foreman_rescue do
28
- requires_foreman '>= 1.15'
28
+ requires_foreman '>= 1.17'
29
29
 
30
30
  # Add permissions
31
31
  security_block :foreman_rescue do
@@ -39,7 +39,7 @@ module ForemanRescue
39
39
  Host::Managed.send(:prepend, ForemanRescue::HostExtensions)
40
40
  HostsHelper.send(:prepend, ForemanRescue::HostsHelperExtensions)
41
41
  Nic::Managed.send(:prepend, ForemanRescue::Orchestration::TFTP)
42
- rescue => e
42
+ rescue StandardError => e
43
43
  Rails.logger.warn "ForemanRescue: skipping engine hook (#{e})"
44
44
  end
45
45
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRescue
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -21,7 +21,7 @@ namespace :foreman_rescue do
21
21
  "#{ForemanRescue::Engine.root}/lib/**/*.rb",
22
22
  "#{ForemanRescue::Engine.root}/test/**/*.rb"]
23
23
  end
24
- rescue
24
+ rescue StandardError
25
25
  puts 'Rubocop not loaded.'
26
26
  end
27
27
 
@@ -32,6 +32,4 @@ end
32
32
  Rake::Task[:test].enhance ['test:foreman_rescue']
33
33
 
34
34
  load 'tasks/jenkins.rake'
35
- if Rake::Task.task_defined?(:'jenkins:unit')
36
- Rake::Task['jenkins:unit'].enhance ['test:foreman_rescue', 'foreman_rescue:rubocop']
37
- end
35
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_rescue', 'foreman_rescue:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
@@ -3,10 +3,10 @@ require 'test_plugin_helper'
3
3
  module ForemanRescue
4
4
  class HostsControllerTest < ::ActionController::TestCase
5
5
  setup do
6
- User.current = FactoryGirl.create(:user, :admin)
6
+ User.current = FactoryBot.create(:user, :admin)
7
7
  end
8
8
 
9
- let(:host) { FactoryGirl.create(:host, :managed) }
9
+ let(:host) { FactoryBot.create(:host, :managed) }
10
10
 
11
11
  describe '#set_rescue' do
12
12
  setup do
@@ -20,7 +20,7 @@ module ForemanRescue
20
20
  context 'when host is not saved' do
21
21
  test 'the flash should inform it' do
22
22
  Host::Managed.any_instance.expects(:set_rescue).returns(false)
23
- put :set_rescue, { :id => host.name }, set_session_user
23
+ put :set_rescue, params: { :id => host.name }, session: set_session_user
24
24
  assert_response :found
25
25
  assert_redirected_to hosts_path
26
26
  assert flash[:error] =~ /Failed to enable #{host} for rescue system/
@@ -33,7 +33,7 @@ module ForemanRescue
33
33
  end
34
34
 
35
35
  test 'the flash should inform it' do
36
- put :set_rescue, { :id => host.name }, set_session_user
36
+ put :set_rescue, params: { :id => host.name }, session: set_session_user
37
37
  assert_response :found
38
38
  assert_redirected_to hosts_path
39
39
  assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
@@ -48,7 +48,7 @@ module ForemanRescue
48
48
 
49
49
  test 'the flash should inform it' do
50
50
  power_mock.stubs(:reset).returns(true)
51
- put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
51
+ put :set_rescue, params: { :id => host.name, :host => { :rescue_mode => '1' } }, session: set_session_user
52
52
  assert_response :found
53
53
  assert_redirected_to hosts_path
54
54
  assert_equal "Enabled #{host} for reboot into rescue system.", flash[:notice]
@@ -56,7 +56,7 @@ module ForemanRescue
56
56
 
57
57
  test 'with failed reboot, the flash should inform it' do
58
58
  power_mock.stubs(:reset).returns(false)
59
- put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
59
+ put :set_rescue, params: { :id => host.name, :host => { :rescue_mode => '1' } }, session: set_session_user
60
60
  host.power.reset
61
61
  assert_response :found
62
62
  assert_redirected_to hosts_path
@@ -65,7 +65,7 @@ module ForemanRescue
65
65
 
66
66
  test 'reboot raised exception, the flash should inform it' do
67
67
  power_mock.stubs(:reset).raises(Foreman::Exception)
68
- put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
68
+ put :set_rescue, params: { :id => host.name, :host => { :rescue_mode => '1' } }, session: set_session_user
69
69
  assert_response :found
70
70
  assert_redirected_to hosts_path
71
71
  assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
@@ -89,7 +89,7 @@ module ForemanRescue
89
89
  end
90
90
 
91
91
  test 'the flash should inform it' do
92
- put :cancel_rescue, { :id => host.name }, set_session_user
92
+ put :cancel_rescue, params: { :id => host.name }, session: set_session_user
93
93
  assert_response :found
94
94
  assert_redirected_to hosts_path
95
95
  assert_equal "Canceled booting into rescue system for #{host}.", flash[:notice]
@@ -102,7 +102,7 @@ module ForemanRescue
102
102
  end
103
103
 
104
104
  test 'the flash should inform it' do
105
- put :cancel_rescue, { :id => host.name }, set_session_user
105
+ put :cancel_rescue, params: { :id => host.name }, session: set_session_user
106
106
  assert_response :found
107
107
  assert_redirected_to hosts_path
108
108
  assert_includes flash[:error], "Failed to cancel booting into rescue system for #{host}"
@@ -112,7 +112,7 @@ module ForemanRescue
112
112
 
113
113
  describe '#rescue' do
114
114
  test 'renders page' do
115
- get :rescue, { :id => host.name }, set_session_user
115
+ get :rescue, params: { :id => host.name }, session: set_session_user
116
116
  assert_response :success
117
117
  assert_template 'foreman_rescue/hosts/rescue'
118
118
  end
@@ -1,4 +1,4 @@
1
- FactoryGirl.modify do
1
+ FactoryBot.modify do
2
2
  factory :host do
3
3
  trait :rescue_mode do
4
4
  rescue_mode true
@@ -2,24 +2,24 @@ require 'test_plugin_helper'
2
2
 
3
3
  class HostTest < ActiveSupport::TestCase
4
4
  setup do
5
- User.current = FactoryGirl.build(:user, :admin)
5
+ User.current = FactoryBot.build(:user, :admin)
6
6
  setup_settings
7
7
  disable_orchestration
8
8
  end
9
9
 
10
10
  context 'a host with tftp orchestration' do
11
- let(:organization) { FactoryGirl.create(:organization) }
12
- let(:tax_location) { FactoryGirl.create(:location) }
11
+ let(:organization) { FactoryBot.create(:organization) }
12
+ let(:tax_location) { FactoryBot.create(:location) }
13
13
  let(:template) do
14
- FactoryGirl.create(
14
+ FactoryBot.create(
15
15
  :provisioning_template,
16
- :template_kind => TemplateKind.find_by_name('PXELinux'),
16
+ :template_kind => TemplateKind.find_by(name: 'PXELinux'),
17
17
  :locations => [tax_location],
18
18
  :organizations => [organization]
19
19
  )
20
20
  end
21
21
  let(:os) do
22
- FactoryGirl.create(
22
+ FactoryBot.create(
23
23
  :operatingsystem,
24
24
  :with_os_defaults,
25
25
  :with_associations,
@@ -28,7 +28,7 @@ class HostTest < ActiveSupport::TestCase
28
28
  )
29
29
  end
30
30
  let(:host) do
31
- FactoryGirl.create(
31
+ FactoryBot.create(
32
32
  :host,
33
33
  :managed,
34
34
  :with_tftp_orchestration,
@@ -64,11 +64,11 @@ class HostTest < ActiveSupport::TestCase
64
64
  end
65
65
 
66
66
  context 'rescue mode tftp remplate rendering' do
67
- let(:host) { FactoryGirl.build(:host, :managed, :rescue_mode) }
67
+ let(:host) { FactoryBot.build(:host, :managed, :rescue_mode) }
68
68
  let(:template) do
69
- FactoryGirl.create(:provisioning_template, :name => 'my template',
70
- :template => 'test content',
71
- :template_kind => template_kinds(:pxelinux))
69
+ FactoryBot.create(:provisioning_template, :name => 'my template',
70
+ :template => 'test content',
71
+ :template_kind => template_kinds(:pxelinux))
72
72
  end
73
73
 
74
74
  test 'renders tftp template' do
@@ -2,9 +2,9 @@
2
2
  require 'test_helper'
3
3
  require 'database_cleaner'
4
4
 
5
- # Add plugin to FactoryGirl's paths
6
- FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
7
- FactoryGirl.reload
5
+ # Add plugin to FactoryBot's paths
6
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
7
+ FactoryBot.reload
8
8
 
9
9
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
10
10
  DatabaseCleaner.strategy = :transaction
@@ -13,12 +13,14 @@ def setup_settings
13
13
  Setting::Rescue.load_defaults
14
14
  end
15
15
 
16
- class Minitest::Spec
17
- before :each do
18
- DatabaseCleaner.start
19
- end
16
+ module Minitest
17
+ class Spec
18
+ before :each do
19
+ DatabaseCleaner.start
20
+ end
20
21
 
21
- after :each do
22
- DatabaseCleaner.clean
22
+ after :each do
23
+ DatabaseCleaner.clean
24
+ end
23
25
  end
24
26
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rescue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: rdoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.49.1
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.49.1
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rdoc
28
+ name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.52.0
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'
40
+ version: 0.52.0
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
@@ -64,10 +64,10 @@ files:
64
64
  - locale/en/foreman_rescue.po
65
65
  - locale/foreman_rescue.pot
66
66
  - locale/gemspec.rb
67
+ - test/controllers/hosts_controller_test.rb
67
68
  - test/factories/host.rb
68
- - test/functional/hosts_controller_test.rb
69
+ - test/models/host_test.rb
69
70
  - test/test_plugin_helper.rb
70
- - test/unit/host_test.rb
71
71
  homepage: https://github.com/dm-drogeriemarkt/foreman_rescue
72
72
  licenses:
73
73
  - GPL-3.0
@@ -93,7 +93,7 @@ signing_key:
93
93
  specification_version: 4
94
94
  summary: Provides the ability to boot a host into a rescue system.
95
95
  test_files:
96
- - test/unit/host_test.rb
96
+ - test/models/host_test.rb
97
97
  - test/factories/host.rb
98
98
  - test/test_plugin_helper.rb
99
- - test/functional/hosts_controller_test.rb
99
+ - test/controllers/hosts_controller_test.rb