foreman_bootdisk 16.1.0 → 17.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +1 -0
  3. data/README.md +9 -0
  4. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +5 -7
  5. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +9 -4
  6. data/app/controllers/foreman_bootdisk/disks_controller.rb +11 -10
  7. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +1 -1
  8. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +4 -1
  9. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk_efi.rb +15 -0
  10. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +10 -1
  11. data/app/models/concerns/foreman_bootdisk/host_ext.rb +3 -6
  12. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +28 -19
  13. data/app/models/setting/bootdisk.rb +4 -0
  14. data/app/services/foreman_bootdisk/iso_generator.rb +114 -54
  15. data/app/services/foreman_bootdisk/renderer.rb +36 -19
  16. data/app/views/foreman_bootdisk/generic_efi_host.erb +64 -0
  17. data/db/seeds.d/50-bootdisk_templates.rb +1 -0
  18. data/lib/foreman_bootdisk/engine.rb +1 -1
  19. data/lib/foreman_bootdisk/version.rb +1 -1
  20. data/lib/tasks/bootdisk.rake +10 -6
  21. data/locale/action_names.rb +5 -0
  22. data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  23. data/locale/ca/foreman_bootdisk.po +37 -4
  24. data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  25. data/locale/de/foreman_bootdisk.po +40 -7
  26. data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  27. data/locale/en/foreman_bootdisk.po +37 -4
  28. data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  29. data/locale/en_GB/foreman_bootdisk.po +38 -5
  30. data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  31. data/locale/es/foreman_bootdisk.po +40 -7
  32. data/locale/foreman_bootdisk.pot +87 -39
  33. data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  34. data/locale/fr/foreman_bootdisk.po +38 -5
  35. data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  36. data/locale/it/foreman_bootdisk.po +38 -5
  37. data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  38. data/locale/ja/foreman_bootdisk.po +38 -5
  39. data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  40. data/locale/ko/foreman_bootdisk.po +38 -5
  41. data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  42. data/locale/pt_BR/foreman_bootdisk.po +38 -5
  43. data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  44. data/locale/ru/foreman_bootdisk.po +38 -5
  45. data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  46. data/locale/sv_SE/foreman_bootdisk.po +38 -5
  47. data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  48. data/locale/zh_CN/foreman_bootdisk.po +38 -5
  49. data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  50. data/locale/zh_TW/foreman_bootdisk.po +38 -5
  51. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +51 -17
  52. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +23 -10
  53. data/test/functional/foreman_bootdisk/disks_controller_test.rb +65 -25
  54. data/test/test_plugin_helper.rb +21 -3
  55. data/test/unit/concerns/host_test.rb +1 -1
  56. data/test/unit/concerns/orchestration/compute_test.rb +32 -13
  57. data/test/unit/foreman_bootdisk/renderer_test.rb +1 -1
  58. data/test/unit/iso_generator_test.rb +6 -7
  59. metadata +19 -2
@@ -5,20 +5,33 @@ require 'test_plugin_helper'
5
5
  class ForemanBootdisk::Api::V2::SubnetDisksControllerTest < ActionController::TestCase
6
6
  include ForemanBootdiskTestHelper
7
7
  setup :setup_bootdisk
8
+ setup :setup_referer
9
+ setup :setup_org_loc
8
10
 
9
- describe '#subnet_host' do
10
- setup :setup_referer
11
- setup :setup_org_loc
12
- setup :setup_subnet
11
+ def perform_subnet_generate
12
+ tmp = create_tempfile
13
+ ForemanBootdisk::ISOGenerator.expects(:generate).yields(create_tempfile.path)
14
+ get :subnet, params: { id: @host.subnet.id }
15
+ assert_response :success
16
+ ensure
17
+ tmp.unlink
18
+ end
19
+
20
+ describe '#subnet_host with TFTP' do
21
+ setup :setup_subnet_with_tftp
22
+ setup :setup_host
23
+
24
+ test 'should generate subnet generic host image' do
25
+ perform_subnet_generate
26
+ end
27
+ end
28
+
29
+ describe '#subnet_host with TFTP and HTTPBOOT' do
30
+ setup :setup_subnet_with_tftp_httpboot_template
13
31
  setup :setup_host
