foreman_bootdisk 8.1.0 → 9.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
  SHA1:
3
- metadata.gz: 082ac2b9dd317b3ccc8009b039eb390a932b36d1
4
- data.tar.gz: 1e0c848ca45723620186429e46a2d9bf7d2a217f
3
+ metadata.gz: 51edea5185dd0ebc1d65265ee3829f0467865488
4
+ data.tar.gz: 437a6db3410aaa989e7d3567df89dc29b759119a
5
5
  SHA512:
6
- metadata.gz: 2778790684106e88c33f2838ab8d6d7fcefe225059c136855a21dbaf91a9d1a8e0dff7cff0ac3b41400c9de6284a839c0b5d84331b5ce7be9b161051062bb64b
7
- data.tar.gz: 67651bcb8230af2f329a1e822af51fa93d63747082ce1785d7ce74da528d87f6cbbb31b76ae71e6785454368794d389c49c2a7529d2f6937a9fb9307995d2f4b
6
+ metadata.gz: 8bb01e994002ba62e9752f02905a7176adf153804b1ee07272876b4e520c031a5cc5373e8cf9f296e1c88a8b726cc3315216ece1badc138fad265d2abc116ac5
7
+ data.tar.gz: '078ff4c14078cffac0f13c049666c5ac946e906eafc0c647fb0df735900ca54763108c1b0ea09c72c868e7e625ba5ef4645a1c19f9bfc2d979aa8c8d37aa44ed'
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v9.0.0
4
+ * add missing bootdisk helpers for template previews (#17893)
5
+ * disable boot disk button on non-Intel architectures (#17497)
6
+ * fix TFTP menu setup on Foreman 1.13 when creating full host disks
7
+
3
8
  ## v8.1.0
4
9
  * add separate ISOLINUX dir setting for Debian OSes (#14896)
5
10
  * add friendly setting category name for Foreman 1.14
data/README.md CHANGED
@@ -43,6 +43,7 @@ gPXE images are unsupported due to lack of initrd support.
43
43
  | >= 1.9 | ~> 6.0 |
44
44
  | >= 1.11 | >= 6.1, < 8.0 |
45
45
  | >= 1.12 | ~> 8.0 |
46
+ | >= 1.13 | ~> 9.0 |
46
47
 
47
48
  # Usage
48
49
 
@@ -6,20 +6,34 @@ module ForemanBootdisk::HostsHelperExt
6
6
  end
7
7
 
8
8
  def host_title_actions_with_bootdisk(*args)
9
+ if @host.bootdisk_downloadable?
10
+ title_actions(
11
+ button_group(
12
+ select_action_button(_('Boot disk'), {:class => 'btn btn-group'},
13
+ display_bootdisk_link_if_authorized(_("Host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'host', :id => @host}, :class=>'la'),
14
+ display_bootdisk_link_if_authorized(_("Full host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'full_host', :id => @host}, :class=>'la'),
15
+ content_tag(:li, "", :class => "divider"),
16
+ display_bootdisk_link_if_authorized(_("Generic image"), {:controller => 'foreman_bootdisk/disks', :action => 'generic'}, :class=>'la'),
17
+ display_bootdisk_for_subnet,
18
+ content_tag(:li, "", :class => "divider"),
19
+ display_bootdisk_link_if_authorized(_("Help"), {:controller => 'foreman_bootdisk/disks', :action => 'help'}, :class=>'la')
20
+ )
21
+ )
22
+ )
23
+ else
24
+ bootdisk_button_disabled
25
+ end
26
+
27
+ host_title_actions_without_bootdisk(*args)
28
+ end
29
+
30
+ def bootdisk_button_disabled
9
31
  title_actions(
10
32
  button_group(
11
- select_action_button(_('Boot disk'), {:class => 'btn btn-group'},
12
- display_bootdisk_link_if_authorized(_("Host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'host', :id => @host}, :class=>'la'),
13
- display_bootdisk_link_if_authorized(_("Full host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'full_host', :id => @host}, :class=>'la'),
14
- content_tag(:li, "", :class => "divider"),
15
- display_bootdisk_link_if_authorized(_("Generic image"), {:controller => 'foreman_bootdisk/disks', :action => 'generic'}, :class=>'la'),
16
- display_bootdisk_for_subnet,
17
- content_tag(:li, "", :class => "divider"),
18
- display_bootdisk_link_if_authorized(_("Help"), {:controller => 'foreman_bootdisk/disks', :action => 'help'}, :class=>'la')
19
- )
33
+ link_to(_("Boot disk"), '#', :disabled => true, :class => 'btn btn-default',
34
+ :title => _("Boot disk download not available for %s architecture") % @host.architecture.name)
20
35
  )
21
36
  )
22
- host_title_actions_without_bootdisk(*args)
23
37
  end
24
38
 
25
39
  # need to wrap this one in a test for template proxy presence
@@ -33,6 +33,14 @@ module ForemanBootdisk::HostExt
33
33
  managed? && bootdisk_build? && SETTINGS[:unattended]
34
34
  end
35
35
 
36
+ def bootdisk_downloadable?
37
+ architecture.blank? || intel_arch?
38
+ end
39
+
40
+ def intel_arch?
41
+ /i.86|x86[_-]64/ =~ architecture.name
42
+ end
43
+
36
44
  def validate_media_with_bootdisk?
37
45
  validate_media_without_bootdisk? || (managed && bootdisk_build? && build?)
38
46
  end
@@ -10,7 +10,7 @@ class ForemanBootdisk::ISOGenerator
10
10
  def self.generate_full_host(host, opts = {}, &block)
11
11
  raise ::Foreman::Exception.new(N_('Host is not in build mode, so the template cannot be rendered')) unless host.build?
12
12
 
13
- tmpl = host.send(:generate_pxe_template)
13
+ tmpl = host.send(:generate_pxe_template, :PXELinux)
14
14
  raise ::Foreman::Exception.new(N_('Unable to generate disk template: %s'), host.errors.full_messages.to_sentence) if tmpl == false
15
15
 
16
16
  # pxe_files and filename conversion is utterly bizarre
@@ -5,6 +5,7 @@ module ForemanBootdisk
5
5
  include ::Foreman::Renderer
6
6
  include Rails.application.routes.url_helpers
7
7
  delegate :logger, :to => :ForemanBootdisk
8
+ include RendererMethods
8
9
 
9
10
  def generic_template_render(subnet = nil)
10
11
  tmpl = ProvisioningTemplate.find_by_name(Setting[:bootdisk_generic_host_template]) || raise(::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template'))
@@ -24,17 +25,5 @@ module ForemanBootdisk
24
25
  modified_template.gsub!(/(?<=iPXE\?)token=faketoken\&(?=mac=)/,'')
25
26
  modified_template
26
27
  end
27
-
28
- def bootdisk_chain_url(mac = '', action = 'iPXE')
29
- Renderer.format_bootdisk_chain_url(foreman_url(action), mac)
30
- end
31
-
32
- def self.format_bootdisk_chain_url(url, mac)
33
- u = URI.parse(url)
34
- ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
35
- u.query = "#{u.query}&mac=#{mac}"
36
- u.fragment = nil
37
- u.to_s
38
- end
39
28
  end
40
29
  end
@@ -0,0 +1,19 @@
1
+ module ForemanBootdisk
2
+ module RendererMethods
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ def format_bootdisk_chain_url(url, mac)
7
+ u = URI.parse(url)
8
+ ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
9
+ u.query = "#{u.query}&mac=#{mac}"
10
+ u.fragment = nil
11
+ u.to_s
12
+ end
13
+ end
14
+
15
+ def bootdisk_chain_url(mac = '', action = 'iPXE')
16
+ self.class.format_bootdisk_chain_url(foreman_url(action), mac)
17
+ end
18
+ end
19
+ end
@@ -48,7 +48,7 @@ module ForemanBootdisk
48
48
 
49
49
  initializer 'foreman_bootdisk.register_plugin', :before => :finisher_hook do |app|
50
50
  Foreman::Plugin.register :foreman_bootdisk do
51
- requires_foreman '>= 1.12'
51
+ requires_foreman '>= 1.13'
52
52
 
53
53
  security_block :bootdisk do |map|
54
54
  permission :download_bootdisk, {:'foreman_bootdisk/disks' => [:generic, :host, :full_host, :subnet, :help],
@@ -62,6 +62,7 @@ module ForemanBootdisk
62
62
  apipie_documented_controllers ["#{ForemanBootdisk::Engine.root}/app/controllers/foreman_bootdisk/api/v2/*.rb"]
63
63
  provision_method 'bootdisk', N_('Boot disk based')
64
64
  template_labels 'Bootdisk' => N_('Boot disk embedded template')
65
+ extend_template_helpers ForemanBootdisk::RendererMethods
65
66
  end
66
67
  end
67
68
 
@@ -1,3 +1,3 @@
1
1
  module ForemanBootdisk
2
- VERSION = '8.1.0'
2
+ VERSION = '9.0.0'
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class ForemanBootdisk::Api::V2::DisksControllerTest < ActionController::TestCase
4
+ include ForemanBootdiskTestHelper
4
5
  setup :setup_bootdisk
5
6
 
6
7
  test "should generate generic image" do
@@ -12,6 +13,7 @@ class ForemanBootdisk::Api::V2::DisksControllerTest < ActionController::TestCase
12
13
  end
13
14
 
14
15
  describe "#host" do
16
+ setup :setup_referer
15
17
  setup :setup_host_env
16
18
 
17
19
  test "should generate host image" do
@@ -1,9 +1,11 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class ForemanBootdisk::Api::V2::SubnetDisksControllerTest < ActionController::TestCase
4
+ include ForemanBootdiskTestHelper
4
5
  setup :setup_bootdisk
5
6
 
6
7
  describe "#subnet_host" do
8
+ setup :setup_referer
7
9
  setup :setup_org_loc
8
10
  setup :setup_subnet
9
11
  setup :setup_host
@@ -1,6 +1,7 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
4
+ include ForemanBootdiskTestHelper
4
5
  setup :setup_bootdisk
5
6
 
6
7
  test "should generate generic image" do
@@ -12,6 +13,7 @@ class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
12
13
  end
13
14
 
14
15
  describe "#host" do
16
+ setup :setup_referer
15
17
  setup :setup_org_loc
16
18
  setup :setup_subnet
17
19
  setup :setup_host
@@ -44,6 +46,7 @@ class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
44
46
  end
45
47
 
46
48
  describe "#host without tftp" do
49
+ setup :setup_referer
47
50
  setup :setup_org_loc
48
51
  setup :setup_subnet_no_tftp
49
52
  setup :setup_host
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ActionController::TestCase
3
+ module ForemanBootdiskTestHelper
4
4
  def setup_bootdisk
5
5
  setup_routes
6
6
  setup_settings
@@ -25,9 +25,12 @@ class ActionController::TestCase
25
25
  load File.join(File.dirname(__FILE__), '..', 'db', 'seeds.d', '50-bootdisk_templates.rb')
26
26
  end
27
27
 
28
+ def setup_referer
29
+ request.env["HTTP_REFERER"] = "/history"
30
+ end
31
+
28
32
  def setup_org_loc
29
33
  disable_orchestration
30
- request.env["HTTP_REFERER"] = "/history"
31
34
  @org, @loc = FactoryGirl.create(:organization), FactoryGirl.create(:location)
32
35
  end
33
36
 
@@ -10,6 +10,7 @@ class ForemanBootdisk::VmwareTest < ActiveSupport::TestCase
10
10
  test "does not call clone_vm when bootdisk provisioning" do
11
11
  args = { "provision_method" => "bootdisk" }
12
12
  mock_vm = mock('vm')
13
+ mock_vm.stubs(:firmware)
13
14
  mock_vm.expects(:save).returns(mock_vm)
14
15
  @cr.stubs(:parse_networks).returns(args)
15
16
  @cr.expects(:clone_vm).times(0)
@@ -40,4 +40,34 @@ class ForemanBootdisk::HostTest < ActiveSupport::TestCase
40
40
  assert_equal false, h.bootdisk?
41
41
  end
42
42
  end
43
+
44
+ context "#bootdisk_downloadable?" do
45
+ test "should be true for 64 bit architecture" do
46
+ architecture = Architecture.where(:name => 'x86_64').first
47
+ host = FactoryGirl.build(:host, :managed, :architecture => architecture)
48
+
49
+ assert host.bootdisk_downloadable?
50
+ end
51
+
52
+ test "should be true for 32 bit architecture" do
53
+ architecture = FactoryGirl.create(:architecture, :name => 'i386')
54
+ host = FactoryGirl.build(:host, :managed, :architecture => architecture)
55
+
56
+ assert host.bootdisk_downloadable?
57
+ end
58
+
59
+ test "should be false for non-intel architecture" do
60
+ architecture = Architecture.where(:name => 's390').first
61
+ host = FactoryGirl.build(:host, :managed, :architecture => architecture)
62
+
63
+ assert_not host.bootdisk_downloadable?
64
+ end
65
+
66
+ test 'should be true if architecture is absent' do
67
+ host = FactoryGirl.build(:host, :managed, :architecture => nil)
68
+
69
+ assert_equal host.architecture, nil
70
+ assert host.bootdisk_downloadable?
71
+ end
72
+ end
43
73
  end
@@ -0,0 +1,49 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanBootdisk::IsoGeneratorTest < ActiveSupport::TestCase
4
+ include ForemanBootdiskTestHelper
5
+ setup :setup_bootdisk
6
+ setup :setup_org_loc
7
+ setup :setup_subnet
8
+ setup :setup_host
9
+
10
+ setup do
11
+ @host.build = true
12
+ end
13
+
14
+ test "generate_full_host creates with ISO-compatible file names" do
15
+ @host.expects(:generate_pxe_template).with(:PXELinux).returns("Fake kernel line boot/Debian-8.1-x86_64-vmlinuz")
16
+ boot_files = [
17
+ {:"boot/Debian-8.1-x86_64"=>"/tmp/pxeboot/vmlinuz"},
18
+ {:"boot/Debian-8.1-x86_64"=>"/tmp/pxeboot/initrd.img"}
19
+ ]
20
+ @host.operatingsystem.expects(:pxe_files).returns(boot_files)
21
+ ForemanBootdisk::ISOGenerator.expects(:generate).with({
22
+ :isolinux => 'Fake kernel line BOOT/DEBIAN_8_1_X86_64_VMLINUZ',
23
+ :files => [[['BOOT/DEBIAN_8_1_X86_64_VMLINUZ', '/tmp/pxeboot/vmlinuz']],
24
+ [['BOOT/DEBIAN_8_1_X86_64_INITRD_IMG', '/tmp/pxeboot/initrd.img']]] }, anything)
25
+ ForemanBootdisk::ISOGenerator.generate_full_host(@host)
26
+ end
27
+
28
+ test "generate_full_host creates with ISO-compatible long file names" do
29
+ @host.expects(:generate_pxe_template).with(:PXELinux).returns("Fake kernel line boot/RedHatEnterpriseLinuxAtomic-7.3-x86_64-vmlinuz")
30
+ boot_files = [
31
+ {:"boot/RedHatEnterpriseLinuxAtomic-7.3-x86_64"=>"/tmp/pxeboot/vmlinuz"},
32
+ {:"boot/RedHatEnterpriseLinuxAtomic-7.3-x86_64"=>"/tmp/pxeboot/initrd.img"}
33
+ ]
34
+ @host.operatingsystem.expects(:pxe_files).returns(boot_files)
35
+ ForemanBootdisk::ISOGenerator.expects(:generate).with({
36
+ :isolinux => 'Fake kernel line BOOT/NUXATOMIC_7_3_X86_64_VMLINUZ',
37
+ :files => [[['BOOT/NUXATOMIC_7_3_X86_64_VMLINUZ', '/tmp/pxeboot/vmlinuz']],
38
+ [['BOOT/ATOMIC_7_3_X86_64_INITRD_IMG', '/tmp/pxeboot/initrd.img']]]}, anything)
39
+ ForemanBootdisk::ISOGenerator.generate_full_host(@host)
40
+ end
41
+
42
+ test "full host image generation generates via PXELinux type" do
43
+ @host.operatingsystem.expects(:pxe_files).returns([])
44
+ @host.operatingsystem.expects(:kernel).returns("kernel")
45
+ @host.operatingsystem.expects(:initrd).returns("initrd")
46
+ ForemanBootdisk::ISOGenerator.expects(:generate).with({:isolinux => nil, :files => []}, anything)
47
+ ForemanBootdisk::ISOGenerator.generate_full_host(@host)
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_bootdisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin for Foreman that creates iPXE-based boot disks to provision hosts
14
14
  without the need for PXE infrastructure.
@@ -36,6 +36,7 @@ files:
36
36
  - app/models/setting/bootdisk.rb
37
37
  - app/services/foreman_bootdisk/iso_generator.rb
38
38
  - app/services/foreman_bootdisk/renderer.rb
39
+ - app/services/foreman_bootdisk/renderer_methods.rb
39
40
  - app/views/foreman_bootdisk/disks/help.html.erb
40
41
  - app/views/foreman_bootdisk/generic_host.erb
41
42
  - app/views/foreman_bootdisk/host.erb
@@ -93,9 +94,10 @@ files:
93
94
  - test/unit/concerns/compute_resources/vmware_test.rb
94
95
  - test/unit/concerns/host_test.rb
95
96
  - test/unit/concerns/orchestration/compute_test.rb
97
+ - test/unit/iso_generator_test.rb
96
98
  homepage: http://github.com/theforeman/foreman_bootdisk
97
99
  licenses:
98
- - GPL-3
100
+ - GPL-3.0
99
101
  metadata: {}
100
102
  post_install_message:
101
103
  rdoc_options: []
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.6.8
118
+ rubygems_version: 2.6.10
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Create boot disks to provision hosts with Foreman