foreman_bootdisk 13.0.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/README.md +3 -2
  4. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +11 -9
  5. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +37 -31
  6. data/app/controllers/foreman_bootdisk/disks_controller.rb +20 -19
  7. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +86 -45
  8. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +2 -0
  9. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb +15 -0
  10. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +4 -2
  11. data/app/models/concerns/foreman_bootdisk/host_ext.rb +43 -31
  12. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +14 -10
  13. data/app/models/setting/bootdisk.rb +28 -23
  14. data/app/services/foreman_bootdisk/iso_generator.rb +127 -104
  15. data/app/services/foreman_bootdisk/renderer.rb +16 -13
  16. data/config/routes.rb +15 -13
  17. data/config/routes/mount_engine.rb +3 -1
  18. data/db/migrate/20130914211030_create_host_bootdisk_template.rb +4 -4
  19. data/db/migrate/20130915104500_edit_host_bootdisk_template_multinic.rb +4 -4
  20. data/db/migrate/20130915133321_create_kickstart_bootdisk_template.rb +4 -4
  21. data/db/migrate/20130915201457_create_generic_host_bootdisk_template.rb +4 -4
  22. data/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +4 -4
  23. data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +16 -14
  24. data/db/migrate/20171009225200_remove_duplicate_bootdisk_templates.rb +4 -2
  25. data/db/seeds.d/50-bootdisk_templates.rb +24 -22
  26. data/lib/foreman_bootdisk.rb +2 -0
  27. data/lib/foreman_bootdisk/engine.rb +22 -33
  28. data/lib/foreman_bootdisk/version.rb +3 -1
  29. data/lib/tasks/bootdisk.rake +34 -17
  30. data/locale/gemspec.rb +3 -1
  31. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +35 -33
  32. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +9 -7
  33. data/test/functional/foreman_bootdisk/disks_controller_test.rb +27 -25
  34. data/test/models/host/managed_test.rb +17 -13
  35. data/test/test_plugin_helper.rb +9 -7
  36. data/test/unit/access_permissions_test.rb +2 -0
  37. data/test/unit/concerns/compute_resources/vmware_test.rb +67 -63
  38. data/test/unit/concerns/host_test.rb +54 -54
  39. data/test/unit/concerns/orchestration/compute_test.rb +41 -39
  40. data/test/unit/foreman_bootdisk/renderer_test.rb +3 -1
  41. data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +3 -1
  42. data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +30 -0
  43. data/test/unit/iso_generator_test.rb +57 -40
  44. metadata +19 -3
@@ -1,73 +1,73 @@
1
- require 'test_plugin_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- class ForemanBootdisk::HostTest < ActiveSupport::TestCase
4
- test "#bootdisk_build? must be true when provision_method is bootdisk" do
5
- host = FactoryBot.build(:host, :managed)
6
- host.provision_method = 'bootdisk'
7
- assert host.bootdisk_build?
8
- refute host.image_build?
9
- refute host.pxe_build?
10
- end
3
+ require 'test_plugin_helper'
11
4
 
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
5
+ module ForemanBootdisk
6
+ class HostTest < ActiveSupport::TestCase
7
+ test '#bootdisk_build? must be true when provision_method is bootdisk' do
8
+ host = FactoryBot.build(:host, :managed)
9
+ host.provision_method = 'bootdisk'
10
+ assert host.bootdisk_build?
11
+ assert_not host.image_build?
12
+ assert_not host.pxe_build?
13
+ end
19
14
 
20
- test "#can_be_built? must be true when provision_method is bootdisk" do
21
- host = FactoryBot.build(:host, :managed,
22
- :provision_method => "bootdisk"
23
- )
24
- assert host.can_be_built?
25
- end
15
+ test '#validate_media? must be true when provision_method is bootdisk' do
16
+ host = FactoryBot.build(:host, :managed,
17
+ provision_method: 'bootdisk',
18
+ build: true)
19
+ assert host.validate_media?
20
+ end
26
21
 
22
+ test '#can_be_built? must be true when provision_method is bootdisk' do
23
+ host = FactoryBot.build(:host, :managed,
24
+ provision_method: 'bootdisk')
25
+ assert host.can_be_built?
26
+ end
27
27
 