14
32
 
15
33
  test 'should generate subnet generic host image' do
16
- ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(ipxe: regexp_matches(/disk generic host template/))).yields('temp ISO')
17
- ForemanBootdisk::Renderer.any_instance.stubs(:bootdisk_chain_url).yields('http://smart-proxy.lan')
18
- File.expects(:read).with('temp ISO').returns('ISO image')
19
- get :subnet, params: { id: @host.subnet.id }
20
- assert_response :success
21
- assert_equal 'ISO image', @response.body
34
+ perform_subnet_generate
22
35
  end
23
36
  end
24
37
  end
@@ -5,45 +5,85 @@ require 'test_plugin_helper'
5
5
  class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
6
6
  include ForemanBootdiskTestHelper
7
7
  setup :setup_bootdisk
8
+ setup :setup_referer
9
+ setup :setup_org_loc
8
10
 
9
- test 'should generate generic image' do
10
- ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(ipxe: regexp_matches(/disk generic host template/))).yields('temp ISO')
11
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
11
+ def perform_generic_generate
12
+ tmp = create_tempfile
13
+ ForemanBootdisk::ISOGenerator.expects(:generate).yields(create_tempfile.path)
12
14
  get :generic, session: set_session_user
13
15
  assert_response :success
14
- assert_equal 'ISO image', @response.body
16
+ ensure
17
+ tmp.unlink
15
18
  end
16
19
 
17
- describe '#host' do
18
- setup :setup_referer
19
- setup :setup_org_loc
20
- setup :setup_subnet
20
+ def perform_host_generate
21
+ tmp = create_tempfile
22
+ ForemanBootdisk::ISOGenerator.expects(:generate).yields(create_tempfile.path)
23
+ get :host, params: { id: @host.name }, session: set_session_user
24
+ assert_response :success
25
+ ensure
26
+ tmp.unlink
27
+ end
28
+
29
+ def perform_full_host_generate
30
+ tmp = create_tempfile
31
+ ForemanBootdisk::ISOGenerator.expects(:generate_full_host).yields(create_tempfile.path)
32
+ get :full_host, params: { id: @host.name }, session: set_session_user
33
+ assert_response :success
34
+ ensure
35
+ tmp.unlink
36
+ end
37
+
38
+ def perform_subnet_generate
39
+ tmp = create_tempfile
40
+ ForemanBootdisk::ISOGenerator.expects(:generate).yields(create_tempfile.path)
41
+ get :subnet, params: { id: @host.name }, session: set_session_user
42
+ assert_empty flash[:error]
43
+ assert_response :success
44
+ ensure
45
+ tmp.unlink
46
+ end
47
+
48
+ describe '#generic with TFTP' do
49
+ setup :setup_subnet_with_tftp
21
50
  setup :setup_host
22
51
 
52
+ test 'should generate generic image' do
53
+ perform_generic_generate
54
+ end
55
+
23
56
  test 'should generate host image' do
24
- ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(ipxe: regexp_matches(/disk host template/))).yields('temp ISO')
25
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
26
- get :host, params: { id: @host.name }, session: set_session_user
27
- assert_response :success
28
- assert_equal 'ISO image', @response.body
57
+ perform_host_generate
29
58
  end
30
59
 
31
60
  test 'should generate full host image' do
32
- ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields('temp ISO')
33
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
34
- get :full_host, params: { id: @host.name }, session: set_session_user
35
- assert_response :success
36
- assert_equal 'ISO image', @response.body
61
+ perform_full_host_generate
37
62
  end
38
63
 
39
64
  test 'should generate subnet image' do
