foreman_salt 16.0.0 → 16.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -3
- data/app/controllers/foreman_salt/state_importer.rb +2 -2
- data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +1 -1
- data/db/migrate/20150411003302_add_environments_to_modules.rb +1 -1
- data/lib/foreman_salt/version.rb +1 -1
- data/test/functional/api/v2/salt_autosign_controller_test.rb +3 -0
- data/test/functional/api/v2/salt_environments_controller_test.rb +3 -0
- data/test/functional/api/v2/salt_keys_controller_test.rb +3 -0
- data/test/functional/api/v2/salt_states_controller_test.rb +8 -0
- data/test/functional/api/v2/salt_variables_controller_test.rb +3 -0
- data/test/functional/hosts_controller_test.rb +2 -0
- data/test/functional/minions_controller_test.rb +14 -0
- data/test/integration/hosts_js_test.rb +12 -6
- data/test/integration/salt_autosign_test.rb +5 -1
- data/test/integration/salt_environment_test.rb +3 -0
- data/test/integration/salt_keys_test.rb +6 -0
- data/test/integration/salt_module_test.rb +4 -0
- data/test/integration/salt_variable_test.rb +3 -0
- data/test/unit/grains_importer_test.rb +2 -0
- data/test/unit/host_extensions_test.rb +16 -1
- data/test/unit/hostgroup_extensions_test.rb +9 -1
- data/test/unit/report_importer_test.rb +10 -2
- data/test/unit/salt_modules_test.rb +2 -0
- data/test/unit/salt_variables_test.rb +6 -2
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95381aab8500525c98ddc2478fbc3b1026df4877a258cbd33118443420056ba3
|
4
|
+
data.tar.gz: 8a6e0a1d5de930a51ac2a30b3d1bafa45bf5a401df62ab9617a793620a3bc318
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df537c8b257cf3e90b62713849ce48424e77262408aa82c71cc09df958ab3593e0969677fa22e9f86a21720eb6114a2457186544be8cb6fe7456117cd8281d9
|
7
|
+
data.tar.gz: 0fec2f56e2733ee848f6958484cd38641a4450408665547ae8b3d551ce58e293f73a3cb700c40d490e91c8f202d7a73995fc2cdca7fa4696876a1e09c6f22d0b
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@ begin
|
|
4
4
|
rescue LoadError
|
5
5
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
6
|
end
|
7
|
+
|
7
8
|
begin
|
8
9
|
require 'rdoc/task'
|
9
10
|
rescue LoadError
|
@@ -20,9 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
22
|
end
|
22
23
|
|
23
|
-
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
|
-
load 'rails/tasks/engine.rake'
|
25
|
-
|
26
24
|
Bundler::GemHelper.install_tasks
|
27
25
|
|
28
26
|
require 'rake/testtask'
|
@@ -34,4 +32,12 @@ Rake::TestTask.new(:test) do |t|
|
|
34
32
|
t.verbose = false
|
35
33
|
end
|
36
34
|
|
35
|
+
begin
|
36
|
+
require 'rubocop/rake_task'
|
37
|
+
rescue LoadError
|
38
|
+
# Test group disabled
|
39
|
+
else
|
40
|
+
RuboCop::RakeTask.new
|
41
|
+
end
|
42
|
+
|
37
43
|
task default: :test
|
@@ -63,11 +63,11 @@ module ForemanSalt
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def clean_orphans
|
66
|
-
SaltModule.all.
|
66
|
+
SaltModule.all.find_each do |state|
|
67
67
|
state.destroy if state.salt_environments.empty?
|
68
68
|
end
|
69
69
|
|
70
|
-
SaltEnvironment.all.
|
70
|
+
SaltEnvironment.all.find_each do |environment|
|
71
71
|
environment.destroy if environment.salt_modules.empty?
|
72
72
|
end
|
73
73
|
end
|
@@ -6,7 +6,7 @@ class AddEnvironmentsToModules < ActiveRecord::Migration[4.2]
|
|
6
6
|
end
|
7
7
|
|
8
8
|
environments = ForemanSalt::SaltEnvironment.all
|
9
|
-
ForemanSalt::SaltModule.all.
|
9
|
+
ForemanSalt::SaltModule.all.find_each do |state|
|
10
10
|
state.salt_environments << environments
|
11
11
|
end
|
12
12
|
end
|
data/lib/foreman_salt/version.rb
CHANGED
@@ -13,18 +13,21 @@ module ForemanSalt
|
|
13
13
|
|
14
14
|
test 'should get index' do
|
15
15
|
get :index, params: { smart_proxy_id: @proxy.id }
|
16
|
+
|
16
17
|
assert_response :success
|
17
18
|
end
|
18
19
|
|
19
20
|
test 'should create autosign' do
|
20
21
|
ProxyAPI::Salt.any_instance.expects(:autosign_create).once.returns(true)
|
21
22
|
post :create, params: { smart_proxy_id: @proxy.id, record: 'unicorn.example.com' }
|
23
|
+
|
22
24
|
assert_response :success
|
23
25
|
end
|
24
26
|
|
25
27
|
test 'should delete autosign' do
|
26
28
|
ProxyAPI::Salt.any_instance.expects(:autosign_remove).once.returns(true)
|
27
29
|
delete :destroy, params: { smart_proxy_id: @proxy.id, record: 'unicorn.example.com' }
|
30
|
+
|
28
31
|
assert_response :success
|
29
32
|
end
|
30
33
|
end
|
@@ -6,6 +6,7 @@ module ForemanSalt
|
|
6
6
|
class SaltEnvironmentsControllerTest < ActionController::TestCase
|
7
7
|
test 'should get index' do
|
8
8
|
get :index
|
9
|
+
|
9
10
|
assert_response :success
|
10
11
|
assert_template 'api/v2/salt_environments/index'
|
11
12
|
end
|
@@ -13,12 +14,14 @@ module ForemanSalt
|
|
13
14
|
test 'should show environment' do
|
14
15
|
environment = ForemanSalt::SaltEnvironment.create(name: 'foo')
|
15
16
|
get :show, params: { id: environment.id }
|
17
|
+
|
16
18
|
assert_response :success
|
17
19
|
assert_template 'api/v2/salt_environments/show'
|
18
20
|
end
|
19
21
|
|
20
22
|
test 'should create environment' do
|
21
23
|
post :create, params: { environment: { name: 'unicorn' } }
|
24
|
+
|
22
25
|
assert_response :success
|
23
26
|
assert ForemanSalt::SaltEnvironment.find_by(name: 'unicorn')
|
24
27
|
assert_template 'api/v2/salt_environments/create'
|
@@ -13,18 +13,21 @@ module ForemanSalt
|
|
13
13
|
|
14
14
|
test 'should get index' do
|
15
15
|
get :index, params: { smart_proxy_id: @proxy.id }
|
16
|
+
|
16
17
|
assert_response :success
|
17
18
|
end
|
18
19
|
|
19
20
|
test 'should update keys' do
|
20
21
|
ProxyAPI::Salt.any_instance.expects(:key_accept).once.returns(true)
|
21
22
|
put :update, params: { smart_proxy_id: @proxy.id, name: 'saltstack.example.com', state: 'accepted' }
|
23
|
+
|
22
24
|
assert_response :success
|
23
25
|
end
|
24
26
|
|
25
27
|
test 'should delete keys' do
|
26
28
|
ProxyAPI::Salt.any_instance.expects(:key_delete).once.returns(true)
|
27
29
|
delete :destroy, params: { smart_proxy_id: @proxy.id, name: 'saltstack.example.com' }
|
30
|
+
|
28
31
|
assert_response :success
|
29
32
|
end
|
30
33
|
end
|
@@ -6,6 +6,7 @@ module ForemanSalt
|
|
6
6
|
class SaltStatesControllerTest < ActionController::TestCase
|
7
7
|
test 'should get index' do
|
8
8
|
get :index
|
9
|
+
|
9
10
|
assert_response :success
|
10
11
|
assert_template 'api/v2/salt_states/index'
|
11
12
|
end
|
@@ -13,12 +14,14 @@ module ForemanSalt
|
|
13
14
|
test 'should show state' do
|
14
15
|
state = ForemanSalt::SaltModule.create(name: 'foo.bar.baz')
|
15
16
|
get :show, params: { id: state.id }
|
17
|
+
|
16
18
|
assert_response :success
|
17
19
|
assert_template 'api/v2/salt_states/show'
|
18
20
|
end
|
19
21
|
|
20
22
|
test 'should create state' do
|
21
23
|
post :create, params: { state: { name: 'unicorn' } }
|
24
|
+
|
22
25
|
assert_response :success
|
23
26
|
assert ForemanSalt::SaltModule.find_by(name: 'unicorn')
|
24
27
|
assert_template 'api/v2/salt_states/create'
|
@@ -48,12 +51,14 @@ module ForemanSalt
|
|
48
51
|
|
49
52
|
@states.each do |env, states|
|
50
53
|
environment = ::ForemanSalt::SaltEnvironment.find_by(name: env)
|
54
|
+
|
51
55
|
assert_empty environment.salt_modules.map(&:name) - states
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
59
|
test 'should import only from a given environment' do
|
56
60
|
post :import, params: { smart_proxy_id: @proxy.id, salt_environments: ['env2'] }
|
61
|
+
|
57
62
|
assert_response :success
|
58
63
|
assert_not ::ForemanSalt::SaltEnvironment.where(name: 'env1').first
|
59
64
|
assert ::ForemanSalt::SaltEnvironment.where(name: 'env2').first
|
@@ -64,6 +69,7 @@ module ForemanSalt
|
|
64
69
|
state = FactoryBot.create :salt_module, salt_environments: [env]
|
65
70
|
|
66
71
|
post :import, params: { smart_proxy_id: @proxy.id, actions: ['add'] }
|
72
|
+
|
67
73
|
assert_response :success
|
68
74
|
assert ::ForemanSalt::SaltModule.where(id: state).first
|
69
75
|
assert ::ForemanSalt::SaltModule.where(name: 'state1').first
|
@@ -72,6 +78,7 @@ module ForemanSalt
|
|
72
78
|
test 'should limit actions to remove' do
|
73
79
|
state = FactoryBot.create :salt_module
|
74
80
|
post :import, params: { smart_proxy_id: @proxy.id, actions: ['remove'] }
|
81
|
+
|
75
82
|
assert_response :success
|
76
83
|
assert_not ::ForemanSalt::SaltModule.where(id: state).first
|
77
84
|
assert_not ::ForemanSalt::SaltModule.where(name: 'state1').first
|
@@ -79,6 +86,7 @@ module ForemanSalt
|
|
79
86
|
|
80
87
|
test 'dryrun should do nothing' do
|
81
88
|
post :import, params: { smart_proxy_id: @proxy.id, dryrun: true }
|
89
|
+
|
82
90
|
assert_response :success
|
83
91
|
assert_not ::ForemanSalt::SaltModule.all.any?
|
84
92
|
assert_not ::ForemanSalt::SaltEnvironment.all.any?
|
@@ -14,12 +14,14 @@ module ForemanSalt
|
|
14
14
|
test 'should get index' do
|
15
15
|
get :index, session: set_session_user
|
16
16
|
response = JSON.parse(@response.body)
|
17
|
+
|
17
18
|
assert_not_empty response['results']
|
18
19
|
assert_response :success
|
19
20
|
end
|
20
21
|
|
21
22
|
test 'should destroy' do
|
22
23
|
delete :destroy, params: { id: @variable.id }, session: set_session_user
|
24
|
+
|
23
25
|
assert_response :ok
|
24
26
|
assert_not SaltVariable.exists?(@variable.id)
|
25
27
|
end
|
@@ -27,6 +29,7 @@ module ForemanSalt
|
|
27
29
|
test 'should create' do
|
28
30
|
params = { key: 'test name', salt_state_id: FactoryBot.create(:salt_module).id }
|
29
31
|
post :create, params: params, session: set_session_user
|
32
|
+
|
30
33
|
assert_response :success
|
31
34
|
end
|
32
35
|
end
|
@@ -21,6 +21,7 @@ module ForemanSalt
|
|
21
21
|
|
22
22
|
post :update_multiple_salt_master, params: params,
|
23
23
|
session: set_session_user.merge(user: users(:one).id)
|
24
|
+
|
24
25
|
assert_response :forbidden
|
25
26
|
end
|
26
27
|
|
@@ -79,6 +80,7 @@ module ForemanSalt
|
|
79
80
|
|
80
81
|
post :update_multiple_salt_environment, params: params,
|
81
82
|
session: set_session_user.merge(user: users(:one).id)
|
83
|
+
|
82
84
|
assert_response :forbidden
|
83
85
|
end
|
84
86
|
|
@@ -18,9 +18,11 @@ module ForemanSalt
|
|
18
18
|
|
19
19
|
test 'salt smart proxy should get salt external node' do
|
20
20
|
get :node, params: { id: @host, format: 'yml' }
|
21
|
+
|
21
22
|
assert_response :success
|
22
23
|
|
23
24
|
res = YAML.safe_load(@response.body)
|
25
|
+
|
24
26
|
assert_equal('different', res['parameters']['parameter1'])
|
25
27
|
end
|
26
28
|
|
@@ -28,9 +30,11 @@ module ForemanSalt
|
|
28
30
|
Setting['salt_namespace_pillars'] = true
|
29
31
|
|
30
32
|
get :node, params: { id: @host, format: 'yml' }
|
33
|
+
|
31
34
|
assert_response :success
|
32
35
|
|
33
36
|
res = YAML.safe_load(@response.body)
|
37
|
+
|
34
38
|
assert_equal('different', res['parameters']['foreman']['parameter1'])
|
35
39
|
end
|
36
40
|
|
@@ -40,9 +44,11 @@ module ForemanSalt
|
|
40
44
|
@host.salt_modules << var.salt_module
|
41
45
|
|
42
46
|
get :node, params: { id: @host, format: 'yml' }
|
47
|
+
|
43
48
|
assert_response :success
|
44
49
|
|
45
50
|
res = YAML.safe_load(@response.body)
|
51
|
+
|
46
52
|
assert_equal res['parameters'][var.key], var.value
|
47
53
|
end
|
48
54
|
|
@@ -52,9 +58,11 @@ module ForemanSalt
|
|
52
58
|
@host.salt_modules << var.salt_module
|
53
59
|
|
54
60
|
get :node, params: { id: @host, format: 'yml' }
|
61
|
+
|
55
62
|
assert_response :success
|
56
63
|
|
57
64
|
res = YAML.safe_load(@response.body)
|
65
|
+
|
58
66
|
assert_equal res['parameters']['parameter1'], var.value
|
59
67
|
end
|
60
68
|
|
@@ -70,9 +78,11 @@ module ForemanSalt
|
|
70
78
|
@host.salt_modules << var.salt_module
|
71
79
|
|
72
80
|
get :node, params: { id: @host, format: 'yml' }
|
81
|
+
|
73
82
|
assert_response :success
|
74
83
|
|
75
84
|
res = YAML.safe_load(@response.body)
|
85
|
+
|
76
86
|
assert_equal res['parameters']['parameter1'], value2.value
|
77
87
|
end
|
78
88
|
|
@@ -87,9 +97,11 @@ module ForemanSalt
|
|
87
97
|
@host2.salt_modules << var.salt_module
|
88
98
|
|
89
99
|
get :node, params: { id: @host2, format: 'yml' }
|
100
|
+
|
90
101
|
assert_response :success
|
91
102
|
|
92
103
|
res = YAML.safe_load(@response.body)
|
104
|
+
|
93
105
|
assert_equal res['parameters']['parameter1'], value2.value
|
94
106
|
end
|
95
107
|
|
@@ -104,9 +116,11 @@ module ForemanSalt
|
|
104
116
|
var.salt_module.salt_environments << @host2.salt_environment
|
105
117
|
@host2.salt_modules << var.salt_module
|
106
118
|
get :node, params: { id: @host2, format: 'yml' }
|
119
|
+
|
107
120
|
assert_response :success
|
108
121
|
|
109
122
|
res = YAML.safe_load(@response.body)
|
123
|
+
|
110
124
|
assert_equal res['parameters']['parameter1'], var.value
|
111
125
|
end
|
112
126
|
end
|
@@ -29,23 +29,26 @@ module ForemanSalt
|
|
29
29
|
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
|
30
30
|
|
31
31
|
# Dropdown visible?
|
32
|
-
|
32
|
+
assert_predicate multiple_actions_div.find('.dropdown-toggle'), :visible?
|
33
33
|
multiple_actions_div.find('.dropdown-toggle').click
|
34
|
-
|
34
|
+
|
35
|
+
assert_predicate multiple_actions_div.find('ul'), :visible?
|
35
36
|
|
36
37
|
# Hosts are added to cookie
|
37
38
|
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
|
39
|
+
|
38
40
|
assert_includes(host_ids_on_cookie, @host.id)
|
39
41
|
|
40
42
|
within('#submit_multiple') do
|
41
43
|
click_on('Change Salt Master')
|
42
44
|
end
|
43
45
|
|
44
|
-
|
46
|
+
assert_predicate index_modal, :visible?, 'Modal window was shown'
|
45
47
|
page.find('#proxy_proxy_id').find("option[value='#{@host.salt_proxy.id}']").select_option
|
46
48
|
|
47
49
|
# remove hosts cookie on submit
|
48
50
|
index_modal.find('.btn-primary').click
|
51
|
+
|
49
52
|
assert_current_path hosts_path
|
50
53
|
assert_empty(get_me_the_cookie('_ForemanSelectedhosts'))
|
51
54
|
end
|
@@ -58,23 +61,26 @@ module ForemanSalt
|
|
58
61
|
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
|
59
62
|
|
60
63
|
# Dropdown visible?
|
61
|
-
|
64
|
+
assert_predicate multiple_actions_div.find('.dropdown-toggle'), :visible?
|
62
65
|
multiple_actions_div.find('.dropdown-toggle').click
|
63
|
-
|
66
|
+
|
67
|
+
assert_predicate multiple_actions_div.find('ul'), :visible?
|
64
68
|
|
65
69
|
# Hosts are added to cookie
|
66
70
|
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
|
71
|
+
|
67
72
|
assert_includes(host_ids_on_cookie, @host.id)
|
68
73
|
|
69
74
|
within('#submit_multiple') do
|
70
75
|
click_on('Change Salt Environment')
|
71
76
|
end
|
72
77
|
|
73
|
-
|
78
|
+
assert_predicate index_modal, :visible?, 'Modal window was shown'
|
74
79
|
page.find('#salt_environment_id').find("option[value='#{@host.salt_environment.id}']").select_option
|
75
80
|
|
76
81
|
# remove hosts cookie on submit
|
77
82
|
index_modal.find('.btn-primary').click
|
83
|
+
|
78
84
|
assert_current_path hosts_path
|
79
85
|
assert_empty(get_me_the_cookie('_ForemanSelectedhosts'))
|
80
86
|
end
|
@@ -17,19 +17,23 @@ module ForemanSalt
|
|
17
17
|
|
18
18
|
test 'smart proxy details has autosign link' do
|
19
19
|
visit smart_proxy_path(@proxy)
|
20
|
+
|
20
21
|
assert page.has_link? 'Salt Autosign'
|
21
22
|
click_link 'Salt Autosign'
|
23
|
+
|
22
24
|
assert page.has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
|
23
25
|
end
|
24
26
|
|
25
27
|
test 'index page' do
|
26
28
|
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)
|
27
|
-
|
29
|
+
|
30
|
+
assert_predicate find_link('Keys'), :visible?, 'Keys is not visible'
|
28
31
|
assert has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
|
29
32
|
end
|
30
33
|
|
31
34
|
test 'has list of autosign' do
|
32
35
|
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)
|
36
|
+
|
33
37
|
assert has_content?('foo.example.com'), 'Missing autosign entry on index page'
|
34
38
|
end
|
35
39
|
end
|
@@ -5,12 +5,14 @@ module ForemanSalt
|
|
5
5
|
class SaltEnvironmentTest < IntegrationTestWithJavascript
|
6
6
|
test 'index page' do
|
7
7
|
FactoryBot.create_list :salt_environment, 5
|
8
|
+
|
8
9
|
assert_index_page(salt_environments_path, 'Salt Environment', 'New Salt Environment')
|
9
10
|
end
|
10
11
|
|
11
12
|
test 'create new page' do
|
12
13
|
assert_new_button(salt_environments_path, 'New Salt Environment', new_salt_environment_path)
|
13
14
|
fill_in 'foreman_salt_salt_environment_name', with: 'common'
|
15
|
+
|
14
16
|
assert_submit_button(salt_environments_path)
|
15
17
|
assert page.has_link? 'common'
|
16
18
|
end
|
@@ -20,6 +22,7 @@ module ForemanSalt
|
|
20
22
|
visit salt_environments_path
|
21
23
|
click_link salt_environment.name
|
22
24
|
fill_in 'foreman_salt_salt_environment_name', with: 'some_other_name'
|
25
|
+
|
23
26
|
assert_submit_button(salt_environments_path)
|
24
27
|
assert page.has_link? 'some_other_name'
|
25
28
|
end
|
@@ -20,29 +20,35 @@ module ForemanSalt
|
|
20
20
|
|
21
21
|
test 'smart proxy details has keys link' do
|
22
22
|
visit smart_proxy_path(@proxy)
|
23
|
+
|
23
24
|
assert page.has_link? 'Salt Keys'
|
24
25
|
click_link 'Salt Keys'
|
26
|
+
|
25
27
|
assert page.has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
|
26
28
|
end
|
27
29
|
|
28
30
|
test 'index page' do
|
29
31
|
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)
|
32
|
+
|
30
33
|
assert has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
|
31
34
|
end
|
32
35
|
|
33
36
|
test 'has list of keys' do
|
34
37
|
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)
|
38
|
+
|
35
39
|
assert has_content?('saltclient01.example.com'), 'Missing key on index page'
|
36
40
|
assert has_content?('98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1'), 'Missing fingerprint on index page'
|
37
41
|
end
|
38
42
|
|
39
43
|
test 'has accept link' do
|
40
44
|
ProxyAPI::Salt.any_instance.stubs(:key_accept).returns(true)
|
45
|
+
|
41
46
|
assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Accept', dropdown: true)
|
42
47
|
end
|
43
48
|
|
44
49
|
test 'has reject link' do
|
45
50
|
ProxyAPI::Salt.any_instance.stubs(:key_reject).returns(true)
|
51
|
+
|
46
52
|
assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Reject', dropdown: true)
|
47
53
|
end
|
48
54
|
end
|
@@ -14,12 +14,14 @@ module ForemanSalt
|
|
14
14
|
|
15
15
|
test 'index page' do
|
16
16
|
FactoryBot.create_list :salt_module, 5
|
17
|
+
|
17
18
|
assert_index_page(salt_modules_path, 'Salt State', 'New Salt State')
|
18
19
|
end
|
19
20
|
|
20
21
|
test 'create new page' do
|
21
22
|
assert_new_button(salt_modules_path, 'New Salt State', new_salt_module_path)
|
22
23
|
fill_in 'foreman_salt_salt_module_name', with: 'common'
|
24
|
+
|
23
25
|
assert_submit_button(salt_modules_path)
|
24
26
|
assert page.has_link? 'common'
|
25
27
|
end
|
@@ -29,6 +31,7 @@ module ForemanSalt
|
|
29
31
|
visit salt_modules_path
|
30
32
|
click_link salt_module.name
|
31
33
|
fill_in :foreman_salt_salt_module_name, with: 'some_other_name'
|
34
|
+
|
32
35
|
assert_submit_button(salt_modules_path)
|
33
36
|
assert page.has_link? 'some_other_name'
|
34
37
|
end
|
@@ -50,6 +53,7 @@ module ForemanSalt
|
|
50
53
|
all('input.state_check').each { |checkbox| check(checkbox[:id]) }
|
51
54
|
|
52
55
|
click_button 'Update'
|
56
|
+
|
53
57
|
assert page.has_link? 'state1'
|
54
58
|
end
|
55
59
|
end
|
@@ -9,14 +9,17 @@ module ForemanSalt
|
|
9
9
|
|
10
10
|
test 'index page' do
|
11
11
|
FactoryBot.create_list :salt_variable, 5
|
12
|
+
|
12
13
|
assert_index_page(salt_variables_path, 'Salt Variable', 'New Salt Variable')
|
13
14
|
end
|
14
15
|
|
15
16
|
test 'create new page' do
|
16
17
|
state = FactoryBot.create :salt_module
|
18
|
+
|
17
19
|
assert_new_button(salt_variables_path, 'New Salt Variable', new_salt_variable_path)
|
18
20
|
fill_in 'foreman_salt_salt_variable_key', with: 'mykey'
|
19
21
|
select2(state.name, from: 'foreman_salt_salt_variable_salt_module_id')
|
22
|
+
|
20
23
|
assert_submit_button(salt_variables_path)
|
21
24
|
assert page.has_link? 'mykey'
|
22
25
|
end
|
@@ -28,6 +28,7 @@ module ForemanSalt
|
|
28
28
|
test 'nested facts have valid parents' do
|
29
29
|
parent = ::FactName.find_by(name: 'cpu_flags')
|
30
30
|
children = @imported_host.fact_values.with_fact_parent_id(parent)
|
31
|
+
|
31
32
|
assert_not_empty children
|
32
33
|
assert_empty children.map(&:fact_name).reject { |fact| fact.name =~ /\Acpu_flags#{FactName::SEPARATOR}[0-9]+/ }
|
33
34
|
end
|
@@ -59,6 +60,7 @@ module ForemanSalt
|
|
59
60
|
|
60
61
|
test 'imported host has additional interface' do
|
61
62
|
nic = @imported_host.interfaces.find_by(identifier: 'eth1')
|
63
|
+
|
62
64
|
assert_equal('de:ad:be:ef:07:13', nic.mac)
|
63
65
|
assert_equal('1.2.3.4', nic.ip)
|
64
66
|
end
|
@@ -10,18 +10,21 @@ module ForemanSalt
|
|
10
10
|
test 'host has a salt smart proxy' do
|
11
11
|
host = FactoryBot.create :host
|
12
12
|
host.salt_proxy = @proxy
|
13
|
+
|
13
14
|
assert host.salt_proxy.has_feature? 'Salt'
|
14
15
|
end
|
15
16
|
|
16
17
|
test 'smart_proxy_ids returns salt smart proxy' do
|
17
18
|
host = FactoryBot.create :host
|
18
19
|
host.salt_proxy = @proxy
|
20
|
+
|
19
21
|
assert_includes host.smart_proxy_ids, host.salt_proxy_id
|
20
22
|
end
|
21
23
|
|
22
24
|
test 'host params includes salt_master' do
|
23
25
|
host = FactoryBot.create :host
|
24
26
|
host.salt_proxy = @proxy
|
27
|
+
|
25
28
|
assert host.params.key? 'salt_master'
|
26
29
|
assert_equal host.params['salt_master'], host.salt_master
|
27
30
|
end
|
@@ -31,6 +34,7 @@ module ForemanSalt
|
|
31
34
|
hostgroup.salt_proxy = @proxy
|
32
35
|
host = FactoryBot.create :host, hostgroup: hostgroup
|
33
36
|
host.set_hostgroup_defaults
|
37
|
+
|
34
38
|
assert_equal host.salt_proxy, hostgroup.salt_proxy
|
35
39
|
end
|
36
40
|
|
@@ -51,9 +55,11 @@ module ForemanSalt
|
|
51
55
|
|
52
56
|
test '#configuration? considers salt' do
|
53
57
|
host = FactoryBot.build(:host)
|
58
|
+
|
54
59
|
assert_not host.configuration?
|
55
60
|
host.salt_proxy = @proxy
|
56
|
-
|
61
|
+
|
62
|
+
assert_predicate host, :configuration?
|
57
63
|
end
|
58
64
|
|
59
65
|
context 'autosign handling' do
|
@@ -70,8 +76,10 @@ module ForemanSalt
|
|
70
76
|
autosign_key = 'asdfasdfasfasdf'
|
71
77
|
@host.expects(:generate_provisioning_key).returns(autosign_key)
|
72
78
|
@host.build = true
|
79
|
+
|
73
80
|
assert @host.save!
|
74
81
|
@host.clear_host_parameters_cache!
|
82
|
+
|
75
83
|
assert_equal autosign_key, @host.salt_autosign_key
|
76
84
|
end
|
77
85
|
end
|
@@ -84,6 +92,7 @@ module ForemanSalt
|
|
84
92
|
|
85
93
|
test 'host returns empty hash when deriving salt grains with default autosign' do
|
86
94
|
expected_hash = {}
|
95
|
+
|
87
96
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains }
|
88
97
|
end
|
89
98
|
|
@@ -91,28 +100,33 @@ module ForemanSalt
|
|
91
100
|
autosign_key = 'asdfasdfasfasdf'
|
92
101
|
expected_hash = { @host.autosign_grain_name => autosign_key }
|
93
102
|
@host.salt_autosign_key = autosign_key
|
103
|
+
|
94
104
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
95
105
|
end
|
96
106
|
|
97
107
|
test 'host returns empty hash when deriving salt grains without any given' do
|
98
108
|
expected_hash = {}
|
109
|
+
|
99
110
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
100
111
|
end
|
101
112
|
|
102
113
|
test 'host returns empty hash when deriving salt grains without autosign' do
|
103
114
|
expected_hash = {}
|
115
|
+
|
104
116
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: false) }
|
105
117
|
end
|
106
118
|
|
107
119
|
test 'host returns host param grains when deriving salt grains' do
|
108
120
|
expected_hash = { "Some key": 'Some value', "Another key": 'An extraordinary value' }
|
109
121
|
@host.host_params[@host.host_params_grains_name] = expected_hash
|
122
|
+
|
110
123
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: false) }
|
111
124
|
end
|
112
125
|
|
113
126
|
test 'host returns only host param grains when deriving salt grains' do
|
114
127
|
expected_hash = { "Some key": 'Some value', "Another key": 'An extraordinary value' }
|
115
128
|
@host.host_params[@host.host_params_grains_name] = expected_hash
|
129
|
+
|
116
130
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
117
131
|
end
|
118
132
|
|
@@ -123,6 +137,7 @@ module ForemanSalt
|
|
123
137
|
expected_hash = host_param_grains.merge(@host.autosign_grain_name => autosign_key)
|
124
138
|
@host.salt_autosign_key = autosign_key
|
125
139
|
@host.host_params[@host.host_params_grains_name] = host_param_grains
|
140
|
+
|
126
141
|
assert_equal expected_hash, @host.instance_eval { derive_salt_grains(use_autosign: true) }
|
127
142
|
end
|
128
143
|
end
|
@@ -10,12 +10,14 @@ 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
14
|
assert_includes hostgroup.salt_proxy.features.map(&:name), 'Salt'
|
14
15
|
end
|
15
16
|
|
16
17
|
test 'nested host group inherits salt modules from parent' do
|
17
18
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
18
19
|
child = FactoryBot.create :hostgroup, parent: parent
|
20
|
+
|
19
21
|
assert_equal [], parent.all_salt_modules - child.all_salt_modules
|
20
22
|
end
|
21
23
|
|
@@ -23,6 +25,7 @@ module ForemanSalt
|
|
23
25
|
parent = FactoryBot.create :hostgroup
|
24
26
|
child_one = FactoryBot.create :hostgroup, parent: parent, salt_proxy: @proxy
|
25
27
|
child_two = FactoryBot.create :hostgroup, parent: child_one
|
28
|
+
|
26
29
|
assert_not_nil parent
|
27
30
|
assert_not_nil child_one
|
28
31
|
assert_not_nil child_two
|
@@ -36,6 +39,7 @@ module ForemanSalt
|
|
36
39
|
parent = FactoryBot.create :hostgroup
|
37
40
|
child_one = FactoryBot.create :hostgroup, parent: parent, salt_environment: environment
|
38
41
|
child_two = FactoryBot.create :hostgroup, parent: child_one
|
42
|
+
|
39
43
|
assert_not_nil parent
|
40
44
|
assert_not_nil child_one
|
41
45
|
assert_not_nil child_two
|
@@ -50,12 +54,14 @@ module ForemanSalt
|
|
50
54
|
child = FactoryBot.create :hostgroup, :with_salt_modules, salt_environment: environment, parent: parent
|
51
55
|
|
52
56
|
total = parent.salt_modules.count + child.salt_modules.count
|
57
|
+
|
53
58
|
assert_equal total, child.all_salt_modules.count
|
54
59
|
end
|
55
60
|
|
56
61
|
test 'child doesnt get modules from outside its environment' do
|
57
62
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
58
63
|
child = FactoryBot.create :hostgroup, :with_salt_modules, parent: parent
|
64
|
+
|
59
65
|
assert_equal child.salt_modules.count, child.all_salt_modules.count
|
60
66
|
end
|
61
67
|
|
@@ -63,6 +69,7 @@ module ForemanSalt
|
|
63
69
|
parent = FactoryBot.create :hostgroup, :with_salt_modules
|
64
70
|
child_one = FactoryBot.create :hostgroup, parent: parent
|
65
71
|
child_two = FactoryBot.create :hostgroup, parent: child_one
|
72
|
+
|
66
73
|
assert_empty parent.all_salt_modules - child_two.all_salt_modules
|
67
74
|
end
|
68
75
|
|
@@ -70,7 +77,8 @@ module ForemanSalt
|
|
70
77
|
parent = FactoryBot.create :hostgroup
|
71
78
|
child_one = FactoryBot.create :hostgroup, parent: parent
|
72
79
|
child_two = FactoryBot.create :hostgroup, :with_salt_modules, parent: child_one
|
73
|
-
|
80
|
+
|
81
|
+
assert_predicate child_two.all_salt_modules, :any?
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
@@ -16,18 +16,21 @@ module ForemanSalt
|
|
16
16
|
test 'importing report creates a host' do
|
17
17
|
assert_not Host.find_by(name: @host)
|
18
18
|
ForemanSalt::ReportImporter.import(@report)
|
19
|
+
|
19
20
|
assert Host.find_by(name: @host)
|
20
21
|
end
|
21
22
|
|
22
23
|
test 'importing report updates host status' do
|
23
24
|
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
|
24
25
|
ForemanSalt::ReportImporter.import(@report)
|
25
|
-
|
26
|
+
|
27
|
+
assert_predicate Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus), :error?
|
26
28
|
end
|
27
29
|
|
28
30
|
test 'importing report has correct status' do
|
29
31
|
ForemanSalt::ReportImporter.import(@report)
|
30
32
|
status = Host.find_by(name: @host).reports.last.status
|
33
|
+
|
31
34
|
assert_equal(9, status['applied'])
|
32
35
|
assert_equal(3, status['failed'])
|
33
36
|
end
|
@@ -35,6 +38,7 @@ module ForemanSalt
|
|
35
38
|
test 'report has salt origin and expected content' do
|
36
39
|
ForemanSalt::ReportImporter.import(@report)
|
37
40
|
report = Host.find_by(name: @host).reports.last
|
41
|
+
|
38
42
|
assert_equal 'Salt', report.origin
|
39
43
|
assert_equal 'pkg_|-postfix_|-postfix_|-installed', report.logs.first.source.value
|
40
44
|
assert_equal 'Package postfix is already installed.', report.logs.first.message.value
|
@@ -44,6 +48,7 @@ module ForemanSalt
|
|
44
48
|
ForemanSalt::ReportImporter.import(@report_pchanges)
|
45
49
|
report = Host.find_by(name: @host).reports.last
|
46
50
|
status = report.status
|
51
|
+
|
47
52
|
assert_equal 'Salt', report.origin
|
48
53
|
assert_equal 'file_|-/etc/motd_|-/etc/motd_|-managed', report.logs.first.source.value
|
49
54
|
assert_equal(1, status['pending'])
|
@@ -51,8 +56,10 @@ module ForemanSalt
|
|
51
56
|
|
52
57
|
test 'import returns Array of reports including host and its name' do
|
53
58
|
reports = ForemanSalt::ReportImporter.import(@report)
|
59
|
+
|
54
60
|
assert_kind_of Array, reports
|
55
61
|
first = reports.first
|
62
|
+
|
56
63
|
assert_equal 'Salt', first.origin
|
57
64
|
assert_equal @host, first.host.name
|
58
65
|
end
|
@@ -60,7 +67,8 @@ module ForemanSalt
|
|
60
67
|
test 'importing report with unhandled highstate' do
|
61
68
|
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
|
62
69
|
ForemanSalt::ReportImporter.import(@report_unhandled)
|
63
|
-
|
70
|
+
|
71
|
+
assert_predicate Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus), :error?
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
@@ -7,11 +7,13 @@ class SaltModulesTest < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
test 'salt module has a valid name' do
|
9
9
|
salt_module = ForemanSalt::SaltModule.new(name: 'foo.bar.baz')
|
10
|
+
|
10
11
|
assert_valid salt_module
|
11
12
|
end
|
12
13
|
|
13
14
|
test 'salt module has invalid name' do
|
14
15
|
salt_module = ForemanSalt::SaltModule.new(name: '&bad$name')
|
16
|
+
|
15
17
|
refute_valid salt_module, :name, /alphanumeric/
|
16
18
|
end
|
17
19
|
end
|
@@ -8,15 +8,18 @@ class SaltVariablesTest < ActiveSupport::TestCase
|
|
8
8
|
|
9
9
|
test 'salt variable has a salt module' do
|
10
10
|
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)
|
11
|
+
|
11
12
|
assert_valid salt_variable
|
12
|
-
|
13
|
+
assert_predicate salt_variable, :salt?
|
13
14
|
assert_equal @state.id, salt_variable.salt_module.id
|
14
15
|
end
|
15
16
|
|
16
17
|
test 'salt variable is referencing a LookupValue' do
|
17
18
|
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)
|
18
|
-
|
19
|
+
|
20
|
+
assert_predicate salt_variable.lookup_values.count, :zero?
|
19
21
|
LookupValue.create(value: '[1.2.3.4,2.3.4.5]', match: 'domain = mydomain.net', lookup_key: salt_variable)
|
22
|
+
|
20
23
|
assert_equal(1, salt_variable.lookup_values.count)
|
21
24
|
end
|
22
25
|
|
@@ -27,6 +30,7 @@ class SaltVariablesTest < ActiveSupport::TestCase
|
|
27
30
|
default_value: "{\r\n \"bat\": \"man\"\r\n}\r\n",
|
28
31
|
override: true)
|
29
32
|
salt_variable.save
|
33
|
+
|
30
34
|
assert salt_variable.default_value.is_a?(Hash)
|
31
35
|
end
|
32
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_salt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 16.0.
|
4
|
+
version: 16.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Benjamin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '9.0'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '14'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '9.0'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '14'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: foreman-tasks
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,7 +269,7 @@ homepage: https://github.com/theforeman/foreman_salt
|
|
269
269
|
licenses:
|
270
270
|
- GPL-3.0
|
271
271
|
metadata: {}
|
272
|
-
post_install_message:
|
272
|
+
post_install_message:
|
273
273
|
rdoc_options: []
|
274
274
|
require_paths:
|
275
275
|
- lib
|
@@ -284,36 +284,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
- !ruby/object:Gem::Version
|
285
285
|
version: '0'
|
286
286
|
requirements: []
|
287
|
-
rubygems_version: 3.
|
288
|
-
signing_key:
|
287
|
+
rubygems_version: 3.4.10
|
288
|
+
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: Foreman Plug-in for Salt
|
291
291
|
test_files:
|
292
|
-
- test/
|
293
|
-
- test/unit/highstate.json
|
294
|
-
- test/unit/grains_importer_test.rb
|
295
|
-
- test/unit/salt_keys_test.rb
|
296
|
-
- test/unit/report_importer_test.rb
|
297
|
-
- test/unit/hostgroup_extensions_test.rb
|
298
|
-
- test/unit/salt_modules_test.rb
|
299
|
-
- test/unit/highstate_pchanges.json
|
300
|
-
- test/unit/salt_variables_test.rb
|
301
|
-
- test/unit/highstate_unhandled.json
|
302
|
-
- test/functional/salt_modules_controller_test.rb
|
303
|
-
- test/functional/minions_controller_test.rb
|
304
|
-
- test/functional/hosts_controller_test.rb
|
305
|
-
- test/functional/api/v2/salt_keys_controller_test.rb
|
306
|
-
- test/functional/api/v2/salt_states_controller_test.rb
|
292
|
+
- test/factories/foreman_salt_factories.rb
|
307
293
|
- test/functional/api/v2/salt_autosign_controller_test.rb
|
308
294
|
- test/functional/api/v2/salt_environments_controller_test.rb
|
309
295
|
- test/functional/api/v2/salt_hostgroups_controller_test.rb
|
296
|
+
- test/functional/api/v2/salt_keys_controller_test.rb
|
297
|
+
- test/functional/api/v2/salt_states_controller_test.rb
|
310
298
|
- test/functional/api/v2/salt_variables_controller_test.rb
|
299
|
+
- test/functional/hosts_controller_test.rb
|
300
|
+
- test/functional/minions_controller_test.rb
|
301
|
+
- test/functional/salt_modules_controller_test.rb
|
311
302
|
- test/functional/salt_variables_controller_test.rb
|
303
|
+
- test/integration/hosts_js_test.rb
|
312
304
|
- test/integration/salt_autosign_test.rb
|
313
|
-
- test/integration/salt_variable_test.rb
|
314
305
|
- test/integration/salt_environment_test.rb
|
315
306
|
- test/integration/salt_keys_test.rb
|
316
|
-
- test/integration/hosts_js_test.rb
|
317
307
|
- test/integration/salt_module_test.rb
|
308
|
+
- test/integration/salt_variable_test.rb
|
318
309
|
- test/test_plugin_helper.rb
|
319
|
-
- test/
|
310
|
+
- test/unit/grains_importer_test.rb
|
311
|
+
- test/unit/highstate.json
|
312
|
+
- test/unit/highstate_pchanges.json
|
313
|
+
- test/unit/highstate_unhandled.json
|
314
|
+
- test/unit/host_extensions_test.rb
|
315
|
+
- test/unit/hostgroup_extensions_test.rb
|
316
|
+
- test/unit/report_importer_test.rb
|
317
|
+
- test/unit/salt_keys_test.rb
|
318
|
+
- test/unit/salt_modules_test.rb
|
319
|
+
- test/unit/salt_variables_test.rb
|