foreman_rescue 1.0.0 → 2.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: fed912b0085c3e6ab01cca79cc2e8df1986b71b8be95449caefa27a461d0ae50
4
- data.tar.gz: 4f9c97ca7d406a58492bc8ac00f4b813dd009faddd857940abdda9275cce0942
3
+ metadata.gz: 1709ec2eb0238edc6b519747e90f282143a0ef2c4295007789ca8dd2cc0595e7
4
+ data.tar.gz: 3cc1c58fb18652286af8f3c1180fab872baec1922b8511c8137a4de2da591a8c
5
5
  SHA512:
6
- metadata.gz: 589d947221c47ccca4d6d5ff1e7ad2f9beba1472a597c91017512ea3b82f97b7ba59e15e45eb6cf4aea3c884ff0df01510cd822ec1ed7fde423e5c6861b34ce6
7
- data.tar.gz: 74308ab3113c2586326fac9e818c2f5a8871e1d0ad1354a21e8ecb88e2aa4c012360ce4c8b1645dac4ec86d9a59d771763c741b1eaecaee39f2f396663a43d78
6
+ metadata.gz: b1f3589dbecaa1643690057abc0a9302e3ebe3637d408a760c14e9739a1f7ac9842b08bfb5b896a0f9ef3e6bae61cbd2bf3925b8739639cafcc59f75a053ab0d
7
+ data.tar.gz: 14457ed5eb8cf325dd6fe9abf915f03765312e8be66f90d7824dea071c761c5e7a99cacfeccfa78de508b9fcb961fe56e4f617307b9a1d25c5fbb0696a0c4570
data/README.md CHANGED
@@ -8,6 +8,7 @@ This plugin allows a user to boot a Foreman host into a rescue system via PXE.
8
8
  | --------------- | -------------- |
9
9
  | >= 1.15 | ~> 0.1 |
10
10
  | >= 1.17 | ~> 1.0 |
11
+ | >= 1.20 | ~> 2.0 |
11
12
 
12
13
  ## Installation
13
14
 
@@ -37,7 +37,7 @@ module ForemanRescue
37
37
  template_name = Setting["rescue_#{kind.downcase}_tftp_template"]
38
38
  template = ::ProvisioningTemplate.find_by(name: template_name)
39
39
  return if template.blank?
40
- unattended_render template
40
+ host.render_template(template: template)
41
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
@@ -1,18 +1,20 @@
1
1
  class Setting
2
2
  class Rescue < ::Setting
3
+ BLANK_ATTRS.concat ['rescue_pxegrub_tftp_template', 'rescue_pxegrub2_tftp_template']
4
+
3
5
  def self.default_settings
4
6
  [
5
7
  set('rescue_pxelinux_tftp_template',
6
8
  N_('PXELinux template used when booting rescue system'),
7
- 'create', N_('PXELinux rescue template'), nil,
9
+ 'Kickstart rescue PXELinux', N_('PXELinux rescue template'), nil,
8
10
  :collection => proc { Setting::Rescue.templates('PXELinux') }),
9
11
  set('rescue_pxegrub_tftp_template',
10
12
  N_('PXEGrub template used when booting rescue system'),
11
- 'create', N_('PXEGrub rescue template'), nil,
13
+ '', N_('PXEGrub rescue template'), nil,
12
14
  :collection => proc { Setting::Rescue.templates('PXEGrub') }),
13
15
  set('rescue_pxegrub2_tftp_template',
14
16
  N_('PXEGrub2 template used when booting rescue system'),
15
- 'create', N_('PXEGrub2 rescue template'), nil,
17
+ '', N_('PXEGrub2 rescue template'), nil,
16
18
  :collection => proc { Setting::Rescue.templates('PXEGrub 2') })
17
19
  ]
18
20
  end
