foreman_bootdisk 16.1.0 → 18.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yaml +19 -0
  3. data/.tx/config +1 -1
  4. data/AUTHORS +5 -0
  5. data/README.md +11 -3
  6. data/app/controllers/concerns/allowed_actions.rb +16 -0
  7. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +15 -8
  8. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +16 -4
  9. data/app/controllers/foreman_bootdisk/disks_controller.rb +29 -23
  10. data/app/controllers/foreman_bootdisk/subnet_disks_controller.rb +41 -0
  11. data/app/helpers/bootdisk_links_helper.rb +46 -0
  12. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +58 -44
  13. data/app/helpers/concerns/foreman_bootdisk/pretty_error.rb +13 -0
  14. data/app/helpers/concerns/foreman_bootdisk/subnets_helper_ext.rb +45 -0
  15. data/app/helpers/disk_helper.rb +8 -0
  16. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +28 -1
  17. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk_efi.rb +15 -0
  18. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +10 -1
  19. data/app/models/concerns/foreman_bootdisk/host_ext.rb +9 -6
  20. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +38 -22
  21. data/app/models/setting/bootdisk.rb +14 -1
  22. data/app/services/foreman_bootdisk/iso_generator.rb +134 -56
  23. data/app/services/foreman_bootdisk/renderer.rb +36 -19
  24. data/app/views/foreman_bootdisk/disks/help.html.erb +16 -4
  25. data/app/views/foreman_bootdisk/generic_efi_host.erb +68 -0
  26. data/app/views/foreman_bootdisk/host.erb +7 -0
  27. data/app/views/subnets/_bootdisk_action_buttons.erb +1 -0
  28. data/app/views/subnets/_bootdisk_title_buttons.erb +1 -0
  29. data/config/routes.rb +1 -1
  30. data/db/seeds.d/50-bootdisk_templates.rb +1 -0
  31. data/lib/foreman_bootdisk/engine.rb +12 -2
  32. data/lib/foreman_bootdisk/version.rb +1 -1
  33. data/lib/tasks/bootdisk.rake +10 -24
  34. data/locale/action_names.rb +5 -0
  35. data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  36. data/locale/ca/foreman_bootdisk.po +74 -11
  37. data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  38. data/locale/de/foreman_bootdisk.po +81 -17
  39. data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  40. data/locale/en/foreman_bootdisk.po +71 -8
  41. data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  42. data/locale/en_GB/foreman_bootdisk.po +75 -12
  43. data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  44. data/locale/es/foreman_bootdisk.po +88 -24
  45. data/locale/foreman_bootdisk.pot +167 -74
  46. data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  47. data/locale/fr/foreman_bootdisk.po +96 -32
  48. data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  49. data/locale/it/foreman_bootdisk.po +75 -12
  50. data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  51. data/locale/ja/foreman_bootdisk.po +86 -22
  52. data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  53. data/locale/ko/foreman_bootdisk.po +75 -12
  54. data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  55. data/locale/pt_BR/foreman_bootdisk.po +96 -33
  56. data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  57. data/locale/ru/foreman_bootdisk.po +75 -12
  58. data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  59. data/locale/sv_SE/foreman_bootdisk.po +75 -12
  60. data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  61. data/locale/zh_CN/foreman_bootdisk.po +129 -66
  62. data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  63. data/locale/zh_TW/foreman_bootdisk.po +75 -12
  64. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +51 -17
  65. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +23 -10
  66. data/test/functional/foreman_bootdisk/disks_controller_test.rb +60 -30
  67. data/test/functional/foreman_bootdisk/subnet_disks_controller_test.rb +51 -0
  68. data/test/test_plugin_helper.rb +21 -3
  69. data/test/unit/concerns/host_test.rb +1 -1
  70. data/test/unit/concerns/orchestration/compute_test.rb +32 -13
  71. data/test/unit/foreman_bootdisk/renderer_test.rb +1 -1
  72. data/test/unit/iso_generator_test.rb +6 -7
  73. metadata +21 -36
