foreman_salt 14.0.0 → 14.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/README.md +1 -2
- data/Rakefile +2 -2
- data/app/controllers/foreman_salt/api/v2/jobs_controller.rb +9 -9
- data/app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb +15 -14
- data/app/controllers/foreman_salt/api/v2/salt_environments_controller.rb +6 -6
- data/app/controllers/foreman_salt/api/v2/salt_hostgroups_controller.rb +42 -0
- data/app/controllers/foreman_salt/api/v2/salt_keys_controller.rb +14 -14
- data/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb +8 -8
- data/app/controllers/foreman_salt/api/v2/salt_states_controller.rb +24 -26
- data/app/controllers/foreman_salt/api/v2/salt_variables_controller.rb +22 -21
- data/app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb +3 -3
- data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +4 -4
- data/app/controllers/foreman_salt/concerns/salt_environment_parameters.rb +1 -1
- data/app/controllers/foreman_salt/concerns/salt_hostgroup_parameters.rb +25 -0
- data/app/controllers/foreman_salt/concerns/salt_module_parameters.rb +1 -1
- data/app/controllers/foreman_salt/concerns/salt_override_value.rb +4 -4
- data/app/controllers/foreman_salt/concerns/salt_variable_parameters.rb +5 -5
- data/app/controllers/foreman_salt/minions_controller.rb +9 -9
- data/app/controllers/foreman_salt/salt_autosign_controller.rb +8 -8
- data/app/controllers/foreman_salt/salt_environments_controller.rb +4 -4
- data/app/controllers/foreman_salt/salt_keys_controller.rb +11 -11
- data/app/controllers/foreman_salt/salt_modules_controller.rb +10 -11
- data/app/controllers/foreman_salt/salt_variables_controller.rb +5 -4
- data/app/controllers/foreman_salt/state_importer.rb +12 -13
- data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +16 -10
- data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +2 -2
- data/app/helpers/foreman_salt/salt_keys_helper.rb +2 -1
- data/app/helpers/foreman_salt/salt_modules_helper.rb +11 -11
- data/app/helpers/foreman_salt/salt_reports_helper.rb +0 -1
- data/app/lib/actions/foreman_salt/report_import.rb +2 -2
- data/app/lib/proxy_api/salt.rb +17 -17
- data/app/models/foreman_salt/concerns/host_managed_extensions.rb +47 -46
- data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +14 -11
- data/app/models/foreman_salt/host_salt_module.rb +1 -1
- data/app/models/foreman_salt/salt_environment.rb +8 -8
- data/app/models/foreman_salt/salt_module.rb +15 -13
- data/app/models/foreman_salt/salt_module_environment.rb +1 -1
- data/app/models/foreman_salt/salt_provider.rb +7 -4
- data/app/models/foreman_salt/salt_variable.rb +8 -8
- data/app/models/setting/salt.rb +12 -10
- data/app/overrides/salt_environment_host_selector.rb +4 -4
- data/app/overrides/salt_environment_hostgroup_selector.rb +4 -4
- data/app/overrides/salt_modules_selector.rb +16 -16
- data/app/overrides/salt_proxy_selector.rb +11 -9
- data/app/services/foreman_salt/report_importer.rb +26 -26
- data/app/services/foreman_salt/smart_proxies/salt_keys.rb +47 -45
- data/app/views/foreman_salt/api/v2/salt_autosign/create.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_environments/create.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_environments/show.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_hostgroups/base.json.rabl +7 -0
- data/app/views/foreman_salt/api/v2/salt_hostgroups/show.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_hostgroups/update.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_keys/update.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_minions/show.json.rabl +3 -4
- data/app/views/foreman_salt/api/v2/salt_states/create.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_states/show.json.rabl +0 -1
- data/app/views/foreman_salt/api/v2/salt_variables/create.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_variables/destroy.json.rabl +1 -1
- data/app/views/foreman_salt/api/v2/salt_variables/show.json.rabl +8 -8
- data/config/api_routes.rb +31 -0
- data/config/routes.rb +16 -44
- data/db/migrate/20140817210214_create_salt_modules.rb +4 -4
- data/db/migrate/20140829210214_add_salt_modules_to_hostgroups.rb +1 -1
- data/db/migrate/20140920232200_create_salt_environments.rb +3 -3
- data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +6 -2
- data/db/migrate/20211108211312_add_missing_permissions.rb +9 -0
- data/db/seeds.d/75-salt_seeds.rb +1 -1
- data/db/seeds.d/76-job_templates.rb +3 -3
- data/lib/foreman_salt/engine.rb +24 -16
- data/lib/foreman_salt/extensions.rb +8 -8
- data/lib/foreman_salt/plugin.rb +120 -114
- data/lib/foreman_salt/version.rb +1 -1
- data/lib/foreman_salt.rb +1 -1
- data/lib/tasks/foreman_salt_tasks.rake +3 -5
- data/locale/action_names.rb +4 -4
- data/test/factories/foreman_salt_factories.rb +5 -5
- data/test/functional/api/v2/salt_autosign_controller_test.rb +26 -20
- data/test/functional/api/v2/salt_environments_controller_test.rb +29 -23
- data/test/functional/api/v2/salt_hostgroups_controller_test.rb +76 -0
- data/test/functional/api/v2/salt_keys_controller_test.rb +25 -19
- data/test/functional/api/v2/salt_states_controller_test.rb +72 -66
- data/test/functional/api/v2/salt_variables_controller_test.rb +4 -4
- data/test/functional/hosts_controller_test.rb +26 -26
- data/test/functional/minions_controller_test.rb +22 -22
- data/test/functional/salt_modules_controller_test.rb +3 -3
- data/test/functional/salt_variables_controller_test.rb +5 -5
- data/test/integration/hosts_js_test.rb +11 -11
- data/test/integration/salt_autosign_test.rb +5 -5
- data/test/integration/salt_environment_test.rb +2 -2
- data/test/integration/salt_keys_test.rb +7 -7
- data/test/integration/salt_module_test.rb +9 -9
- data/test/integration/salt_variable_test.rb +2 -2
- data/test/test_plugin_helper.rb +1 -1
- data/test/unit/grains_importer_test.rb +12 -12
- data/test/unit/host_extensions_test.rb +19 -19
- data/test/unit/hostgroup_extensions_test.rb +13 -13
- data/test/unit/report_importer_test.rb +9 -9
- data/test/unit/salt_keys_test.rb +2 -2
- data/test/unit/salt_modules_test.rb +2 -2
- data/test/unit/salt_variables_test.rb +10 -10
- metadata +22 -13
@@ -15,28 +15,28 @@ module ForemanSalt
|
|
15
15
|
as_admin do
|
16
16
|
proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
|
17
17
|
salt_environment = FactoryBot.create(:salt_environment)
|
18
|
-
@host = FactoryBot.create(:host, :
|
18
|
+
@host = FactoryBot.create(:host, salt_proxy: proxy, salt_environment: salt_environment)
|
19
19
|
Setting::Salt.load_defaults
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
test
|
23
|
+
describe 'hosts details run salt button' do
|
24
|
+
test 'verify run salt button availabilty' do
|
25
25
|
Setting[:salt_hide_run_salt_button] = false
|
26
26
|
visit hosts_path
|
27
27
|
click_link @host.fqdn
|
28
|
-
assert page.has_link?(
|
28
|
+
assert page.has_link?('Run Salt')
|
29
29
|
end
|
30
30
|
|
31
|
-
test
|
31
|
+
test 'verify run salt button absence' do
|
32
32
|
Setting[:salt_hide_run_salt_button] = true
|
33
33
|
visit hosts_path
|
34
34
|
click_link @host.fqdn
|
35
|
-
assert_not page.has_link?(
|
35
|
+
assert_not page.has_link?('Run Salt')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe
|
39
|
+
describe 'hosts index salt multiple actions' do
|
40
40
|
test 'change salt master action' do
|
41
41
|
visit hosts_path
|
42
42
|
check 'check_all'
|
@@ -51,13 +51,13 @@ module ForemanSalt
|
|
51
51
|
|
52
52
|
# Hosts are added to cookie
|
53
53
|
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
|
54
|
-
|
54
|
+
assert_includes(host_ids_on_cookie, @host.id)
|
55
55
|
|
56
56
|
within('#submit_multiple') do
|
57
57
|
click_on('Change Salt Master')
|
58
58
|
end
|
59
59
|
|
60
|
-
assert index_modal.visible?,
|
60
|
+
assert index_modal.visible?, 'Modal window was shown'
|
61
61
|
page.find('#proxy_proxy_id').find("option[value='#{@host.salt_proxy.id}']").select_option
|
62
62
|
|
63
63
|
# remove hosts cookie on submit
|
@@ -80,13 +80,13 @@ module ForemanSalt
|
|
80
80
|
|
81
81
|
# Hosts are added to cookie
|
82
82
|
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
|
83
|
-
|
83
|
+
assert_includes(host_ids_on_cookie, @host.id)
|
84
84
|
|
85
85
|
within('#submit_multiple') do
|
86
86
|
click_on('Change Salt Environment')
|
87
87
|
end
|
88
88
|
|
89
|
-
assert index_modal.visible?,
|
89
|
+
assert index_modal.visible?, 'Modal window was shown'
|
90
90
|
page.find('#salt_environment_id').find("option[value='#{@host.salt_environment.id}']").select_option
|
91
91
|
|
92
92
|
# remove hosts cookie on submit
|
@@ -12,25 +12,25 @@ module ForemanSalt
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'smart proxy page has autosign link' do
|
15
|
-
assert_row_button(smart_proxies_path, @proxy.name, 'Salt Autosign', true)
|
15
|
+
assert_row_button(smart_proxies_path, @proxy.name, 'Salt Autosign', dropdown: true)
|
16
16
|
end
|
17
17
|
|
18
18
|
test 'smart proxy details has autosign link' do
|
19
19
|
visit smart_proxy_path(@proxy)
|
20
|
-
assert page.has_link?
|
21
|
-
click_link
|
20
|
+
assert page.has_link? 'Salt Autosign'
|
21
|
+
click_link 'Salt Autosign'
|
22
22
|
assert page.has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
|
23
23
|
end
|
24
24
|
|
25
25
|
test 'index page' do
|
26
|
-
visit smart_proxy_salt_autosign_index_path(:
|
26
|
+
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)
|
27
27
|
assert find_link('Keys').visible?, 'Keys is not visible'
|
28
28
|
assert has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
|
29
29
|
assert has_content?('Displaying'), 'Pagination "Display ..." does not appear'
|
30
30
|
end
|
31
31
|
|
32
32
|
test 'has list of autosign' do
|
33
|
-
visit smart_proxy_salt_autosign_index_path(:
|
33
|
+
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)
|
34
34
|
assert has_content?('foo.example.com'), 'Missing autosign entry on index page'
|
35
35
|
end
|
36
36
|
end
|
@@ -10,7 +10,7 @@ module ForemanSalt
|
|
10
10
|
|
11
11
|
test 'create new page' do
|
12
12
|
assert_new_button(salt_environments_path, 'New Salt Environment', new_salt_environment_path)
|
13
|
-
fill_in 'foreman_salt_salt_environment_name', :
|
13
|
+
fill_in 'foreman_salt_salt_environment_name', with: 'common'
|
14
14
|
assert_submit_button(salt_environments_path)
|
15
15
|
assert page.has_link? 'common'
|
16
16
|
end
|
@@ -19,7 +19,7 @@ module ForemanSalt
|
|
19
19
|
salt_environment = FactoryBot.create :salt_environment
|
20
20
|
visit salt_environments_path
|
21
21
|
click_link salt_environment.name
|
22
|
-
fill_in 'foreman_salt_salt_environment_name', :
|
22
|
+
fill_in 'foreman_salt_salt_environment_name', with: 'some_other_name'
|
23
23
|
assert_submit_button(salt_environments_path)
|
24
24
|
assert page.has_link? 'some_other_name'
|
25
25
|
end
|
@@ -15,36 +15,36 @@ module ForemanSalt
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test 'smart proxy page has keys link' do
|
18
|
-
assert_row_button(smart_proxies_path, @proxy.name, 'Salt Keys', true)
|
18
|
+
assert_row_button(smart_proxies_path, @proxy.name, 'Salt Keys', dropdown: true)
|
19
19
|
end
|
20
20
|
|
21
21
|
test 'smart proxy details has keys link' do
|
22
22
|
visit smart_proxy_path(@proxy)
|
23
|
-
assert page.has_link?
|
24
|
-
click_link
|
23
|
+
assert page.has_link? 'Salt Keys'
|
24
|
+
click_link 'Salt Keys'
|
25
25
|
assert page.has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'index page' do
|
29
|
-
visit smart_proxy_salt_keys_path(:
|
29
|
+
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)
|
30
30
|
assert has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
|
31
31
|
assert has_content?('Displaying'), 'Pagination "Display ..." does not appear'
|
32
32
|
end
|
33
33
|
|
34
34
|
test 'has list of keys' do
|
35
|
-
visit smart_proxy_salt_keys_path(:
|
35
|
+
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)
|
36
36
|
assert has_content?('saltclient01.example.com'), 'Missing key on index page'
|
37
37
|
assert has_content?('98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1'), 'Missing fingerprint on index page'
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'has accept link' do
|
41
41
|
ProxyAPI::Salt.any_instance.stubs(:key_accept).returns(true)
|
42
|
-
assert_row_button(smart_proxy_salt_keys_path(:
|
42
|
+
assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Accept', dropdown: true)
|
43
43
|
end
|
44
44
|
|
45
45
|
test 'has reject link' do
|
46
46
|
ProxyAPI::Salt.any_instance.stubs(:key_reject).returns(true)
|
47
|
-
assert_row_button(smart_proxy_salt_keys_path(:
|
47
|
+
assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Reject', dropdown: true)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -6,7 +6,7 @@ module ForemanSalt
|
|
6
6
|
setup do
|
7
7
|
User.current = users :admin
|
8
8
|
|
9
|
-
states = %w
|
9
|
+
states = %w[state1 state2 state3 state4]
|
10
10
|
state_list = { 'env1' => states, 'env2' => states }
|
11
11
|
|
12
12
|
ProxyAPI::Salt.any_instance.stubs(:states_list).returns(state_list)
|
@@ -19,7 +19,7 @@ module ForemanSalt
|
|
19
19
|
|
20
20
|
test 'create new page' do
|
21
21
|
assert_new_button(salt_modules_path, 'New Salt State', new_salt_module_path)
|
22
|
-
fill_in 'foreman_salt_salt_module_name', :
|
22
|
+
fill_in 'foreman_salt_salt_module_name', with: 'common'
|
23
23
|
assert_submit_button(salt_modules_path)
|
24
24
|
assert page.has_link? 'common'
|
25
25
|
end
|
@@ -28,24 +28,24 @@ module ForemanSalt
|
|
28
28
|
salt_module = FactoryBot.create :salt_module
|
29
29
|
visit salt_modules_path
|
30
30
|
click_link salt_module.name
|
31
|
-
fill_in :foreman_salt_salt_module_name, :
|
31
|
+
fill_in :foreman_salt_salt_module_name, with: 'some_other_name'
|
32
32
|
assert_submit_button(salt_modules_path)
|
33
33
|
assert page.has_link? 'some_other_name'
|
34
34
|
end
|
35
35
|
|
36
36
|
test 'import states' do
|
37
37
|
proxy = FactoryBot.create :smart_proxy, :with_salt_feature
|
38
|
-
state = FactoryBot.create :salt_module, :
|
38
|
+
state = FactoryBot.create :salt_module, salt_environments: [FactoryBot.create(:salt_environment)]
|
39
39
|
|
40
40
|
visit salt_modules_path
|
41
41
|
click_link "Import from #{proxy.name}"
|
42
42
|
|
43
|
-
assert page.has_selector?('td', :
|
44
|
-
assert page.has_selector?('td', :
|
45
|
-
assert page.has_selector?('td', :
|
43
|
+
assert page.has_selector?('td', text: 'env1'), 'Could not find env1 on importer page'
|
44
|
+
assert page.has_selector?('td', text: 'Add'), 'Could not find env1 on importer page'
|
45
|
+
assert page.has_selector?('td', text: 'state1, state2, state3, and state4'), 'Could not find states on importer page'
|
46
46
|
|
47
|
-
assert page.has_selector?('td', :
|
48
|
-
assert page.has_selector?('td', :
|
47
|
+
assert page.has_selector?('td', text: 'Remove'), 'Could not find remove on importer page'
|
48
|
+
assert page.has_selector?('td', text: state.name), 'Could not find state to remove'
|
49
49
|
|
50
50
|
all('input.state_check').each { |checkbox| check(checkbox[:id]) }
|
51
51
|
|
@@ -15,8 +15,8 @@ module ForemanSalt
|
|
15
15
|
test 'create new page' do
|
16
16
|
state = FactoryBot.create :salt_module
|
17
17
|
assert_new_button(salt_variables_path, 'New Salt Variable', new_salt_variable_path)
|
18
|
-
fill_in 'foreman_salt_salt_variable_key', :
|
19
|
-
select2(state.name, :
|
18
|
+
fill_in 'foreman_salt_salt_variable_key', with: 'mykey'
|
19
|
+
select2(state.name, from: 'foreman_salt_salt_variable_salt_module_id')
|
20
20
|
assert_submit_button(salt_variables_path)
|
21
21
|
assert page.has_link? 'mykey'
|
22
22
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# This calls the main test_helper in Foreman-core
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
def assert_row_button(index_path, link_text, button_text, dropdown
|
4
|
+
def assert_row_button(index_path, link_text, button_text, dropdown: false)
|
5
5
|
visit index_path
|
6
6
|
within(:xpath, "//tr[contains(.,'#{link_text}')]") do
|
7
7
|
find('span.caret').click if dropdown
|
@@ -10,9 +10,9 @@ module ForemanSalt
|
|
10
10
|
User.current = users :admin
|
11
11
|
Setting[:create_new_host_when_facts_are_uploaded] = true
|
12
12
|
|
13
|
-
Operatingsystem.where(:
|
13
|
+
Operatingsystem.where(name: 'CentOS', major: '6', minor: '5').delete_all
|
14
14
|
|
15
|
-
grains = JSON.parse(File.read(File.join(
|
15
|
+
grains = JSON.parse(File.read(File.join(Foreman::Application.root, 'test', 'static_fixtures', 'facts', 'grains_centos.json')))
|
16
16
|
@imported_host = ::Host::Managed.import_host grains['name'], 'salt'
|
17
17
|
@imported_host.import_facts grains['facts'].with_indifferent_access
|
18
18
|
end
|
@@ -26,7 +26,7 @@ module ForemanSalt
|
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'nested facts have valid parents' do
|
29
|
-
parent = ::FactName.
|
29
|
+
parent = ::FactName.find_by(name: 'cpu_flags')
|
30
30
|
children = @imported_host.fact_values.with_fact_parent_id(parent)
|
31
31
|
assert_not_empty children
|
32
32
|
assert_empty children.map(&:fact_name).reject { |fact| fact.name =~ /\Acpu_flags#{FactName::SEPARATOR}[0-9]+/ }
|
@@ -34,33 +34,33 @@ module ForemanSalt
|
|
34
34
|
|
35
35
|
# Parser
|
36
36
|
test 'imported host has operating system' do
|
37
|
-
assert_equal @imported_host.os.to_label
|
37
|
+
assert_equal('CentOS 6.5', @imported_host.os.to_label)
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'imported host operating system has deduced family' do
|
41
|
-
assert_equal @imported_host.os.family
|
41
|
+
assert_equal('Redhat', @imported_host.os.family)
|
42
42
|
end
|
43
43
|
|
44
44
|
test 'imported host has hardware model' do
|
45
|
-
assert_equal @imported_host.model.name
|
45
|
+
assert_equal('KVM', @imported_host.model.name)
|
46
46
|
end
|
47
47
|
|
48
48
|
test 'imported host has architecture' do
|
49
|
-
assert_equal @imported_host.arch.name
|
49
|
+
assert_equal('x86_64', @imported_host.arch.name)
|
50
50
|
end
|
51
51
|
|
52
52
|
test 'imported host has primary ip' do
|
53
|
-
assert_equal
|
53
|
+
assert_equal('10.7.13.141', @imported_host.ip)
|
54
54
|
end
|
55
55
|
|
56
56
|
test 'imported host has primary mac' do
|
57
|
-
assert_equal
|
57
|
+
assert_equal('52:54:00:35:30:2a', @imported_host.mac)
|
58
58
|
end
|
59
59
|
|
60
60
|
test 'imported host has additional interface' do
|
61
|
-
nic = @imported_host.interfaces.
|
62
|
-
assert_equal
|
63
|
-
assert_equal
|
61
|
+
nic = @imported_host.interfaces.find_by(identifier: 'eth1')
|
62
|
+
assert_equal('de:ad:be:ef:07:13', nic.mac)
|
63
|
+
assert_equal('1.2.3.4', nic.ip)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -16,7 +16,7 @@ module ForemanSalt
|
|
16
16
|
test 'smart_proxy_ids returns salt smart proxy' do
|
17
17
|
host = FactoryBot.create :host
|
18
18
|
host.salt_proxy = @proxy
|
19
|
-
|
19
|
+
assert_includes host.smart_proxy_ids, host.salt_proxy_id
|
20
20
|
end
|
21
21
|
|
22
22
|
test 'host params includes salt_master' do
|
@@ -29,7 +29,7 @@ module ForemanSalt
|
|
29
29
|
test 'host inherits salt proxy from host group' do
|
30
30
|
hostgroup = FactoryBot.create :hostgroup
|
31
31
|
hostgroup.salt_proxy = @proxy
|
32
|
-
host = FactoryBot.create :host, :
|
32
|
+
host = FactoryBot.create :host, hostgroup: hostgroup
|
33
33
|
host.set_hostgroup_defaults
|
34
34
|
assert_equal host.salt_proxy, hostgroup.salt_proxy
|
35
35
|
end
|
@@ -41,12 +41,12 @@ module ForemanSalt
|
|
41
41
|
state = FactoryBot.create :salt_module
|
42
42
|
other_environment.salt_modules << state
|
43
43
|
|
44
|
-
host = FactoryBot.create :host, :
|
44
|
+
host = FactoryBot.create :host, salt_environment: hosts_environment
|
45
45
|
host.salt_proxy = @proxy
|
46
46
|
host.salt_modules = [state]
|
47
47
|
|
48
48
|
assert_not host.save
|
49
|
-
|
49
|
+
assert_includes host.errors.full_messages, 'Salt states must be in the environment of the host'
|
50
50
|
end
|
51
51
|
|
52
52
|
test '#configuration? considers salt' do
|
@@ -60,12 +60,12 @@ module ForemanSalt
|
|
60
60
|
before do
|
61
61
|
@host = FactoryBot.create(:host, :managed)
|
62
62
|
@host.salt_proxy = @proxy
|
63
|
-
stub_request(:post, "#{@proxy.url}/salt/autosign_key/asdfasdfasfasdf")
|
64
|
-
to_return(status: 200, body:
|
63
|
+
stub_request(:post, "#{@proxy.url}/salt/autosign_key/asdfasdfasfasdf")
|
64
|
+
.to_return(status: 200, body: '', headers: {})
|
65
65
|
end
|
66
66
|
|
67
67
|
test 'host autosign is created when host is built' do
|
68
|
-
autosign_key =
|
68
|
+
autosign_key = 'asdfasdfasfasdf'
|
69
69
|
@host.expects(:generate_provisioning_key).returns(autosign_key)
|
70
70
|
@host.build = true
|
71
71
|
assert @host.save!
|
@@ -81,42 +81,42 @@ module ForemanSalt
|
|
81
81
|
end
|
82
82
|
|
83
83
|
test 'host returns autosign when deriving salt grains' do
|
84
|
-
autosign_key =
|
84
|
+
autosign_key = 'asdfasdfasfasdf'
|
85
85
|
expected_hash = { @host.autosign_grain_name => autosign_key }
|
86
86
|
@host.salt_autosign_key = autosign_key
|
87
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
87
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
88
88
|
end
|
89
89
|
|
90
90
|
test 'host returns empty hash when deriving salt grains without any given' do
|
91
91
|
expected_hash = {}
|
92
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
92
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
93
93
|
end
|
94
94
|
|
95
95
|
test 'host returns empty hash when deriving salt grains without autosign' do
|
96
96
|
expected_hash = {}
|
97
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
97
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: false) }
|
98
98
|
end
|
99
99
|
|
100
100
|
test 'host returns host param grains when deriving salt grains' do
|
101
|
-
expected_hash = { "Some key":
|
101
|
+
expected_hash = { "Some key": 'Some value', "Another key": 'An extraordinary value' }
|
102
102
|
@host.host_params[@host.host_params_grains_name] = expected_hash
|
103
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
103
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: false) }
|
104
104
|
end
|
105
105
|
|
106
106
|
test 'host returns only host param grains when deriving salt grains' do
|
107
|
-
expected_hash = { "Some key":
|
107
|
+
expected_hash = { "Some key": 'Some value', "Another key": 'An extraordinary value' }
|
108
108
|
@host.host_params[@host.host_params_grains_name] = expected_hash
|
109
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
109
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
110
110
|
end
|
111
111
|
|
112
112
|
test 'host returns host param grains plus autosign when deriving salt grains' do
|
113
|
-
autosign_key =
|
114
|
-
host_param_grains = { "Some key":
|
115
|
-
"Another key":
|
113
|
+
autosign_key = 'asdfasdfasfasdf'
|
114
|
+
host_param_grains = { "Some key": 'Some value',
|
115
|
+
"Another key": 'An extraordinary value' }
|
116
116
|
expected_hash = host_param_grains.merge(@host.autosign_grain_name => autosign_key)
|
117
117
|
@host.salt_autosign_key = autosign_key
|
118
118
|
@host.host_params[@host.host_params_grains_name] = host_param_grains
|
119
|
-
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(:
|
119
|
+
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -10,19 +10,19 @@ module ForemanSalt
|
|
10
10
|
test 'host group has a salt smart proxy' do
|
11
11
|
hostgroup = FactoryBot.create :hostgroup
|
12
12
|
hostgroup.salt_proxy = @proxy
|
13
|
-
|
13
|
+
assert_includes hostgroup.salt_proxy.features.map(&:name), 'Salt'
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'nested host group inherits salt modules from parent' do
|
17
17
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
18
|
-
child = FactoryBot.create :hostgroup, :
|
18
|
+
child = FactoryBot.create :hostgroup, parent: parent
|
19
19
|
assert_equal [], parent.all_salt_modules - child.all_salt_modules
|
20
20
|
end
|
21
21
|
|
22
22
|
test 'child host group inherits salt proxy from child parent' do
|
23
23
|
parent = FactoryBot.create :hostgroup
|
24
|
-
child_one = FactoryBot.create :hostgroup, :
|
25
|
-
child_two = FactoryBot.create :hostgroup, :
|
24
|
+
child_one = FactoryBot.create :hostgroup, parent: parent, salt_proxy: @proxy
|
25
|
+
child_two = FactoryBot.create :hostgroup, parent: child_one
|
26
26
|
assert_not_nil parent
|
27
27
|
assert_not_nil child_one
|
28
28
|
assert_not_nil child_two
|
@@ -34,8 +34,8 @@ module ForemanSalt
|
|
34
34
|
test 'child host group inherits salt environment from child parent' do
|
35
35
|
environment = FactoryBot.create :salt_environment
|
36
36
|
parent = FactoryBot.create :hostgroup
|
37
|
-
child_one = FactoryBot.create :hostgroup, :
|
38
|
-
child_two = FactoryBot.create :hostgroup, :
|
37
|
+
child_one = FactoryBot.create :hostgroup, parent: parent, salt_environment: environment
|
38
|
+
child_two = FactoryBot.create :hostgroup, parent: child_one
|
39
39
|
assert_not_nil parent
|
40
40
|
assert_not_nil child_one
|
41
41
|
assert_not_nil child_two
|
@@ -46,8 +46,8 @@ module ForemanSalt
|
|
46
46
|
|
47
47
|
test 'child and parent salt modules are combined' do
|
48
48
|
environment = FactoryBot.create :salt_environment
|
49
|
-
parent = FactoryBot.create :hostgroup, :with_salt_modules, :
|
50
|
-
child = FactoryBot.create :hostgroup, :with_salt_modules, :
|
49
|
+
parent = FactoryBot.create :hostgroup, :with_salt_modules, salt_environment: environment
|
50
|
+
child = FactoryBot.create :hostgroup, :with_salt_modules, salt_environment: environment, parent: parent
|
51
51
|
|
52
52
|
total = parent.salt_modules.count + child.salt_modules.count
|
53
53
|
assert_equal total, child.all_salt_modules.count
|
@@ -55,21 +55,21 @@ module ForemanSalt
|
|
55
55
|
|
56
56
|
test 'child doesnt get modules from outside its environment' do
|
57
57
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
58
|
-
child = FactoryBot.create :hostgroup, :with_salt_modules, :
|
58
|
+
child = FactoryBot.create :hostgroup, :with_salt_modules, parent: parent
|
59
59
|
assert_equal child.salt_modules.count, child.all_salt_modules.count
|
60
60
|
end
|
61
61
|
|
62
62
|
test 'inheritance when only parent has modules' do
|
63
63
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
64
|
-
child_one = FactoryBot.create :hostgroup, :
|
65
|
-
child_two = FactoryBot.create :hostgroup, :
|
64
|
+
child_one = FactoryBot.create :hostgroup, parent: parent
|
65
|
+
child_two = FactoryBot.create :hostgroup, parent: child_one
|
66
66
|
assert_empty parent.all_salt_modules - child_two.all_salt_modules
|
67
67
|
end
|
68
68
|
|
69
69
|
test 'inheritance when no parents have modules' do
|
70
70
|
parent = FactoryBot.create :hostgroup
|
71
|
-
child_one = FactoryBot.create :hostgroup, :
|
72
|
-
child_two = FactoryBot.create :hostgroup, :with_salt_modules, :
|
71
|
+
child_one = FactoryBot.create :hostgroup, parent: parent
|
72
|
+
child_two = FactoryBot.create :hostgroup, :with_salt_modules, parent: child_one
|
73
73
|
assert child_two.all_salt_modules.any?
|
74
74
|
end
|
75
75
|
end
|
@@ -13,27 +13,27 @@ module ForemanSalt
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test 'importing report creates a host' do
|
16
|
-
assert_not Host.
|
16
|
+
assert_not Host.find_by(name: @host)
|
17
17
|
ForemanSalt::ReportImporter.import(@report)
|
18
|
-
assert Host.
|
18
|
+
assert Host.find_by(name: @host)
|
19
19
|
end
|
20
20
|
|
21
21
|
test 'importing report updates host status' do
|
22
22
|
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
|
23
23
|
ForemanSalt::ReportImporter.import(@report)
|
24
|
-
assert Host.
|
24
|
+
assert Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus).error?
|
25
25
|
end
|
26
26
|
|
27
27
|
test 'importing report has correct status' do
|
28
28
|
ForemanSalt::ReportImporter.import(@report)
|
29
|
-
status = Host.
|
30
|
-
assert_equal status['applied']
|
31
|
-
assert_equal status['failed']
|
29
|
+
status = Host.find_by(name: @host).reports.last.status
|
30
|
+
assert_equal(9, status['applied'])
|
31
|
+
assert_equal(3, status['failed'])
|
32
32
|
end
|
33
33
|
|
34
34
|
test 'report has salt origin and expected content' do
|
35
35
|
ForemanSalt::ReportImporter.import(@report)
|
36
|
-
report = Host.
|
36
|
+
report = Host.find_by(name: @host).reports.last
|
37
37
|
assert_equal 'Salt', report.origin
|
38
38
|
assert_equal 'pkg_|-postfix_|-postfix_|-installed', report.logs.first.source.value
|
39
39
|
assert_equal 'Package postfix is already installed.', report.logs.first.message.value
|
@@ -41,11 +41,11 @@ module ForemanSalt
|
|
41
41
|
|
42
42
|
test 'report with pchanges has salt origin and expected content' do
|
43
43
|
ForemanSalt::ReportImporter.import(@report_pchanges)
|
44
|
-
report = Host.
|
44
|
+
report = Host.find_by(name: @host).reports.last
|
45
45
|
status = report.status
|
46
46
|
assert_equal 'Salt', report.origin
|
47
47
|
assert_equal 'file_|-/etc/motd_|-/etc/motd_|-managed', report.logs.first.source.value
|
48
|
-
assert_equal status['pending']
|
48
|
+
assert_equal(1, status['pending'])
|
49
49
|
end
|
50
50
|
|
51
51
|
test 'import returns Array of reports including host and its name' do
|
data/test/unit/salt_keys_test.rb
CHANGED
@@ -7,7 +7,7 @@ class SaltKeysTest < ActiveSupport::TestCase
|
|
7
7
|
# Fix for 1.8.7 OpenStruct http://stackoverflow.com/questions/9079441/populate-select-tag-ruby-rails
|
8
8
|
OpenStruct.__send__(:define_method, :id) { @table[:id] }
|
9
9
|
|
10
|
-
@proxy = OpenStruct.new(:
|
10
|
+
@proxy = OpenStruct.new(id: 1, url: 'http://dummy.example.com:9090')
|
11
11
|
|
12
12
|
ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
|
13
13
|
'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
|
@@ -38,7 +38,7 @@ class SaltKeysTest < ActiveSupport::TestCase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'finds a key by name' do
|
41
|
-
assert_equal ForemanSalt::SmartProxies::SaltKeys.find(@proxy, 'saltstack.example.com').name
|
41
|
+
assert_equal('saltstack.example.com', ForemanSalt::SmartProxies::SaltKeys.find(@proxy, 'saltstack.example.com').name)
|
42
42
|
end
|
43
43
|
|
44
44
|
test 'find keys by state' do
|
@@ -6,12 +6,12 @@ class SaltModulesTest < ActiveSupport::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'salt module has a valid name' do
|
9
|
-
salt_module = ForemanSalt::SaltModule.new(:
|
9
|
+
salt_module = ForemanSalt::SaltModule.new(name: 'foo.bar.baz')
|
10
10
|
assert_valid salt_module
|
11
11
|
end
|
12
12
|
|
13
13
|
test 'salt module has invalid name' do
|
14
|
-
salt_module = ForemanSalt::SaltModule.new(:
|
14
|
+
salt_module = ForemanSalt::SaltModule.new(name: '&bad$name')
|
15
15
|
refute_valid salt_module, :name, /alphanumeric/
|
16
16
|
end
|
17
17
|
end
|
@@ -7,25 +7,25 @@ class SaltVariablesTest < ActiveSupport::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'salt variable has a salt module' do
|
10
|
-
salt_variable = ForemanSalt::SaltVariable.new(:
|
10
|
+
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)
|
11
11
|
assert_valid salt_variable
|
12
|
-
|
12
|
+
assert salt_variable.salt?
|
13
13
|
assert_equal @state.id, salt_variable.salt_module.id
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'salt variable is referencing a LookupValue' do
|
17
|
-
salt_variable = ForemanSalt::SaltVariable.new(:
|
17
|
+
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)
|
18
18
|
assert salt_variable.lookup_values.count.zero?
|
19
|
-
LookupValue.create(:
|
20
|
-
|
19
|
+
LookupValue.create(value: '[1.2.3.4,2.3.4.5]', match: 'domain = mydomain.net', lookup_key: salt_variable)
|
20
|
+
assert_equal(1, salt_variable.lookup_values.count)
|
21
21
|
end
|
22
22
|
|
23
23
|
test 'should cast default_value to hash' do
|
24
|
-
salt_variable = ForemanSalt::SaltVariable.new(:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
24
|
+
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key',
|
25
|
+
salt_module_id: @state.id,
|
26
|
+
key_type: 'hash',
|
27
|
+
default_value: "{\r\n \"bat\": \"man\"\r\n}\r\n",
|
28
|
+
override: true)
|
29
29
|
salt_variable.save
|
30
30
|
assert salt_variable.default_value.is_a?(Hash)
|
31
31
|
end
|