foreman_bootdisk 12.0.1 → 13.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: abab6031b8511f7af62b971e9c5c71f6232939598072f768293bccd601006426
4
- data.tar.gz: b00a72a8e9671356e7bb6fa2f0de33024d58c8e6eb96aa72da75149e99c2e496
3
+ metadata.gz: d43b8549de63eaac53bdccedfed1db1c8c96f9481ee411724686686476e01767
4
+ data.tar.gz: 30d918f87198e96711e2d75506127bb7ded00cafef415e5eaa176c24810f1a94
5
5
  SHA512:
6
- metadata.gz: 5a8be6424824875972b6416ed1b68415ced0c1979db35b693a05e91660078114ff0489c7ba113d4be11b1ae3c15c779012ed71d770242248e9d87859c67adb75
7
- data.tar.gz: 0fd0503eb874bd3c3a73b9e2515a5a15d28076a1a714a484865b447302601af299615b14f8f7d430b89eb373d1f684dfdc93279ce0fd7f06409e8d5afee47437
6
+ metadata.gz: c8d73855b7dbf1f7ed717883a56813917d1fba38ca226cf77fa0c73005b38e44220563bd411c112c636182ba328d52ef336b912c80c7c356f29a4d8bb29687ab
7
+ data.tar.gz: 832d7248d4bc1364f17507dad46325cd929e719790d3ebe08529459a21762d557987d908c5fca82d632bd8e522df3f4a1ba34b49a24faff60a0f5ebc0c6b5251
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v13.0.0
4
+ * static credentials failover
5
+ * Rails 5.2 support
6
+ * use of core new renderer framework
7
+
3
8
  ## v12.0.0
4
9
  * fixed subnet image token stub (#22428)
5
10
  * moved MAC based identification to Foreman core (#22858)
data/README.md CHANGED
@@ -47,6 +47,8 @@ gPXE images are unsupported due to lack of initrd support.
47
47
  | >= 1.15 | ~> 10.0 |
48
48
  | >= 1.17 | ~> 11.0 |
49
49
  | >= 1.18 | ~> 12.0 |
50
+ | >= 1.19 | ~> 12.0 |
51
+ | >= 1.20 | ~> 13.0 |
50
52
 
51
53
  # Usage
52
54
 
@@ -4,6 +4,10 @@ module ForemanBootdisk
4
4
  class DisksController < ::ApplicationController
5
5
  before_action :find_resource, :only => %w[host full_host subnet]
6
6
 
7
+ # as this engine is isolated, we need to include url helpers from core explicitly
8
+ # to render help page layout
9
+ include Rails.application.routes.url_helpers
10
+
7
11
  def generic
8
12
  begin
9
13
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
@@ -0,0 +1,21 @@
1
+ module ForemanBootdisk
2
+ module Scope
3
+ class Bootdisk < ::Foreman::Renderer::Scope::Provisioning
4
+ def bootdisk_chain_url(mac = host.try(:mac), action = 'iPXE')
5
+ url = foreman_url(action)
6
+ u = URI.parse(url)
7
+ ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
8
+ new_query_data = URI.decode_www_form(u.query || '') << ['mac', mac || '']
9
+ new_querystring = URI.encode_www_form(new_query_data)
10
+ u.query = nil
11
+ u.query = new_querystring if new_querystring.present?
12
+ u.fragment = nil
13
+ u.to_s
14
+ end
15
+
16
+ def bootdisk_raise(*args)
17
+ raise ::Foreman::Exception.new(*args)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -6,8 +6,7 @@ module ForemanBootdisk::HostExt
6
6
  end
7
7
 
8
8
  def bootdisk_template_render
9
- @host = self
10
- unattended_render(bootdisk_template.template)
9
+ ForemanBootdisk::Renderer.new.render_template(template: bootdisk_template, host: self)
11
10
  end
12
11
 
13
12
  def bootdisk_build?
@@ -26,6 +25,10 @@ module ForemanBootdisk::HostExt
26
25
  /i.86|x86[_-]64/ =~ architecture.name
27
26
  end
28
27
 
28
+ def validate_media?
29
+ super || (managed && bootdisk_build? && build?)
30
+ end
31
+
29
32
  def can_be_built?
30
33
  super || (managed? and SETTINGS[:unattended] and bootdisk_build? and !build?)
31
34
  end
@@ -2,28 +2,43 @@ require 'uri'
2
2
 
3
3
  module ForemanBootdisk
4
4
  class Renderer
5
- include ::Foreman::Renderer
6
- include Rails.application.routes.url_helpers
7
- delegate :logger, :to => :ForemanBootdisk
8
- include RendererMethods
9
-
10
5
  def generic_template_render(subnet = nil)
11
- tmpl = ProvisioningTemplate.unscoped.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'))
12
-
13
6
  if subnet.present?
14
7
  # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
15
- # valid host, with a token, and with a tftp proxy
16
- @host = Struct.new(:token, :provision_interface).new(
17
- Struct.new(:value).new('faketoken'),
8
+ # valid host, without a token, but with a tftp proxy
9
+ host = Struct.new(:token, :provision_interface).new(
10
+ nil,
18
11
  Struct.new(:subnet).new(subnet)
19
12
  )
20
13
  else
21
- @host = Struct.new(:token, :subnet).new(nil,nil)
14
+ host = Struct.new(:token, :subnet).new(nil, nil)
22
15
  end
23
- modified_template = unattended_render(tmpl.template)
24
- # remove the token from subnet-level generation, since this is meant to be generic
25
- modified_template.gsub!(/(?<=iPXE\?)token=faketoken\&(?=mac=)/,'')
26
- modified_template
16
+
17
+ render_template(template: generic_host_template, host: host)
18
+ end
19
+
20
+ def render_template(template: , host:)
21
+ source = Foreman::Renderer.get_source(
22
+ template: template,
23
+ host: host
24
+ )
25
+ scope = Foreman::Renderer.get_scope(
26
+ host: host,
27
+ klass: renderer_scope
28
+ )
29
+ Foreman::Renderer.render(source, scope)
30
+ end
31
+
32
+ private
33
+
34
+ def renderer_scope
35
+ ForemanBootdisk::Scope::Bootdisk
36
+ end
37
+
38
+ def generic_host_template
39
+ template = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template])
40
+ raise ::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template') unless template
41
+ template
27
42
  end
28
43
  end
29
44
  end
@@ -21,8 +21,26 @@ dhcp net<%= i %> || goto net<%= i+1 %>
21
21
  chain <%= url %>${net<%= i -%>/mac} || goto net<%= i+1 %>
22
22
  exit 0
23
23
  <% end -%>
24
+ echo Failed to chainload from any network interface, fallback to static.
25
+ ifstat
24
26
 
25
27
  :no_nic
26
- echo Failed to chainload from any network interface
27
- sleep 30
28
- exit 1
28
+ echo -n Enter interface name to boot from (e.g. net0): && read interface
29
+ isset ${${interface}/mac} && goto get_static_ip
30
+ echo Interface ${interface} is not initialized, try again
31
+ goto no_nic
32
+
33
+ :get_static_ip
34
+ ifopen ${interface}
35
+ echo Please enter IP details for ${interface}
36
+ echo
37
+ echo -n IP address : && read ${interface}/ip
38
+ echo -n Subnet mask : && read ${interface}/netmask
39
+ echo -n Default gateway : && read ${interface}/gateway
40
+ echo -n DNS server : && read dns
41
+ chain <%= url %>${${interface}/mac} || goto boot_failure
42
+ exit 0
43
+
44
+ :boot_failure
45
+ echo Cannot continue, spawning shell
46
+ shell
@@ -48,6 +48,5 @@ chain <%= bootdisk_chain_url %>
48
48
  exit 0
49
49
 
50
50
  :no_nic
51
- echo Cannot find interface with MAC <%= interface.mac %>
52
- sleep 30
53
- exit 1
51
+ echo Cannot find interface with MAC <%= interface.mac %>, spawning shell
52
+ shell
@@ -1,6 +1,6 @@
1
1
  class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
2
2
  class FakeConfigTemplate < ApplicationRecord
3
- if ActiveRecord::Migrator.get_all_versions.include?(20150514072626)
3
+ if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20150514072626)
4
4
  self.table_name = 'templates'
5
5
  else
6
6
  self.table_name = 'config_templates'
@@ -9,8 +9,9 @@ module ForemanBootdisk
9
9
  config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
10
10
  config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
11
11
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
12
+ config.autoload_paths += Dir["#{config.root}/app/lib"]
12
13
 
13
- initializer 'foreman_bootdisk.mount_engine', :after=> :build_middleware_stack do |app|
14
+ initializer 'foreman_bootdisk.mount_engine' do |app|
14
15
  app.routes_reloader.paths << "#{ForemanBootdisk::Engine.root}/config/routes/mount_engine.rb"
15
16
  end
16
17
 
@@ -60,11 +61,10 @@ module ForemanBootdisk
60
61
 
61
62
  add_all_permissions_to_default_roles
62
63
 
63
- allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
64
64
  apipie_documented_controllers ["#{ForemanBootdisk::Engine.root}/app/controllers/foreman_bootdisk/api/v2/*.rb"]
65
65
  provision_method 'bootdisk', N_('Boot disk based')
66
66
  template_labels 'Bootdisk' => N_('Boot disk embedded template')
67
- extend_template_helpers ForemanBootdisk::RendererMethods
67
+ allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
68
68
  end
69
69
  end
70
70
 
@@ -77,7 +77,6 @@ module ForemanBootdisk
77
77
  config.to_prepare do
78
78
  begin
79
79
  Host::Managed.send(:prepend, ForemanBootdisk::HostExt)
80
- Host::Managed.send(:include, ForemanBootdisk::RendererMethods)
81
80
  Host::Managed.send(:include, ForemanBootdisk::Orchestration::Compute) if SETTINGS[:unattended]
82
81
  HostsHelper.send(:prepend, ForemanBootdisk::HostsHelperExt)
83
82
  Foreman::Model::Vmware.send(:prepend, ForemanBootdisk::ComputeResources::Vmware) if Foreman::Model::Vmware.available?
@@ -1,3 +1,3 @@
1
1
  module ForemanBootdisk
2
- VERSION = '12.0.1'
2
+ VERSION = '13.0.0'
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class Host::ManagedTest < ActiveSupport::TestCase
4
+ include ForemanBootdiskTestHelper
5
+
6
+ setup do
7
+ User.current = users(:admin)
8
+ setup_bootdisk
9
+ end
10
+
11
+ context 'with host' do
12
+ let(:host) { FactoryBot.create(:host, :managed, :with_subnet, build: true) }
13
+
14
+ test 'finds the bootdisk_template specified in settings' do
15
+ assert_kind_of ProvisioningTemplate, host.bootdisk_template
16
+ end
17
+
18
+ test 'renders the host bootdisk template' do
19
+ assert_includes host.bootdisk_template_render, 'loop_success'
20
+ end
21
+ end
22
+ end
@@ -9,6 +9,14 @@ class ForemanBootdisk::HostTest < ActiveSupport::TestCase
9
9
  refute host.pxe_build?
10
10
  end
11
11
 
12
+ test "#validate_media? must be true when provision_method is bootdisk" do
13
+ host = FactoryBot.build(:host, :managed,
14
+ :provision_method => "bootdisk",
15
+ :build => true,
16
+ )
17
+ assert host.validate_media?
18
+ end
19
+
12
20
  test "#can_be_built? must be true when provision_method is bootdisk" do
13
21
  host = FactoryBot.build(:host, :managed,
14
22
  :provision_method => "bootdisk"
@@ -0,0 +1,34 @@
1
+ require 'test_plugin_helper'
2
+
3
+ module ForemanBootdisk
4
+ class RendererTest < ActiveSupport::TestCase
5
+ include ForemanBootdiskTestHelper
6
+
7
+ setup do
8
+ User.current = users(:admin)
9
+ setup_bootdisk
10
+ end
11
+
12
+ let(:renderer) { ForemanBootdisk::Renderer.new }
13
+
14
+ describe 'a generic template' do
15
+ test 'can be rendered' do
16
+ rendered_template = renderer.generic_template_render
17
+ assert_includes rendered_template, 'ifstat'
18
+ end
19
+
20
+ test 'does not include a host token' do
21
+ rendered_template = renderer.generic_template_render
22
+ assert_includes rendered_template, 'http://foreman.some.host.fqdn/unattended/iPXE?mac=${net0/mac}'
23
+ refute_includes rendered_template, 'token'
24
+ end
25
+ end
26
+
27
+ context 'with a subnet' do
28
+ let(:subnet) { FactoryBot.create(:subnet_ipv4) }
29
+ test 'renders a subnet template' do
30
+ assert_includes renderer.generic_template_render(subnet), 'ifstat'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_plugin_helper'
2
+
3
+ module ForemanBootdisk
4
+ module Scope
5
+ class BootdiskTest < ActiveSupport::TestCase
6
+ let(:host) { FactoryBot.build(:host, :managed) }
7
+ let(:source) { Foreman::Renderer::Source::String.new(content: 'Test') }
8
+ let(:scope) { ForemanBootdisk::Scope::Bootdisk.new(host: host, source: source) }
9
+
10
+ describe '#bootdisk_chain_url' do
11
+ test 'should render bootdisk chain url' do
12
+ assert_equal "http://foreman.some.host.fqdn/unattended/iPXE?mac=#{URI.encode_www_form_component(host.mac)}", scope.bootdisk_chain_url
13
+ end
14
+
15
+ test 'should render bootdisk chain url with custom mac' do
16
+ assert_equal "http://foreman.some.host.fqdn/unattended/iPXE?mac=00%3A11%3A22%3A33%3A44%3A55", scope.bootdisk_chain_url('00:11:22:33:44:55')
17
+ end
18
+ end
19
+
20
+ describe '#bootdisk_raise' do
21
+ test 'should raise a Foreman::Exception' do
22
+ assert_raise ::Foreman::Exception do
23
+ scope.bootdisk_raise('Some error.')
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ 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: 12.0.1
4
+ version: 13.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: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2018-10-04 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.
@@ -29,13 +29,13 @@ files:
29
29
  - app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb
30
30
  - app/controllers/foreman_bootdisk/disks_controller.rb
31
31
  - app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb
32
+ - app/lib/foreman_bootdisk/scope/bootdisk.rb
32
33
  - app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb
33
34
  - app/models/concerns/foreman_bootdisk/host_ext.rb
34
35
  - app/models/concerns/foreman_bootdisk/orchestration/compute.rb
35
36
  - app/models/setting/bootdisk.rb
36
37
  - app/services/foreman_bootdisk/iso_generator.rb
37
38
  - app/services/foreman_bootdisk/renderer.rb
38
- - app/services/foreman_bootdisk/renderer_methods.rb
39
39
  - app/views/foreman_bootdisk/disks/help.html.erb
40
40
  - app/views/foreman_bootdisk/generic_host.erb
41
41
  - app/views/foreman_bootdisk/host.erb
@@ -89,11 +89,14 @@ files:
89
89
  - test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb
90
90
  - test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb
91
91
  - test/functional/foreman_bootdisk/disks_controller_test.rb
92
+ - test/models/host/managed_test.rb
92
93
  - test/test_plugin_helper.rb
93
94
  - test/unit/access_permissions_test.rb
94
95
  - test/unit/concerns/compute_resources/vmware_test.rb
95
96
  - test/unit/concerns/host_test.rb
96
97
  - test/unit/concerns/orchestration/compute_test.rb
98
+ - test/unit/foreman_bootdisk/renderer_test.rb
99
+ - test/unit/foreman_bootdisk/scope/bootdisk_test.rb
97
100
  - test/unit/iso_generator_test.rb
98
101
  homepage: http://github.com/theforeman/foreman_bootdisk
99
102
  licenses:
@@ -1,27 +0,0 @@
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
-
14
- def bootdisk_raise(*args)
15
- raise ::Foreman::Exception.new(*args)
16
- end
17
- end
18
-
19
- def bootdisk_chain_url(mac = self.try(:mac), action = 'iPXE')
20
- self.class.format_bootdisk_chain_url(foreman_url(action), mac)
21
- end
22
-
23
- def bootdisk_raise(*args)
24
- self.class.bootdisk_raise(*args)
25
- end
26
- end
27
- end