@@ -5,10 +5,10 @@
5
5
  # Translators:
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: foreman_bootdisk 16.1.0\n"
8
+ "Project-Id-Version: foreman_bootdisk 18.0.0\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
- "PO-Revision-Date: 2019-10-22 20:06+0000\n"
11
- "Last-Translator: Bryan Kearney <bryan.kearney@gmail.com>\n"
10
+ "PO-Revision-Date: 2021-09-24 07:25+0000\n"
11
+ "Last-Translator: Transifex Bot <>\n"
12
12
  "Language-Team: Chinese (Taiwan) (http://www.transifex.com/foreman/foreman/lang"
13
13
  "uage/zh_TW/)\n"
14
14
  "MIME-Version: 1.0\n"
@@ -17,6 +17,9 @@ msgstr ""
17
17
  "Language: zh_TW\n"
18
18
  "Plural-Forms: nplurals=1; plural=0;\n"
19
19
 
20
+ msgid "* - These bootdisk types were disabled, you can enable them in Administer - Settings."
21
+ msgstr ""
22
+
20
23
  msgid "A variant of the per-host image which contains the OS bootloader embedded inside the disk. This may be useful if chainloading fails on certain hardware, but has the downside that the image must be regenerated for any change in the OS, bootloader or PXELinux templates."
21
24
  msgstr "個別主機映像檔的變體,磁碟中嵌入了 OS 的開機載入程式。這對於在特定硬體上的 chainloading 失敗時特別有幫助,不過缺點就是若要對 OS、開機載入程式或 PXELinux 範本進行任何更改,映像檔就必須重新產生。"
22
25
 
@@ -26,6 +29,9 @@ msgstr "有子計畫的動作"
26
29
  msgid "All images are usable as either ISOs or as disk images, including being written to a USB disk with `dd`."
27
30
  msgstr "所有映像檔皆能作為 ISO 或是磁碟映像檔使用,包括以 `dd` 寫入一個 USB 磁碟中。"
28
31
 
32
+ msgid "Allowed bootdisk types"
33
+ msgstr ""
34
+
29
35
  msgid "Attach ISO image to CDROM drive for %s"
30
36
  msgstr ""
31
37
 
@@ -35,6 +41,9 @@ msgstr "上一步"
35
41
  msgid "Boot disk"
36
42
  msgstr "開機磁碟"
37
43
 
44
+ msgid "Boot disk Help"
45
+ msgstr ""
46
+
38
47
  msgid "Boot disk based"
39
48
  msgstr ""
40
49
 
@@ -53,6 +62,12 @@ msgstr ""
53
62
  msgid "Command to generate ISO image, use genisoimage or mkisofs"
54
63
  msgstr "請使用 genisoimage 或是 mkisofs 來作為產生 ISO 映像檔的指令"
55
64
 
65
+ msgid "Creating new image failed, install truncate utility"
66
+ msgstr ""
67
+
68
+ msgid "Detach ISO image from CDROM drive for %s"
69
+ msgstr ""
70
+
56
71
  msgid "Download generic image"
57
72
  msgstr "下載泛型映像檔"
58
73
 
@@ -62,9 +77,21 @@ msgstr "下載主機映像檔"
62
77
  msgid "Download subnet generic image"
63
78
  msgstr "下載子網路泛型映像檔"
64
79
 
80
+ msgid "Ensure %{file} is readable (or update \"Grub2 directory\" setting)"
81
+ msgstr ""
82
+
65
83
  msgid "Failed to attach ISO image to CDROM drive of instance %{name}: %{message}"
66
84
  msgstr ""
67
85
 
86
+ msgid "Failed to create a directory within the ESP image"
87
+ msgstr ""
88
+
89
+ msgid "Failed to detach ISO image from CDROM drive of instance %{name}: %{message}"
90
+ msgstr ""
91
+
92
+ msgid "Failed to format the ESP image via mkfs.msdos"
93
+ msgstr ""
94
+
68
95
  msgid "Failed to generate ISO image for instance %{name}: %{message}"