28
- test "host should have bootdisk" do
29
- if unattended?
30
- h = FactoryBot.build(:host, :managed,
31
- :provision_method => "bootdisk"
32
- )
33
- assert h.bootdisk?
28
+ test 'host should have bootdisk' do
29
+ if unattended?
30
+ h = FactoryBot.build(:host, :managed,
31
+ provision_method: 'bootdisk')
32
+ assert h.bootdisk?
33
+ end
34
34
  end
35
- end
36
35
 
37
- test "host should not have bootdisk" do
38
- if unattended?
39
- h = FactoryBot.create(:host)
40
- assert_equal false, h.bootdisk?
36
+ test 'host should not have bootdisk' do
37
+ if unattended?
38
+ h = FactoryBot.create(:host)
39
+ assert_equal false, h.bootdisk?
40
+ end
41
41
  end
42
- end
43
42
 
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 = FactoryBot.build(:host, :managed, :architecture => architecture)
43
+ context '#bootdisk_downloadable?' do
44
+ test 'should be true for 64 bit architecture' do
45
+ architecture = Architecture.where(name: 'x86_64').first
46
+ host = FactoryBot.build(:host, :managed, architecture: architecture)
48
47
 
49
- assert host.bootdisk_downloadable?
50
- end
48
+ assert host.bootdisk_downloadable?
49
+ end
51
50
 
52
- test "should be true for 32 bit architecture" do
53
- architecture = FactoryBot.create(:architecture, :name => 'i386')
54
- host = FactoryBot.build(:host, :managed, :architecture => architecture)
51
+ test 'should be true for 32 bit architecture' do
52
+ architecture = FactoryBot.create(:architecture, name: 'i386')
53
+ host = FactoryBot.build(:host, :managed, architecture: architecture)
55
54
 
56
- assert host.bootdisk_downloadable?
57
- end
55
+ assert host.bootdisk_downloadable?
56
+ end
58
57
 
59
- test "should be false for non-intel architecture" do
60
- architecture = Architecture.where(:name => 's390').first
61
- host = FactoryBot.build(:host, :managed, :architecture => architecture)
58
+ test 'should be false for non-intel architecture' do
59
+ architecture = Architecture.where(name: 's390').first
60
+ host = FactoryBot.build(:host, :managed, architecture: architecture)
62
61
 
63
- assert_not host.bootdisk_downloadable?
64
- end
62
+ assert_not host.bootdisk_downloadable?
63
+ end
65
64
 
66
- test 'should be true if architecture is absent' do
67
- host = FactoryBot.build(:host, :managed, :architecture => nil)
65
+ test 'should be true if architecture is absent' do
66
+ host = FactoryBot.build(:host, :managed, architecture: nil)
68
67
 
69
- assert_nil host.architecture
70
- assert host.bootdisk_downloadable?
68
+ assert_nil host.architecture
69
+ assert host.bootdisk_downloadable?
70
+ end
71
71
  end
72
72
  end
73
73
  end
@@ -1,48 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
- class ForemanBootdisk::OrchestrationComputeTest < ActiveSupport::TestCase
4
- setup do
5
- disable_orchestration
6
- @cr = FactoryBot.build(:vmware_cr)
7
- @host = FactoryBot.build(:host, :managed,
8
- :compute_resource => @cr,
9
- :provision_method => "bootdisk",
10
- )
11
- end
5
+ module ForemanBootdisk
6
+ class OrchestrationComputeTest < ActiveSupport::TestCase
7
+ setup do
8
+ disable_orchestration
9
+ @cr = FactoryBot.build(:vmware_cr)
10
+ @host = FactoryBot.build(:host, :managed,
11
+ compute_resource: @cr,
12
+ provision_method: 'bootdisk')
13
+ end
12
14
 
13
- test "provisioning a host with provision method bootdisk should upload iso" do
14
- @cr.expects(:iso_upload)
15
- @host.send(:setIsoImage)
16
- end
15
+ test 'provisioning a host with provision method bootdisk should upload iso' do
16
+ @cr.expects(:iso_upload)
17
+ @host.send(:setIsoImage)
18
+ end
17
19
 
18
- test "provisioning a host with provision method bootdisk should attach iso" do
19
- @cr.expects(:iso_attach)
20
- @host.send(:setAttachIsoImage)
21
- end
20
+ test 'provisioning a host with provision method bootdisk should attach iso' do
21
+ @cr.expects(:iso_attach)
22
+ @host.send(:setAttachIsoImage)
23
+ end
22
24
 