40
- ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(ipxe: regexp_matches(/disk generic host template/))).yields('temp ISO')
41
- ForemanBootdisk::Renderer.any_instance.stubs(:bootdisk_chain_url).yields('http://smart-proxy.lan')
42
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
43
- get :subnet, params: { id: @host.name }, session: set_session_user
44
- assert_empty flash[:error]
45
- assert_response :success
46
- assert_equal 'ISO image', @response.body
65
+ perform_subnet_generate
66
+ end
67
+ end
68
+
69
+ describe '#subnet_host with TFTP and HTTPBOOT' do
70
+ setup :setup_subnet_with_tftp_httpboot_template
71
+ setup :setup_host
72
+
73
+ test 'should generate generic image' do
74
+ perform_generic_generate
75
+ end
76
+
77
+ test 'should generate host image' do
78
+ perform_host_generate
79
+ end
80
+
81
+ test 'should generate full host image' do
82
+ perform_full_host_generate
83
+ end
84
+
85
+ test 'should generate subnet image' do
86
+ perform_subnet_generate
47
87
  end
48
88
  end
49
89
 
@@ -5,15 +5,23 @@ require 'webmock/minitest'
5
5
  require 'webmock'
6
6
 
7
7
  module ForemanBootdiskTestHelper
8
+ def create_tempfile
9
+ file = Tempfile.new('bootdisk-test', '/tmp')
10
+ file.close
11
+ file
12
+ end
13
+
8
14
  def setup_bootdisk
15
+ ForemanBootdisk::Scope::Bootdisk.any_instance.stubs(:bootdisk_chain_url).returns('http://smart-proxy.example.com/unattended/iPXE?mac=')
9
16
  setup_routes
10
17
  setup_settings
11
18
  setup_templates
12
19
  end
13
20
 
21
+ # TODO remove me
14
22
  def setup_host_env
15
23
  setup_org_loc
16
- setup_subnet
24
+ setup_subnet_with_tftp
17
25
  setup_host
18
26
  end
19
27
 
@@ -39,7 +47,17 @@ module ForemanBootdiskTestHelper
39
47
  @loc = FactoryBot.create(:location)
40
48
  end
41
49
 
42
- def setup_subnet
50
+ def setup_subnet_with_tftp_httpboot_template
51
+ ProxyAPI::V2::Features.any_instance.stubs(:features).returns(:httpboot => { :settings => { :https_port => 1234 }, :state => 'running' }, :templates => {}, :tftp => {})
52
+ SmartProxy.any_instance.stubs(:httpboot_http_port).returns('8888')
53
+ SmartProxy.any_instance.stubs(:httpboot_https_port).returns('9999')
54
+
55
+ proxy = FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:tftp_feature), FactoryBot.create(:feature, :templates), FactoryBot.create(:feature, :httpboot)])
56
+ proxy.reload
57
+ setup_subnet_no_tftp.update! tftp: proxy, httpboot: proxy, template: proxy
58
+ end
59
+
60
+ def setup_subnet_with_tftp
43
61
  tftp_proxy = FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:tftp_feature)])
44
62
  setup_subnet_no_tftp.update! tftp: tftp_proxy
45
63
  end
@@ -49,6 +67,6 @@ module ForemanBootdiskTestHelper
49
67
  end
50
68
 
51
69
  def setup_host
52
- @host = FactoryBot.create(:host, :managed, subnet: @subnet, ip: @subnet.network.sub(/0$/, '4'), organization: @org, location: @loc)
70
+ @host = FactoryBot.create(:host, :managed, subnet: @subnet, ip: @subnet.network.sub(/0$/, '4'), organization: @org, location: @loc, build: true)
53
71
  end
54
72
  end
@@ -36,7 +36,7 @@ module ForemanBootdisk
36
36
  test 'host should not have bootdisk' do
37
37
  if unattended?
38
38
  h = FactoryBot.create(:host)
39
- assert_equal false, h.bootdisk?
39
+ assert_not(h.bootdisk?)
40
40
  end
41
41
  end
42
42
 
@@ -22,29 +22,48 @@ module ForemanBootdisk
22
22
  @host.send(:setAttachIsoImage)
23
23
  end
24
24
 
25
- test 'provisioning a host with provision method bootdisk should queue bootdisk tasks' do
25
+ test 'provisioning a host with provision method bootdisk should detach iso' do
26
+ @cr.expects(:iso_detach)
27
+ @host.send(:setDetachIsoImage)
28
+ end
29
+
30
+ test 'provisioning a new host with provision method bootdisk should queue bootdisk tasks' do
26
31
  @host.stubs(:compute?).returns(true)
32
+ @host.stubs(:build?).returns(true)
27
33
  @host.send(:queue_bootdisk_compute)
28
34
  tasks = @host.queue.all.map(&:name)
29
35
  assert_includes tasks, "Generating ISO image for #{@host.name}"
30
36
  assert_includes tasks, "Upload ISO image to datastore for #{@host.name}"
31
37
  assert_includes tasks, "Attach ISO image to CDROM drive for #{@host.name}"
38
+ assert_not_includes tasks, "Detach ISO image from CDROM drive for #{@host.name}"
32
39
  end
33
40
 
34
- test 'should rebuild bootdisk' do
35
- @host.expects(:bootdisk_generate_iso_image).returns(true)
36
- @host.expects(:bootdisk_upload_iso).returns(true)
37
- @host.expects(:bootdisk_attach_iso).returns(true)
38
- assert @host.rebuild_with_bootdisk
41
+ test 'rebuilding a host with provision method bootdisk should queue bootdisk tasks' do
42
+ @host.stubs(:compute?).returns(true)
43
+ old = stub()
44
+ old.stubs(:build?).returns(false)
45
+ @host.stubs(:old).returns(old)
46
+ @host.stubs(:build?).returns(true)
47
+ @host.send(:queue_bootdisk_compute)
48
+ tasks = @host.queue.all.map(&:name)
49
+ assert_includes tasks, "Generating ISO image for #{@host.name}"
50
+ assert_includes tasks, "Upload ISO image to datastore for #{@host.name}"
51
+ assert_includes tasks, "Attach ISO image to CDROM drive for #{@host.name}"
52
+ assert_not_includes tasks, "Detach ISO image from CDROM drive for #{@host.name}"
39
53
  end
40
54
 
41
- test 'should skip rebuild bootdisk' do
42
- host = FactoryBot.build(:host,
43
- compute_resource: @cr)
44
- host.expects(:bootdisk_generate_iso_image).never
45
- host.expects(:bootdisk_upload_iso).never
46
- host.expects(:bootdisk_attach_iso).never
47
- assert host.rebuild_with_bootdisk
55
+ test 'the iso should be detached when the host leaves build mode' do
56
+ @host.stubs(:compute?).returns(true)
57
+ old = stub()
58
+ old.stubs(:build?).returns(true)
59
+ @host.stubs(:old).returns(old)
60
+ @host.stubs(:build?).returns(false)
61
+ @host.send(:queue_bootdisk_compute)
62
+ tasks = @host.queue.all.map(&:name)
63
+ assert_not_includes tasks, "Generating ISO image for #{@host.name}"
64
+ assert_not_includes tasks, "Upload ISO image to datastore for #{@host.name}"
65
+ assert_not_includes tasks, "Attach ISO image to CDROM drive for #{@host.name}"
66
+ assert_includes tasks, "Detach ISO image from CDROM drive for #{@host.name}"
48
67
  end
49
68
  end
50
69
  end
@@ -21,7 +21,7 @@ module ForemanBootdisk
21
21
 
22
22
  test 'does not include a host token' do
23
23
  rendered_template = renderer.generic_template_render