69
96
  msgstr ""
70
97
 
@@ -83,17 +110,26 @@ msgstr "完整的主機映像檔"
83
110
  msgid "Generating ISO image for %s"
84
111
  msgstr ""
85
112
 
113
+ msgid "Generic Grub2 EFI image template"
114
+ msgstr ""
115
+
86
116
  msgid "Generic image"
87
117
  msgstr "泛型映像檔"
88
118
 
89
119
  msgid "Generic image template"
90
120
  msgstr ""
91
121
 
122
+ msgid "Generic images"
123
+ msgstr ""
124
+
92
125
  msgid "Generic images are a reusable disk image that works for any host registered in Foreman. It requires a basic DHCP and DNS service to function and contact the server, but does not require DHCP reservations or static IP addresses."
93
126
  msgstr "泛型映像檔是個可重複使用的磁碟映像檔,並且可使用於任何向 Foreman 註冊過的主機上。它需要一項基本的 DHCP 和 DNS 服務才能運作和聯絡伺服器,不過並不需要 DHCP 預留或靜態 IP 位址。"
94
127
 
95
- msgid "Help"
96
- msgstr "協助"
128
+ msgid "Grub2 directory"
129
+ msgstr ""
130
+
131
+ msgid "Grub2 template to use for generic EFI host boot disks"
132
+ msgstr ""
97
133
 
98
134
  msgid "Host '%s' image"
99
135
  msgstr "主機「%s」映像檔"
@@ -119,17 +155,26 @@ msgstr "主機映像檔"
119
155
  msgid "Host image template"
120
156
  msgstr ""
121
157
 
158
+ msgid "Host images"
159
+ msgstr ""
160
+
161
+ msgid "Host is not in build mode"
162
+ msgstr ""
163
+
122
164
  msgid "Host is not in build mode, so the template cannot be rendered"
123
165
  msgstr "主機不在組建模式下,因此無法編寫範本"
124
166
 
167
+ msgid "Host is not in build mode."
168
+ msgstr ""
169
+
125
170
  msgid "ISO build failed"
126
171
  msgstr "建立 ISO 失敗"
127
172
 
128
173
  msgid "ISO generation command"
129
174
  msgstr ""
130
175
 
131
- msgid "ISO hybrid conversion failed"
132
- msgstr "ISO 混合式轉換失敗"
176
+ msgid "ISO hybrid conversion failed: %s"
177
+ msgstr ""
133
178
 
134
179
  msgid "ISOLINUX directory"
135
180
  msgstr ""
@@ -146,9 +191,15 @@ msgstr ""
146
191
  msgid "Installation media files will be cached for full host images"
147
192
  msgstr "安裝媒介檔案將會被快取以作為完整的主機映像檔"
148
193
 
194
+ msgid "List of allowed bootdisk types, remove type to disable it"
195
+ msgstr ""
196
+
149
197
  msgid "Once chainloaded, the OS bootloader and installer are downloaded directly from the installation media configured in Foreman, and the provisioning script (kickstart/preseed) is downloaded from Foreman."
150
198
  msgstr "在 chainload 之後,OS 開機載入程式和安裝程式將會直接從 Foreman 中所配置的安裝媒介下載,而佈建 script(kickstart/preseed)則會由 Foreman 下載。"
151
199
 
200
+ msgid "Path to directory containing grubx64.efi and shimx64.efi"
201
+ msgstr ""
202
+
152
203
  msgid "Path to directory containing iPXE images"
153
204
  msgstr "包含 iPXE 映像檔的目錄之路徑"
154
205
 
@@ -182,34 +233,46 @@ msgstr "子網路「%s」泛型映像檔"
182
233
  msgid "Subnet boot disks"
183
234
  msgstr "子網路開機磁碟"
184
235
 
236
+ msgid "Subnet generic image"
237
+ msgstr ""
238
+
185
239
  msgid "Subnet image"