@@ -0,0 +1,70 @@
1
+ <%#
2
+ kind: PXELinux
3
+ name: Kickstart rescue PXELinux
4
+ model: ProvisioningTemplate
5
+ oses:
6
+ - CentOS
7
+ - Fedora
8
+ - RedHat
9
+ -%>
10
+ # This file was deployed via '<%= template_name %>' template
11
+
12
+ <%
13
+ major = @host.operatingsystem.major.to_i
14
+ mac = @host.provision_interface.mac
15
+
16
+ # Tell Anaconda to perform network functions with boot interface
17
+ # both current and legacy syntax provided
18
+ options = ["ksdevice=bootif", "ks.device=bootif"]
19
+ if mac
20
+ bootif = '00-' + mac.gsub(':', '-')
21
+ options.push("BOOTIF=#{bootif}")
22
+ end
23
+
24
+ # Tell Anaconda what to pass off to kickstart server
25
+ # both current and legacy syntax provided
26
+ options.push("nomount", "lang=en_US", "keymap=us")
27
+
28
+ # handle non-DHCP environments (e.g. bootdisk)
29
+ subnet = @host.provision_interface.subnet
30
+ unless subnet.dhcp_boot_mode?
31
+ # static network configuration
32
+ ip = @host.provision_interface.ip
33
+ mask = subnet.mask
34
+ gw = subnet.gateway
35
+ dns = [subnet.dns_primary]
36
+ if subnet.dns_secondary != ''
37
+ dns.push(subnet.dns_secondary)
38
+ end
39
+ if (@host.operatingsystem.name.match(/Fedora/i) && major < 17) || major < 7
40
+ # old Anacoda found in Fedora 16 or RHEL 6 and older
41
+ dns_servers = dns.join(',')
42
+ options.push("ip=#{ip}", "netmask=#{mask}", "gateway=#{gw}", "dns=#{dns_servers}")
43
+ else
44
+ options.push("ip=#{ip}::#{gw}:#{mask}:::none")
45
+ dns.each { |server|
46
+ options.push("nameserver=#{server}")
47
+ }
48
+ end
49
+ end
50
+
51
+ # kickstart repository for LiveOS
52
+ options.push("method=#{@host.operatingsystem.medium_uri(@host)}")
53
+
54
+ if host_param('blacklist')
55
+ options.push("modprobe.blacklist=" + host_param('blacklist').gsub(' ', ''))
56
+ end
57
+
58
+ # Enable rescue mode
59
+ options.push('rescue')
60
+
61
+ ksoptions = options.join(' ')
62
+ -%>
63
+
64
+ TIMEOUT <%= host_param('loader_timeout') || 10 %>
65
+ DEFAULT <%= template_name %>
66
+
67
+ LABEL <%= template_name %>
68
+ KERNEL <%= @kernel %>
69
+ APPEND initrd=<%= @initrd %> <%= pxe_kernel_options %> <%= ksoptions %>
70
+ IPAPPEND 2
@@ -0,0 +1,18 @@
1
+ User.as_anonymous_admin do
2
+ templates = [
3
+ { :name => 'Kickstart rescue PXELinux', :source => 'PXELinux/kickstart_rescue_pxelinux.erb', :template_kind => TemplateKind.find_by(:name => 'PXELinux') }
4
+ ]
5
+
6
+ templates.each do |template|
7
+ template[:contents] = File.read(File.join(ForemanRescue::Engine.root, 'app/views/foreman/unattended/provisioning_templates', template[:source]))
8
+ ProvisioningTemplate.where(:name => template[:name]).first_or_create do |pt|
9
+ pt.vendor = 'ForemanRescue'
10
+ pt.default = true
11
+ pt.locked = true
12
+ pt.name = template[:name]
13
+ pt.template = template[:contents]
14
+ pt.template_kind = template[:template_kind] if template[:template_kind]
15
+ pt.snippet = template[:snippet] if template[:snippet]
16
+ end
17
+ end
18
+ end
@@ -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.17'
28
+ requires_foreman '>= 1.20'
29
29
 
30
30
  # Add permissions
31
31
  security_block :foreman_rescue do
@@ -44,6 +44,12 @@ module ForemanRescue
44
44
  end
45
45
  end
46
46
 
47
+ rake_tasks do
48
+ Rake::Task['db:seed'].enhance do
49
+ ForemanOmaha::Engine.load_seed
50
+ end
51
+ end
52
+
47
53
  initializer 'foreman_rescue.register_gettext', after: :load_config_initializers do |_app|
48
54
  locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
49
55
  locale_domain = 'foreman_rescue'
@@ -1,3 +1,3 @@
1
1
  module ForemanRescue
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -36,7 +36,7 @@ module ForemanRescue
36
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
- assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
39
+ assert_equal "Enabled #{host} for rescue system on next boot.", flash[:success]
40
40
  end
41
41
 
42
42
  context 'when reboot is requested' do
@@ -51,7 +51,7 @@ module ForemanRescue
51
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
- assert_equal "Enabled #{host} for reboot into rescue system.", flash[:notice]
54
+ assert_equal "Enabled #{host} for reboot into rescue system.", flash[:success]
55
55
  end
