foreman_bootdisk 13.0.0 → 16.1.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 +4 -4
- data/AUTHORS +29 -0
- data/CHANGES.md +4 -0
- data/README.md +19 -2
- data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +11 -9
- data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +37 -31
- data/app/controllers/foreman_bootdisk/disks_controller.rb +20 -19
- data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +86 -45
- data/app/lib/foreman_bootdisk/scope/bootdisk.rb +2 -0
- data/app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb +15 -0
- data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +4 -2
- data/app/models/concerns/foreman_bootdisk/host_ext.rb +42 -30
- data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +14 -10
- data/app/models/setting/bootdisk.rb +21 -23
- data/app/services/foreman_bootdisk/iso_generator.rb +144 -104
- data/app/services/foreman_bootdisk/renderer.rb +17 -13
- data/app/views/foreman_bootdisk/generic_static_host.erb +34 -0
- data/app/views/foreman_bootdisk/host.erb +27 -11
- data/config/routes.rb +15 -13
- data/config/routes/mount_engine.rb +3 -1
- data/db/migrate/20130914211030_create_host_bootdisk_template.rb +4 -4
- data/db/migrate/20130915104500_edit_host_bootdisk_template_multinic.rb +4 -4
- data/db/migrate/20130915133321_create_kickstart_bootdisk_template.rb +4 -4
- data/db/migrate/20130915201457_create_generic_host_bootdisk_template.rb +4 -4
- data/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +4 -4
- data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +16 -14
- data/db/migrate/20171009225200_remove_duplicate_bootdisk_templates.rb +4 -2
- data/db/seeds.d/50-bootdisk_templates.rb +21 -36
- data/lib/foreman_bootdisk.rb +2 -0
- data/lib/foreman_bootdisk/engine.rb +26 -37
- data/lib/foreman_bootdisk/version.rb +3 -1
- data/lib/tasks/bootdisk.rake +34 -17
- data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/ca/foreman_bootdisk.po +31 -15
- data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/de/foreman_bootdisk.po +39 -21
- data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/en/foreman_bootdisk.po +24 -9
- data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/en_GB/foreman_bootdisk.po +30 -15
- data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/es/foreman_bootdisk.po +48 -33
- data/locale/foreman_bootdisk.pot +80 -52
- data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/fr/foreman_bootdisk.po +30 -15
- data/locale/gemspec.rb +3 -1
- data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/it/foreman_bootdisk.po +28 -13
- data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/ja/foreman_bootdisk.po +29 -14
- data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/ko/foreman_bootdisk.po +28 -13
- data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/pt_BR/foreman_bootdisk.po +42 -26
- data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/ru/foreman_bootdisk.po +28 -13
- data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/sv_SE/foreman_bootdisk.po +26 -11
- data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/zh_CN/foreman_bootdisk.po +46 -31
- data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
- data/locale/zh_TW/foreman_bootdisk.po +28 -13
- data/release-gem +84 -0
- data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +35 -33
- data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +9 -7
- data/test/functional/foreman_bootdisk/disks_controller_test.rb +27 -25
- data/test/models/host/managed_test.rb +17 -13
- data/test/test_plugin_helper.rb +11 -7
- data/test/unit/access_permissions_test.rb +2 -0
- data/test/unit/concerns/compute_resources/vmware_test.rb +67 -63
- data/test/unit/concerns/host_test.rb +64 -53
- data/test/unit/concerns/orchestration/compute_test.rb +41 -39
- data/test/unit/foreman_bootdisk/renderer_test.rb +3 -1
- data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +3 -1
- data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +30 -0
- data/test/unit/iso_generator_test.rb +67 -40
- metadata +65 -5
data/release-gem
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
$plugin_name = "foreman_bootdisk"
|
6
|
+
RUBY_VERSION_FILE = "lib/#{$plugin_name}/version.rb"
|
7
|
+
|
8
|
+
def die(msg)
|
9
|
+
STDERR.puts msg; exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(cmd)
|
13
|
+
puts `#{cmd}`
|
14
|
+
die("Command #{cmd} failed with #{$?}!") if $?.to_i != 0
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def action(question)
|
19
|
+
puts "#{question} ? [Y/n]"
|
20
|
+
die("Aborted.") if STDIN.gets.chomp.match(/^(n|no|nope)$/i)
|
21
|
+
die("Check failed, exiting.") if block_given? && ! yield
|
22
|
+
end
|
23
|
+
|
24
|
+
action "Extracted strings with: rake plugin:gettext[#{$plugin_name}] (Foreman dir)"
|
25
|
+
|
26
|
+
action "Pulled updates with: make -C locale tx-update"
|
27
|
+
|
28
|
+
action "Merged the updates with: rake plugin:gettext[#{$plugin_name}] (Foreman dir)"
|
29
|
+
|
30
|
+
action "Rebuilt the MO files with: make -C locale mo-files" do
|
31
|
+
Dir["locale/**/*.po"].each do |po|
|
32
|
+
mo = po.sub(/#{$plugin_name}\.po$/, "LC_MESSAGES/#{$plugin_name}.mo")
|
33
|
+
puts("Warning, file #{mo} does not exist!") unless File.exist?(mo)
|
34
|
+
puts("Warning, file #{mo} outdated!") if File.mtime(po) > File.mtime(mo)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
action "Want me to update AUTHORS file" do
|
39
|
+
run "git log --pretty=format:'%an' | sort -u > AUTHORS"
|
40
|
+
end
|
41
|
+
|
42
|
+
action "Modified lib/#{$plugin_name}/engine.rb to match minimum Foreman core version"
|
43
|
+
|
44
|
+
action "Modified #{RUBY_VERSION_FILE} to match desired version"
|
45
|
+
|
46
|
+
action "Created 'Version X.Y' commit with engine.rb/version.rb change"
|
47
|
+
|
48
|
+
action "Created git tag" do
|
49
|
+
$git_version = `git describe --abbrev=0 --tags`.chomp.sub("v", "")
|
50
|
+
$git_version == File.read(RUBY_VERSION_FILE).match(/VERSION\s*=\s'([0-9\.]+)'/)[1]
|
51
|
+
end
|
52
|
+
|
53
|
+
action "Is version #{$git_version} the one to be released"
|
54
|
+
|
55
|
+
$gem_filename = "#{$plugin_name}-#{$git_version}.gem"
|
56
|
+
action "Shall I build the #{$gem_filename} now" do
|
57
|
+
run "gem build #{$plugin_name}.gemspec"
|
58
|
+
end
|
59
|
+
|
60
|
+
action "Investigated the #{$gem_filename} via gem compare -k -b #{$plugin_name} OLD #{$git_version} -k" do
|
61
|
+
run "tar -xOf #{$gem_filename} data.tar.gz | tar -z -list | sort"
|
62
|
+
end
|
63
|
+
|
64
|
+
action "Created and built OS distribution packages"
|
65
|
+
|
66
|
+
action "Updated dependencies in both RPM and DEB spec files"
|
67
|
+
|
68
|
+
action "All commits and *tags* pushed to origin"
|
69
|
+
|
70
|
+
action "Shell I push the #{$gem_filename} to rubygems.org now" do
|
71
|
+
run "gem push #{$gem_filename}"
|
72
|
+
end
|
73
|
+
|
74
|
+
action "Is https://rubygems.org/gems/#{$plugin_name} looking good"
|
75
|
+
|
76
|
+
action "Created new stable branch and pushed to origin"
|
77
|
+
|
78
|
+
action "Updated documentation at www.theforeman.org?"
|
79
|
+
|
80
|
+
action "Updated jenkins_job_builder http://bit.ly/2iZKR3B branch"
|
81
|
+
|
82
|
+
puts "Well done! Go ahead and create documentation and changelog:"
|
83
|
+
puts " git log --pretty=format:'%s' develop...X.Y.Z"
|
84
|
+
puts " git log --pretty=format:'%an' develop...X.Y.Z | sort -u"
|
@@ -1,61 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class ForemanBootdisk::Api::V2::DisksControllerTest < ActionController::TestCase
|
4
6
|
include ForemanBootdiskTestHelper
|
5
7
|
setup :setup_bootdisk
|
6
8
|
|
7
|
-
test
|
8
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
9
|
-
@controller.expects(:read_file).with(
|
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')
|
10
12
|
get :generic
|
11
13
|
assert_response :success
|
12
|
-
assert_equal
|
14
|
+
assert_equal 'ISO image', @response.body
|
13
15
|
end
|
14
16
|
|
15
|
-
describe
|
17
|
+
describe '#host' do
|
16
18
|
setup :setup_referer
|
17
19
|
setup :setup_host_env
|
18
20
|
|
19
|
-
test
|
20
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
21
|
-
@controller.expects(:read_file).with(
|
22
|
-
get :host, params: {:
|
21
|
+
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 }
|
23
25
|
assert_response :success
|
24
|
-
assert_equal
|
26
|
+
assert_equal 'ISO image', @response.body
|
25
27
|
end
|
26
28
|
|
27
|
-
test
|
28
|
-
ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields(
|
29
|
-
@controller.expects(:read_file).with(
|
30
|
-
get :host, params: {:
|
29
|
+
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 }
|
31
33
|
assert_response :success
|
32
|
-
assert_equal
|
34
|
+
assert_equal 'ISO image', @response.body
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
describe
|
38
|
+
describe 'default API version 2' do
|
37
39
|
setup :setup_host_env
|
38
40
|
|
39
|
-
test
|
40
|
-
if Rails::VERSION::MAJOR >= 5
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
test 'path - /api/hosts/:host_id routes to #host' do
|
42
|
+
expected_path = if Rails::VERSION::MAJOR >= 5
|
43
|
+
"/api/v2/hosts/#{@host.id}"
|
44
|
+
else
|
45
|
+
"/api/hosts/#{@host.id}"
|
46
|
+
end
|
45
47
|
assert_routing expected_path,
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
48
|
+
format: 'json',
|
49
|
+
apiv: 'v2',
|
50
|
+
controller: 'foreman_bootdisk/api/v2/disks',
|
51
|
+
action: 'host',
|
52
|
+
id: @host.id.to_s
|
51
53
|
end
|
52
54
|
|
53
|
-
test
|
54
|
-
assert_routing
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
55
|
+
test 'path - /api/generic routes to #generic' do
|
56
|
+
assert_routing '/api/generic',
|
57
|
+
format: 'json',
|
58
|
+
apiv: 'v2',
|
59
|
+
controller: 'foreman_bootdisk/api/v2/disks',
|
60
|
+
action: 'generic'
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
@@ -1,22 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class ForemanBootdisk::Api::V2::SubnetDisksControllerTest < ActionController::TestCase
|
4
6
|
include ForemanBootdiskTestHelper
|
5
7
|
setup :setup_bootdisk
|
6
8
|
|
7
|
-
describe
|
9
|
+
describe '#subnet_host' do
|
8
10
|
setup :setup_referer
|
9
11
|
setup :setup_org_loc
|
10
12
|
setup :setup_subnet
|
11
13
|
setup :setup_host
|
12
14
|
|
13
|
-
test
|
14
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
15
|
-
ForemanBootdisk::Renderer.any_instance.stubs(:bootdisk_chain_url).yields(
|
16
|
-
File.expects(:read).with(
|
17
|
-
get :subnet, params: {:
|
15
|
+
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 }
|
18
20
|
assert_response :success
|
19
|
-
assert_equal
|
21
|
+
assert_equal 'ISO image', @response.body
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,64 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
5
|
class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
|
4
6
|
include ForemanBootdiskTestHelper
|
5
7
|
setup :setup_bootdisk
|
6
8
|
|
7
|
-
test
|
8
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
9
|
-
@controller.expects(:read_file).with(
|
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')
|
10
12
|
get :generic, session: set_session_user
|
11
13
|
assert_response :success
|
12
|
-
assert_equal
|
14
|
+
assert_equal 'ISO image', @response.body
|
13
15
|
end
|
14
16
|
|
15
|
-
describe
|
17
|
+
describe '#host' do
|
16
18
|
setup :setup_referer
|
17
19
|
setup :setup_org_loc
|
18
20
|
setup :setup_subnet
|
19
21
|
setup :setup_host
|
20
22
|
|
21
|
-
test
|
22
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
23
|
-
@controller.expects(:read_file).with(
|
24
|
-
get :host, params: {:
|
23
|
+
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
|
25
27
|
assert_response :success
|
26
|
-
assert_equal
|
28
|
+
assert_equal 'ISO image', @response.body
|
27
29
|
end
|
28
30
|
|
29
|
-
test
|
30
|
-
ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields(
|
31
|
-
@controller.expects(:read_file).with(
|
32
|
-
get :full_host, params: {:
|
31
|
+
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
|
33
35
|
assert_response :success
|
34
|
-
assert_equal
|
36
|
+
assert_equal 'ISO image', @response.body
|
35
37
|
end
|
36
38
|
|
37
|
-
test
|
38
|
-
ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:
|
39
|
-
ForemanBootdisk::Renderer.any_instance.stubs(:bootdisk_chain_url).yields(
|
40
|
-
@controller.expects(:read_file).with(
|
41
|
-
get :subnet, params: {:
|
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
|
42
44
|
assert_empty flash[:error]
|
43
45
|
assert_response :success
|
44
|
-
assert_equal
|
46
|
+
assert_equal 'ISO image', @response.body
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
describe
|
50
|
+
describe '#host without tftp' do
|
49
51
|
setup :setup_referer
|
50
52
|
setup :setup_org_loc
|
51
53
|
setup :setup_subnet_no_tftp
|
52
54
|
setup :setup_host
|
53
55
|
|
54
|
-
test
|
55
|
-
get :subnet, params: {:
|
56
|
+
test 'should not generate subnet image' do
|
57
|
+
get :subnet, params: { id: @host.name }, session: set_session_user
|
56
58
|
assert_match(/Failed.*: TFTP feature not enabled/, flash[:error])
|
57
59
|
assert_response :redirect
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
test
|
63
|
+
test 'should render help' do
|
62
64
|
get :help, session: set_session_user
|
63
65
|
assert_response :success
|
64
66
|
end
|
@@ -1,22 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
module Host
|
6
|
+
class ManagedTest < ActiveSupport::TestCase
|
7
|
+
include ForemanBootdiskTestHelper
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
setup do
|
10
|
+
User.current = users(:admin)
|
11
|
+
setup_bootdisk
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
context 'with host' do
|
15
|
+
let(:host) { FactoryBot.create(:host, :managed, :with_subnet, build: true) }
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
test 'finds the bootdisk_template specified in settings' do
|
18
|
+
assert_kind_of ProvisioningTemplate, host.bootdisk_template
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
test 'renders the host bootdisk template' do
|
22
|
+
assert_includes host.bootdisk_template_render, 'loop_success'
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
4
|
+
require 'webmock/minitest'
|
5
|
+
require 'webmock'
|
2
6
|
|
3
7
|
module ForemanBootdiskTestHelper
|
4
8
|
def setup_bootdisk
|
@@ -26,25 +30,25 @@ module ForemanBootdiskTestHelper
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def setup_referer
|
29
|
-
request.env[
|
33
|
+
request.env['HTTP_REFERER'] = '/history'
|
30
34
|
end
|
31
35
|
|
32
36
|
def setup_org_loc
|
33
37
|
disable_orchestration
|
34
|
-
@org
|
38
|
+
@org = FactoryBot.create(:organization)
|
39
|
+
@loc = FactoryBot.create(:location)
|
35
40
|
end
|
36
41
|
|
37
42
|
def setup_subnet
|
38
|
-
tftp_proxy = FactoryBot.create(:smart_proxy, :
|
39
|
-
setup_subnet_no_tftp.update! :
|
43
|
+
tftp_proxy = FactoryBot.create(:smart_proxy, features: [FactoryBot.create(:tftp_feature)])
|
44
|
+
setup_subnet_no_tftp.update! tftp: tftp_proxy
|
40
45
|
end
|
41
46
|
|
42
47
|
def setup_subnet_no_tftp
|
43
|
-
@subnet = FactoryBot.create(:subnet_ipv4, :
|
48
|
+
@subnet = FactoryBot.create(:subnet_ipv4, gateway: '10.0.1.254', dns_primary: '8.8.8.8', organizations: [@org], locations: [@loc])
|
44
49
|
end
|
45
50
|
|
46
51
|
def setup_host
|
47
|
-
@host = FactoryBot.create(:host, :managed, :
|
52
|
+
@host = FactoryBot.create(:host, :managed, subnet: @subnet, ip: @subnet.network.sub(/0$/, '4'), organization: @org, location: @loc)
|
48
53
|
end
|
49
|
-
|
50
54
|
end
|
@@ -1,79 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_plugin_helper'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module ForemanBootdisk
|
6
|
+
class VmwareTest < ActiveSupport::TestCase
|
7
|
+
describe '#create_vm' do
|
8
|
+
setup do
|
9
|
+
@cr = FactoryBot.build(:vmware_cr)
|
10
|
+
@cr.stubs(:test_connection)
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
test 'does not call clone_vm when bootdisk provisioning' do
|
14
|
+
args = { 'provision_method' => 'bootdisk' }
|
15
|
+
mock_vm = mock('vm')
|
16
|
+
mock_vm.stubs(:firmware)
|
17
|
+
mock_vm.expects(:save).returns(mock_vm)
|
18
|
+
@cr.stubs(:parse_networks).returns(args)
|
19
|
+
@cr.expects(:clone_vm).times(0)
|
20
|
+
@cr.expects(:new_vm).returns(mock_vm)
|
21
|
+
@cr.create_vm(args)
|
22
|
+
end
|
19
23
|
end
|
20
|
-
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
describe '#new_vm' do
|
26
|
+
setup do
|
27
|
+
@cr = FactoryBot.build(:vmware_cr)
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
test 'calls client with cdrom drive and correct boot order when bootdisk provisioning' do
|
31
|
+
args = { 'provision_method' => 'bootdisk' }
|
32
|
+
mock_client = mock('client')
|
33
|
+
mock_servers = mock('servers')
|
34
|
+
mock_cdrom = mock('cdrom')
|
35
|
+
mock_client.expects(:servers).returns(mock_servers)
|
36
|
+
mock_servers.expects(:new).with do |opts|
|
37
|
+
assert_equal opts[:boot_order], %w[cdrom disk]
|
38
|
+
assert_equal opts[:boot_retry], 10
|
39
|
+
assert_includes opts[:cdroms], mock_cdrom
|
40
|
+
end
|
41
|
+
@cr.expects(:new_cdrom).returns(mock_cdrom)
|
42
|
+
@cr.expects(:new_interface)
|
43
|
+
@cr.expects(:new_volume)
|
44
|
+
@cr.expects(:datacenter)
|
45
|
+
@cr.expects(:client).returns(mock_client)
|
46
|
+
@cr.new_vm(args)
|
37
47
|
end
|
38
|
-
@cr.expects(:new_cdrom).returns(mock_cdrom)
|
39
|
-
@cr.expects(:new_interface)
|
40
|
-
@cr.expects(:new_volume)
|
41
|
-
@cr.expects(:datacenter)
|
42
|
-
@cr.expects(:client).returns(mock_client)
|
43
|
-
@cr.new_vm(args)
|
44
48
|
end
|
45
|
-
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
describe '#parse_args' do
|
51
|
+
setup do
|
52
|
+
@cr = FactoryBot.build(:vmware_cr)
|
53
|
+
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
test 'should add a cdrom drive while keeping other parameters when provision_method is bootdisk' do
|
56
|
+
mock_cdrom = mock('cdrom')
|
57
|
+
@cr.expects(:new_cdrom).returns(mock_cdrom)
|
58
|
+
attrs_in = HashWithIndifferentAccess.new(
|
59
|
+
'cpus' => '1',
|
60
|
+
:provision_method => 'bootdisk'
|
61
|
+
)
|
62
|
+
attrs_out = {
|
63
|
+
cpus: '1',
|
64
|
+
provision_method: 'bootdisk',
|
65
|
+
cdroms: [mock_cdrom],
|
66
|
+
boot_order: %w[cdrom disk],
|
67
|
+
boot_retry: 10
|
68
|
+
}
|
69
|
+
assert_equal attrs_out, @cr.parse_args(attrs_in)
|
70
|
+
end
|
67
71
|
end
|
68
|
-
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
describe '#capabilities' do
|
74
|
+
setup do
|
75
|
+
@cr = FactoryBot.build(:vmware_cr)
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
78
|
+
test 'should include bootdisk' do
|
79
|
+
assert_includes @cr.capabilities, :bootdisk
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|