186
240
  msgstr "子網路映像檔"
187
241
 
188
242
  msgid "Subnet images are similar to generic images, but chain-loading is done via the TFTP Smart Proxy assigned to the Subnet of the host. The smart proxy must have the \"Templates\" module enabled and configured."
189
243
  msgstr "子網路映像檔跟泛型映像檔類似,但連鎖載入(chain-loading)是透過 TFTP 智慧型代理指定至主機的子網路。智慧型代理必須啟用並配置了「模版」(Templates)模組。"
190
244
 
191
- msgid "Subnet is not assigned to the host %s"
192
- msgstr "子網路並未指定給主機 %s"
193
-
194
245
  msgid "TFTP feature not enabled for subnet %s"
195
246
  msgstr "TFTP 功能並未啟動給子網路 %s 使用"
196
247
 
197
248
  msgid "The OS install continues using the installation media configured in Foreman, and it will typically configure static networking, depending on how the OS iPXE template is configured."
198
249
  msgstr "OS 安裝程序會繼續使用配置於 Foreman 中的安裝媒介,並且它一般會根據 OS iPXE 範本的配置方法來配置靜態網路。"
199
250
 
251
+ msgid "These images are more generic than previous images. You can find them at subnet index page."
252
+ msgstr ""
253
+
254
+ msgid "These images are used for host. You can find them at host detail page."
255
+ msgstr ""
256
+
200
257
  msgid "This image is generic for all hosts with a provisioning NIC on that subnet."
201
258
  msgstr "這映像檔對在該子網路上配有網路卡的所有主機來說,是通用的。"
202
259
 
260
+ msgid "This type of bootdisk is not allowed. Please contact administrator."
261
+ msgstr ""
262
+
203
263
  msgid "True for full, false for basic reusable image"
204
264
  msgstr "「true」代表完整,「false」則代表可重複使用的基本映像檔"
205
265
 
206
266
  msgid "Unable to find template specified by %s setting"
207
267
  msgstr "找不到 %s 設定所指定的範本"
208
268
 
209
- msgid "Unable to generate disk PXELinux template: %s"
269
+ msgid "Unable to generate disk %{kind} template: %{error}"
270
+ msgstr ""
271
+
272
+ msgid "Unable to generate disk template, %{kind} template not found."
210
273
  msgstr ""
211
274
 
212
- msgid "Unable to generate disk template, PXELinux template not found."
275
+ msgid "Unable to mcopy %{file}"
213
276
  msgstr ""
214
277
 
215
278
  msgid "Upload ISO image to datastore for %s"
@@ -5,33 +5,67 @@ require 'test_plugin_helper'
5
5
  class ForemanBootdisk::Api::V2::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
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_host_env
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 }
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 :host, params: { id: @host.name, full: true }
33
+ assert_response :success
34
+ ensure
35
+ tmp.unlink
36
+ end
37
+
38
+ describe '#generic with TFTP' do
39
+ setup :setup_subnet_with_tftp
40
+ setup :setup_host
41
+
42
+ test 'should generate generic image' do
43
+ perform_generic_generate
44
+ end
45
+
46
+ test 'should generate host image' do
47
+ perform_host_generate
48
+ end
49
+
50
+ test 'should generate full host image' do
51
+ perform_full_host_generate
52
+ end
53
+ end
54
+
55
+ describe '#subnet_host with TFTP and HTTPBOOT' do
56
+ setup :setup_subnet_with_tftp_httpboot_template
57
+ setup :setup_host
58
+
59
+ test 'should generate generic image' do
60
+ perform_generic_generate
61
+ end
20
62
 
21
63
  test 'should generate host image' do
22
- ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(ipxe: regexp_matches(/disk host template/))).yields('temp ISO')
23
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
24
- get :host, params: { id: @host.name }
25
- assert_response :success
26
- assert_equal 'ISO image', @response.body
64
+ perform_host_generate
27
65
  end
28
66
 
29
67
  test 'should generate full host image' do
30
- ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields('temp ISO')
31
- @controller.expects(:read_file).with('temp ISO').returns('ISO image')
32
- get :host, params: { id: @host.name, full: true }
33
- assert_response :success
34
- assert_equal 'ISO image', @response.body
68
+ perform_full_host_generate
35
69
  end
36
70
  end
37
71
 
@@ -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,67 @@ 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
+ describe '#generic with TFTP' do
39
+ setup :setup_subnet_with_tftp
21
40
  setup :setup_host
22
41
 
42
+ test 'should generate generic image' do
43
+ perform_generic_generate
44
+ end
45
+
23
46
  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
47
+ perform_host_generate
29
48
  end
30
49
 
31
50
  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
51
+ perform_full_host_generate
37
52
  end
53
+ end
38
54
 
39
- 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
55
+ describe '#subnet_host with TFTP and HTTPBOOT' do
56
+ setup :setup_subnet_with_tftp_httpboot_template
57
+ setup :setup_host
58
+
59
+ test 'should generate generic image' do
60
+ perform_generic_generate
61
+ end
62
+
63
+ test 'should generate host image' do
64
+ perform_host_generate
65
+ end
66
+
67
+ test 'should generate full host image' do
68
+ perform_full_host_generate
47
69
  end
48
70
  end
49
71
 
@@ -53,10 +75,18 @@ class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
53
75
  setup :setup_subnet_no_tftp
54
76
  setup :setup_host
55
77
 
56
- test 'should not generate subnet image' do
57
- get :subnet, params: { id: @host.name }, session: set_session_user
58
- assert_match(/Failed.*: TFTP feature not enabled/, flash[:error])
59
- assert_response :redirect
78
+ test 'should prolong token for host image' do
79
+ Setting[:token_duration] = 60
80
+ @host.set_token
81
+ past = Time.now
82
+ assert @host.token.expires > past
83
+ travel_to(past + 2.hours)
84
+ assert @host.token_expired?
85
+
86
+ perform_full_host_generate
87
+
88
+ assert_equal @host.token_expired?, true
89
+ assert @host.token.expires > past
60
90
  end
61
91
  end
62
92
 
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ class ForemanBootdisk::SubnetDisksControllerTest < ActionController::TestCase
6
+ include ForemanBootdiskTestHelper
7
+ setup :setup_bootdisk
8
+ setup :setup_referer
9
+ setup :setup_org_loc
10
+
11
+ def perform_subnet_generate
12
+ tmp = create_tempfile
13
+ ForemanBootdisk::ISOGenerator.expects(:generate).yields(create_tempfile.path)
14
+ get :subnet, params: { id: @subnet.id }, session: set_session_user
15
+ assert_empty flash[:error]
16
+ assert_response :success
17
+ ensure
18
+ tmp.unlink
19
+ end
20
+
21
+ describe '#generic with TFTP' do
22
+ setup :setup_subnet_with_tftp
23
+ setup :setup_host
24
+
25
+ test 'should generate subnet image' do
26
+ perform_subnet_generate
27
+ end
28
+ end
29
+
30
+ describe '#subnet_host with TFTP and HTTPBOOT' do
31
+ setup :setup_subnet_with_tftp_httpboot_template
32
+ setup :setup_host
33
+
34
+ test 'should generate subnet image' do
35
+ perform_subnet_generate
36
+ end
37
+ end
38
+
39
+ describe '#host without tftp' do
40
+ setup :setup_referer
41
+ setup :setup_org_loc
42
+ setup :setup_subnet_no_tftp
43
+ setup :setup_host
44
+
45
+ test 'should not generate subnet image' do
46
+ get :subnet, params: { id: @subnet.id }, session: set_session_user
47
+ assert_match(/Failed.*: TFTP feature not enabled/, flash[:error])
48
+ assert_response :redirect
49
+ end
50
+ end
51
+ end
@@ -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