23
- test "provisioning a host with provision method bootdisk should queue bootdisk tasks" do
24
- @host.stubs(:compute?).returns(true)
25
- @host.send(:queue_bootdisk_compute)
26
- tasks = @host.queue.all.map { |t| t.name }
27
- assert_includes tasks, "Generating ISO image for #{@host.name}"
28
- assert_includes tasks, "Upload ISO image to datastore for #{@host.name}"
29
- assert_includes tasks, "Attach ISO image to CDROM drive for #{@host.name}"
30
- end
25
+ test 'provisioning a host with provision method bootdisk should queue bootdisk tasks' do
26
+ @host.stubs(:compute?).returns(true)
27
+ @host.send(:queue_bootdisk_compute)
28
+ tasks = @host.queue.all.map(&:name)
29
+ assert_includes tasks, "Generating ISO image for #{@host.name}"
30
+ assert_includes tasks, "Upload ISO image to datastore for #{@host.name}"
31
+ assert_includes tasks, "Attach ISO image to CDROM drive for #{@host.name}"
32
+ end
31
33
 
32
- test "should rebuild bootdisk" do
33
- @host.expects(:bootdisk_generate_iso_image).returns(true)
34
- @host.expects(:bootdisk_upload_iso).returns(true)
35
- @host.expects(:bootdisk_attach_iso).returns(true)
36
- assert @host.rebuild_with_bootdisk
37
- end
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
39
+ end
38
40
 
39
- test "should skip rebuild bootdisk" do
40
- host = FactoryBot.build(:host,
41
- :compute_resource => @cr
42
- )
43
- host.expects(:bootdisk_generate_iso_image).never
44
- host.expects(:bootdisk_upload_iso).never
45
- host.expects(:bootdisk_attach_iso).never
46
- assert host.rebuild_with_bootdisk
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
48
+ end
47
49
  end
48
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanBootdisk
@@ -20,7 +22,7 @@ module ForemanBootdisk
20
22
  test 'does not include a host token' do
21
23
  rendered_template = renderer.generic_template_render
22
24
  assert_includes rendered_template, 'http://foreman.some.host.fqdn/unattended/iPXE?mac=${net0/mac}'
23
- refute_includes rendered_template, 'token'
25
+ assert_not_includes rendered_template, 'token'
24
26
  end
25
27
  end
26
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanBootdisk
@@ -13,7 +15,7 @@ module ForemanBootdisk
13
15
  end
14
16
 
15
17
  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')
18
+ 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
19
  end
18
20
  end
19
21
 
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module ForemanBootdisk
6
+ module Scope
7
+ class BootdiskTest < ActiveSupport::TestCase
8
+ let(:operatingsystem) { FactoryBot.create(:ubuntu14_10, :with_media, :with_archs) }
9
+ let(:host) { FactoryBot.build(:host, :managed, operatingsystem: operatingsystem) }
10
+ let(:source) { Foreman::Renderer::Source::String.new(content: 'Test') }
11
+ let(:scope) { ForemanBootdisk::Scope::FullHostBootdisk.new(host: host, source: source) }
12
+
13
+ setup do
14
+ MediumProviders::Default.any_instance.stubs(:unique_id).returns('MyMedium01-ZYHBD6OPET')
15
+ end
16
+
17
+ describe '@kernel' do
18
+ test 'should match filename on bootdisk' do
19
+ assert_equal 'BOOT/MYMEDIUM01_ZYHBD6OPET_LINUX', scope.instance_variable_get('@kernel')
20
+ end
21
+ end
22
+
23
+ describe '@initrd' do
24
+ test 'should match filename on bootdisk' do
25
+ assert_equal 'BOOT/EDIUM01_ZYHBD6OPET_INITRD_GZ', scope.instance_variable_get('@initrd')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,48 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
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
5
+ module ForemanBootdisk
6
+ class IsoGeneratorTest < ActiveSupport::TestCase
7
+ include ForemanBootdiskTestHelper
8
+ setup :setup_bootdisk
9
9
 