56
56
 
57
57
  test 'with failed reboot, the flash should inform it' do
@@ -60,7 +60,7 @@ module ForemanRescue
60
60
  host.power.reset
61
61
  assert_response :found
62
62
  assert_redirected_to hosts_path
63
- assert_equal "Enabled #{host} for boot into rescue system on next boot, but failed to power cycle the host.", flash[:notice]
63
+ assert_equal "Enabled #{host} for boot into rescue system on next boot, but failed to power cycle the host.", flash[:success]
64
64
  end
65
65
 
66
66
  test 'reboot raised exception, the flash should inform it' do
@@ -68,7 +68,7 @@ module ForemanRescue
68
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
- assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
71
+ assert_equal "Enabled #{host} for rescue system on next boot.", flash[:success]
72
72
  end
73
73
  end
74
74
  end
@@ -92,7 +92,7 @@ module ForemanRescue
92
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
- assert_equal "Canceled booting into rescue system for #{host}.", flash[:notice]
95
+ assert_equal "Canceled booting into rescue system for #{host}.", flash[:success]
96
96
  end
97
97
  end
98
98
 
@@ -0,0 +1,33 @@
1
+ require 'test_plugin_helper'
2
+
3
+ module ForemanRescue
4
+ class SeedsTest < ActiveSupport::TestCase
5
+ setup do
6
+ Foreman.stubs(:in_rake?).returns(true)
7
+ end
8
+
9
+ teardown do
10
+ User.current = nil
11
+ end
12
+
13
+ test 'seeds rescue provisioning templates' do
14
+ seed
15
+ assert ProvisioningTemplate.unscoped.where(:default => true).exists?
16
+ expected_template_names = ['Kickstart rescue PXELinux']
17
+
18
+ seeded_templates = ProvisioningTemplate.unscoped.where(:default => true, :vendor => 'ForemanRescue').pluck(:name)
19
+
20
+ expected_template_names.each do |template|
21
+ assert_includes seeded_templates, template
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def seed
28
+ User.current = FactoryBot.build(:user, :admin => true,
29
+ :organizations => [], :locations => [])
30
+ load Rails.root.join('db', 'seeds.rb')
31
+ end
32
+ end
33
+ end
@@ -51,7 +51,6 @@ class HostTest < ActiveSupport::TestCase
51
51
  assert_includes tasks, "Deploy TFTP PXEGrub2 config for #{host}"
52
52
  assert_includes tasks, "Deploy TFTP PXELinux config for #{host}"
53
53
  assert_includes tasks, "Deploy TFTP PXEGrub config for #{host}"
54
- assert_equal 3, tasks.size
55
54
  end
56
55
 
57
56
  test 'should deploy rescue template' do
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: 1.0.0
4
+ version: 2.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-08 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -53,9 +53,11 @@ files:
53
53
  - app/models/concerns/foreman_rescue/host_extensions.rb
54
54
  - app/models/concerns/foreman_rescue/orchestration/tftp.rb
55
55
  - app/models/setting/rescue.rb
56
+ - app/views/foreman/unattended/provisioning_templates/PXELinux/kickstart_rescue_pxelinux.erb
56
57
  - app/views/foreman_rescue/hosts/rescue.html.erb
57
58
  - config/routes.rb
58
59
  - db/migrate/20170901131321_add_rescue_mode_to_host.foreman_rescue.rb
60
+ - db/seeds.d/103-provisioning_templates.rb
59
61
  - lib/foreman_rescue.rb
60
62
  - lib/foreman_rescue/engine.rb
61
63
  - lib/foreman_rescue/version.rb
@@ -66,6 +68,7 @@ files:
66
68
  - locale/gemspec.rb
67
69
  - test/controllers/hosts_controller_test.rb
68
70
  - test/factories/host.rb
71
+ - test/lib/tasks/seeds_test.rb
69
72
  - test/models/host_test.rb
70
73
  - test/test_plugin_helper.rb
71
74
  homepage: https://github.com/dm-drogeriemarkt/foreman_rescue
@@ -95,5 +98,6 @@ summary: Provides the ability to boot a host into a rescue system.
95
98
  test_files:
96
99
  - test/models/host_test.rb
97
100
  - test/factories/host.rb
101
+ - test/lib/tasks/seeds_test.rb
98
102
  - test/test_plugin_helper.rb
99
103
  - test/controllers/hosts_controller_test.rb