24
- assert_includes rendered_template, 'http://foreman.some.host.fqdn/unattended/iPXE?mac=${net0/mac}'
24
+ assert_includes rendered_template, 'http://smart-proxy.example.com/unattended/iPXE?mac=${net0/mac}'
25
25
  assert_not_includes rendered_template, 'token'
26
26
  end
27
27
  end
@@ -11,10 +11,12 @@ module ForemanBootdisk
11
11
  let(:medium) { FactoryBot.create(:medium, name: 'Red Hat Enterprise Linux Atomic Mirror') }
12
12
  let(:operatingsystem) { FactoryBot.create(:ubuntu14_10, :with_archs, :with_ptables, media: [medium]) }
13
13
  let(:host) { FactoryBot.create(:host, :managed, operatingsystem: operatingsystem, build: true) }
14
- let(:template) { FactoryBot.create(:provisioning_template, template: 'Fake kernel line <%= @kernel %> - <%= @initrd %>') }
14
+ let(:pxelinux_template) { FactoryBot.create(:provisioning_template, template: 'Fake kernel line <%= @kernel %> - <%= @initrd %>') }
15
+ let(:pxegrub2_template) { FactoryBot.create(:provisioning_template, template: 'Fake kernel line <%= @kernel %> - <%= @initrd %>') }
15
16
 
16
17
  setup do
17
- host.stubs(:provisioning_template).with(kind: :PXELinux).returns(template)
18
+ host.stubs(:provisioning_template).with(kind: :PXELinux).returns(pxelinux_template)
19
+ host.stubs(:provisioning_template).with(kind: :PXEGrub2).returns(pxegrub2_template)
18
20
  end
19
21
 
20
22
  test 'fetch handles redirect' do
@@ -40,11 +42,8 @@ module ForemanBootdisk
40
42
  )
41
43
  initrd_url = urls[:initrd]
42
44
 
43
- ForemanBootdisk::ISOGenerator.expects(:generate).with({
44
- isolinux: "Fake kernel line #{kernel} - #{initrd}",
45
- files: { kernel => kernel_url,
46
- initrd => initrd_url }
47
- }, anything)
45
+ ForemanBootdisk::ISOGenerator.expects(:generate)
46
+ .with({ isolinux: "Fake kernel line #{kernel} - #{initrd}", grub: "Fake kernel line /#{kernel} - /#{initrd}", files: { kernel => kernel_url, initrd => initrd_url } }, anything)
48
47
 
49
48
  ForemanBootdisk::ISOGenerator.generate_full_host(host)
50
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: 16.1.0
4
+ version: 17.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop-performance
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,7 @@ files:
88
102
  - app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb
89
103
  - app/lib/foreman_bootdisk/scope/bootdisk.rb
90
104
  - app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb
105
+ - app/lib/foreman_bootdisk/scope/full_host_bootdisk_efi.rb
91
106
  - app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb
92
107
  - app/models/concerns/foreman_bootdisk/host_ext.rb
93
108
  - app/models/concerns/foreman_bootdisk/orchestration/compute.rb
@@ -95,6 +110,7 @@ files:
95
110
  - app/services/foreman_bootdisk/iso_generator.rb
96
111
  - app/services/foreman_bootdisk/renderer.rb
97
112
  - app/views/foreman_bootdisk/disks/help.html.erb
113
+ - app/views/foreman_bootdisk/generic_efi_host.erb
98
114
  - app/views/foreman_bootdisk/generic_host.erb
99
115
  - app/views/foreman_bootdisk/generic_static_host.erb
100
116
  - app/views/foreman_bootdisk/host.erb
@@ -114,6 +130,7 @@ files:
114
130
  - lib/foreman_bootdisk/version.rb
115
131
  - lib/tasks/bootdisk.rake
116
132
  - locale/Makefile
133
+ - locale/action_names.rb
117
134
  - locale/ca/LC_MESSAGES/foreman_bootdisk.mo
118
135
  - locale/ca/foreman_bootdisk.po
119
136
  - locale/de/LC_MESSAGES/foreman_bootdisk.mo