10
- setup do
11
- @host.build = true
12
- end
10
+ describe '#generate_full_host' do
11
+ let(:medium) { FactoryBot.create(:medium, name: 'Red Hat Enterprise Linux Atomic Mirror') }
12
+ let(:operatingsystem) { FactoryBot.create(:ubuntu14_10, :with_archs, :with_ptables, media: [medium]) }
13
+ let(:host) { FactoryBot.create(:host, :managed, operatingsystem: operatingsystem, build: true) }
14
+ let(:template) { FactoryBot.create(:provisioning_template, template: 'Fake kernel line <%= @kernel %> - <%= @initrd %>') }
13
15
 
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
16
+ setup do
17
+ host.expects(:provisioning_template).with(kind: :PXELinux).returns(template)
18
+ end
27
19
 
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
20
+ test 'generate_full_host creates with ISO-compatible file names' do
21
+ urls = host.operatingsystem.boot_file_sources(host.medium_provider)
22
+
23
+ kernel = ForemanBootdisk::ISOGenerator.iso9660_filename(
24
+ host.operatingsystem.kernel(host.medium_provider)
25
+ )
26
+ kernel_url = urls[:kernel]
27
+
28
+ initrd = ForemanBootdisk::ISOGenerator.iso9660_filename(
29
+ host.operatingsystem.initrd(host.medium_provider)
30
+ )
31
+ initrd_url = urls[:initrd]
32
+
33
+ ForemanBootdisk::ISOGenerator.expects(:generate).with({
34
+ isolinux: "Fake kernel line #{kernel} - #{initrd}",
35
+ files: { kernel => kernel_url,
36
+ initrd => initrd_url }
37
+ }, anything)
38
+
39
+ ForemanBootdisk::ISOGenerator.generate_full_host(host)
40
+ end
41
+ end
42
+
43
+ describe '#generate' do
44
+ test 'generates an iso image' do
45
+ ForemanBootdisk::ISOGenerator.expects(:system).with(
46
+ regexp_matches(/genisoimage -o .*output.iso -iso-level 2 -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .*build/)
47
+ ).returns(true)
48
+ ForemanBootdisk::ISOGenerator.expects(:system).with('isohybrid', anything).returns(true)
49
+ ForemanBootdisk::ISOGenerator.generate do |iso|
50
+ assert_not_nil iso
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#iso9660_filename' do
56
+ test 'converts path to iso9660' do
57
+ assert_equal 'BOOT/SOME_FILE_N_A_M_E123_', ForemanBootdisk::ISOGenerator.iso9660_filename('boot/some-File-n_a_m_e123Ä')
58
+ end
41
59
 
42
- test "full host image generation generates via PXELinux type" do
43
- @host.expects(:generate_pxe_template).with(:PXELinux).returns("Template")
44
- @host.operatingsystem.expects(:pxe_files).returns([])
45
- ForemanBootdisk::ISOGenerator.expects(:generate).with({:isolinux => "Template", :files => []}, anything)
46
- ForemanBootdisk::ISOGenerator.generate_full_host(@host)
60
+ test 'shortens long filenames' do
61
+ assert_equal 'BOOT/RPRISELINUXATOMIC_7_3_X86_64', ForemanBootdisk::ISOGenerator.iso9660_filename('boot/RedHatEnterpriseLinuxAtomic-7.3-x86_64')
62
+ end
63
+ end
47
64
  end
48
65
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_bootdisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.0
4
+ version: 14.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: 2018-10-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Plugin for Foreman that creates iPXE-based boot disks to provision hosts
14
28
  without the need for PXE infrastructure.
15
29
  email: dcleal@redhat.com
@@ -30,6 +44,7 @@ files:
30
44
  - app/controllers/foreman_bootdisk/disks_controller.rb
31
45
  - app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb
32
46
  - app/lib/foreman_bootdisk/scope/bootdisk.rb
47
+ - app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb
33
48
  - app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb
34
49
  - app/models/concerns/foreman_bootdisk/host_ext.rb
35
50
  - app/models/concerns/foreman_bootdisk/orchestration/compute.rb
@@ -97,6 +112,7 @@ files:
97
112
  - test/unit/concerns/orchestration/compute_test.rb
98
113
  - test/unit/foreman_bootdisk/renderer_test.rb
99
114
  - test/unit/foreman_bootdisk/scope/bootdisk_test.rb
115
+ - test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb
100
116
  - test/unit/iso_generator_test.rb
101
117
  homepage: http://github.com/theforeman/foreman_bootdisk
102
118
  licenses: