foreman_salt 4.0.1 → 5.0.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/app/assets/javascripts/foreman_salt/states.js +5 -3
- data/app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb +1 -1
- data/app/controllers/foreman_salt/api/v2/salt_keys_controller.rb +1 -1
- data/app/controllers/foreman_salt/api/v2/salt_states_controller.rb +1 -1
- data/app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb +1 -1
- data/app/controllers/foreman_salt/minions_controller.rb +1 -1
- data/app/controllers/foreman_salt/state_importer.rb +4 -4
- data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +7 -9
- data/app/models/foreman_salt/concerns/host_managed_extensions.rb +7 -2
- data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +3 -0
- data/app/models/foreman_salt/fact_name.rb +3 -1
- data/app/models/foreman_salt/salt_environment.rb +2 -0
- data/app/models/foreman_salt/salt_module.rb +2 -0
- data/app/overrides/salt_modules_selector.rb +2 -2
- data/app/services/foreman_salt/fact_importer.rb +1 -1
- data/app/services/foreman_salt/fact_parser.rb +3 -3
- data/app/services/foreman_salt/report_importer.rb +7 -6
- data/config/routes.rb +3 -3
- data/db/seeds.d/75-salt_seeds.rb +1 -1
- data/lib/foreman_salt/engine.rb +3 -1
- data/lib/foreman_salt/plugin.rb +1 -1
- data/lib/foreman_salt/version.rb +1 -1
- data/test/factories/foreman_salt_factories.rb +1 -1
- data/test/functional/api/v2/salt_states_controller_test.rb +2 -2
- data/test/test_plugin_helper.rb +1 -1
- data/test/unit/host_extensions_test.rb +2 -2
- data/test/unit/hostgroup_extensions_test.rb +1 -1
- data/test/unit/report_importer_test.rb +1 -0
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9868208c4e4fcafc333d26d1328d26fda1aedbe
|
4
|
+
data.tar.gz: 5123aa03c84c55a2b2bcf7781bd20a4c8f8c0bc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3eb26a7c80cfd36770eeaa6fd758641e24942940964c4a97d2e516ecd3e80f59b7806f1828cea71dc3abee4623f30e6056e66df97a6143f12e67087e23244ba
|
7
|
+
data.tar.gz: 2912f3b5f10639dfd156bc5b7b3110fcc18eb732b49c04f1b4e036f2fc32c75916ad739d08456423c8c846c71486651aa73348f401a22e5e87bf49c52c64917e
|
@@ -8,6 +8,8 @@ function update_salt_states(element) {
|
|
8
8
|
var url = $(element).attr('data-url');
|
9
9
|
var data = $("form").serialize().replace('method=put', 'method=post');
|
10
10
|
|
11
|
+
if (url == undefined) return;
|
12
|
+
|
11
13
|
if (url.match('hostgroups')) {
|
12
14
|
data = data + '&hostgroup_id=' + host_id;
|
13
15
|
} else {
|
@@ -18,9 +20,9 @@ function update_salt_states(element) {
|
|
18
20
|
return;
|
19
21
|
}
|
20
22
|
|
21
|
-
|
23
|
+
foreman.tools.showSpinner();
|
22
24
|
$.ajax({
|
23
|
-
type: '
|
25
|
+
type: 'put',
|
24
26
|
url: url,
|
25
27
|
data: data,
|
26
28
|
success: function(request) {
|
@@ -29,7 +31,7 @@ function update_salt_states(element) {
|
|
29
31
|
multiSelectOnLoad();
|
30
32
|
},
|
31
33
|
complete: function() {
|
32
|
-
|
34
|
+
foreman.tools.hideSpinner();
|
33
35
|
}
|
34
36
|
});
|
35
37
|
}
|
@@ -89,7 +89,7 @@ module ForemanSalt
|
|
89
89
|
|
90
90
|
def find_environment
|
91
91
|
if params[:salt_environment_id]
|
92
|
-
@salt_environment = ForemanSalt::SaltEnvironment.find(params[:salt_environment_id])
|
92
|
+
@salt_environment = ForemanSalt::SaltEnvironment.friendly.find(params[:salt_environment_id])
|
93
93
|
fail _('Could not find salt environment with id %s') % params[:salt_environment_id] unless @salt_environment
|
94
94
|
end
|
95
95
|
end
|
@@ -11,7 +11,7 @@ module ForemanSalt
|
|
11
11
|
@hostgroup = Hostgroup.authorized(:view_hostgroups, Hostgroup).find_by_id(params[:hostgroup_id]) || Hostgroup.new(params[:hostgroup])
|
12
12
|
|
13
13
|
if params[:hostgroup][:salt_environment_id].present?
|
14
|
-
@salt_environment = ::ForemanSalt::SaltEnvironment.find(params[:hostgroup][:salt_environment_id])
|
14
|
+
@salt_environment = ::ForemanSalt::SaltEnvironment.friendly.find(params[:hostgroup][:salt_environment_id])
|
15
15
|
load_vars_for_ajax
|
16
16
|
render :partial => 'foreman_salt/salt_modules/host_tab_pane'
|
17
17
|
else
|
@@ -34,7 +34,7 @@ module ForemanSalt
|
|
34
34
|
|
35
35
|
def salt_environment_selected
|
36
36
|
if params[:host][:salt_environment_id].present?
|
37
|
-
@salt_environment = ::ForemanSalt::SaltEnvironment.find(params[:host][:salt_environment_id])
|
37
|
+
@salt_environment = ::ForemanSalt::SaltEnvironment.friendly.find(params[:host][:salt_environment_id])
|
38
38
|
load_ajax_vars
|
39
39
|
render :partial => 'foreman_salt/salt_modules/host_tab_pane'
|
40
40
|
else
|
@@ -46,19 +46,19 @@ module ForemanSalt
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def add_to_environment(states, environment)
|
49
|
-
environment = SaltEnvironment.
|
49
|
+
environment = SaltEnvironment.where(:name => environment).first_or_create
|
50
50
|
|
51
51
|
states.each do |state_name|
|
52
|
-
state = SaltModule.
|
52
|
+
state = SaltModule.where(:name => state_name).first_or_create
|
53
53
|
state.salt_environments << environment unless state.salt_environments.include? environment
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def remove_from_environment(states, environment)
|
58
|
-
return unless (environment = SaltEnvironment.find(environment))
|
58
|
+
return unless (environment = SaltEnvironment.friendly.find(environment))
|
59
59
|
|
60
60
|
states.each do |state_name|
|
61
|
-
state = SaltModule.find(state_name)
|
61
|
+
state = SaltModule.friendly.find(state_name)
|
62
62
|
state.salt_environments.delete(environment) if state
|
63
63
|
end
|
64
64
|
end
|
@@ -7,16 +7,14 @@ module ForemanSalt
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def proxy_actions_with_salt_proxy(proxy, authorizer)
|
10
|
-
|
11
|
-
[
|
12
|
-
if salt
|
13
|
-
display_link_if_authorized(_('Salt Keys'), :controller => 'foreman_salt/salt_keys', :action => 'index', :smart_proxy_id => proxy)
|
14
|
-
end,
|
10
|
+
actions = proxy_actions_without_salt_proxy(proxy, authorizer)
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
if proxy.has_feature?('Salt')
|
13
|
+
actions << display_link_if_authorized(_('Salt Keys'), :controller => 'foreman_salt/salt_keys', :action => 'index', :smart_proxy_id => proxy)
|
14
|
+
actions << display_link_if_authorized(_('Salt Autosign'), :controller => 'foreman_salt/salt_autosign', :action => 'index', :smart_proxy_id => proxy)
|
15
|
+
end
|
16
|
+
|
17
|
+
actions
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -24,6 +24,9 @@ module ForemanSalt
|
|
24
24
|
after_build :delete_salt_key, :if => ->(host) { host.salt_proxy }
|
25
25
|
before_provision :accept_salt_key, :if => ->(host) { host.salt_proxy }
|
26
26
|
before_destroy :delete_salt_key, :if => ->(host) { host.salt_proxy }
|
27
|
+
|
28
|
+
attr_accessible :salt_proxy_id, :salt_proxy_name, :salt_environment_id,
|
29
|
+
:salt_environment_name, :salt_modules, :salt_module_ids
|
27
30
|
end
|
28
31
|
|
29
32
|
def configuration_with_salt?
|
@@ -87,7 +90,8 @@ module ForemanSalt
|
|
87
90
|
def accept_salt_key
|
88
91
|
begin
|
89
92
|
Rails.logger.info("Host #{fqdn} is built, accepting Salt key")
|
90
|
-
ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn)
|
93
|
+
key = ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn)
|
94
|
+
key.accept unless key.nil?
|
91
95
|
rescue Foreman::Exception => e
|
92
96
|
Rails.logger.warn("Unable to accept key for #{fqdn}: #{e}")
|
93
97
|
end
|
@@ -95,7 +99,8 @@ module ForemanSalt
|
|
95
99
|
|
96
100
|
def delete_salt_key
|
97
101
|
begin
|
98
|
-
ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn)
|
102
|
+
key = ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn)
|
103
|
+
key.delete unless key.nil?
|
99
104
|
rescue Foreman::Exception => e
|
100
105
|
Rails.logger.warn("Unable to delete key for #{fqdn}: #{e}")
|
101
106
|
end
|
@@ -13,6 +13,9 @@ module ForemanSalt
|
|
13
13
|
scoped_search :in => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
|
14
14
|
scoped_search :in => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
|
15
15
|
scoped_search :in => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
|
16
|
+
|
17
|
+
attr_accessible :salt_proxy_id, :salt_proxy_name, :salt_environment_id,
|
18
|
+
:salt_environment_name, :salt_modules, :salt_module_ids
|
16
19
|
end
|
17
20
|
|
18
21
|
def all_salt_modules
|
@@ -4,6 +4,8 @@ module ForemanSalt
|
|
4
4
|
extend FriendlyId
|
5
5
|
friendly_id :name
|
6
6
|
|
7
|
+
attr_accessible :name, :salt_environments, :salt_environment_ids
|
8
|
+
|
7
9
|
# before_destroy EnsureNotUsedBy.new(:hosts, :hostgroups)
|
8
10
|
|
9
11
|
has_many :hosts, :through => :host_salt_modules, :class_name => '::Host::Managed'
|
@@ -5,7 +5,7 @@ Deface::Override.new(:virtual_path => 'hosts/_form',
|
|
5
5
|
|
6
6
|
Deface::Override.new(:virtual_path => 'hosts/_form',
|
7
7
|
:name => 'add_salt_modules_tab_pane_to_host',
|
8
|
-
:insert_before => 'div#
|
8
|
+
:insert_before => 'div#primary',
|
9
9
|
:partial => 'foreman_salt/salt_modules/host_tab_pane')
|
10
10
|
|
11
11
|
Deface::Override.new(:virtual_path => 'hostgroups/_form',
|
@@ -15,5 +15,5 @@ Deface::Override.new(:virtual_path => 'hostgroups/_form',
|
|
15
15
|
|
16
16
|
Deface::Override.new(:virtual_path => 'hostgroups/_form',
|
17
17
|
:name => 'add_salt_modules_tab_pane_to_hg',
|
18
|
-
:insert_before => 'div#
|
18
|
+
:insert_before => 'div#primary',
|
19
19
|
:partial => 'foreman_salt/salt_modules/host_tab_pane')
|
@@ -27,7 +27,7 @@ module ForemanSalt
|
|
27
27
|
name_with_prefix = prefix.empty? ? name : prefix + FactName::SEPARATOR + name
|
28
28
|
|
29
29
|
compose = value.is_a?(Hash)
|
30
|
-
if fact_names[name_with_prefix].present?
|
30
|
+
if fact_names.is_a?(Hash) && fact_names[name_with_prefix].present?
|
31
31
|
fact_name_id = fact_names[name_with_prefix]
|
32
32
|
else
|
33
33
|
fact_name_id = fact_name_class.create!(:name => name_with_prefix,
|
@@ -15,7 +15,7 @@ module ForemanSalt
|
|
15
15
|
def architecture
|
16
16
|
name = facts[:osarch]
|
17
17
|
name = 'x86_64' if name == 'amd64'
|
18
|
-
Architecture.
|
18
|
+
Architecture.where(:name => name).first_or_create unless name.blank?
|
19
19
|
end
|
20
20
|
|
21
21
|
def environment
|
@@ -24,12 +24,12 @@ module ForemanSalt
|
|
24
24
|
|
25
25
|
def model
|
26
26
|
name = facts[:productname]
|
27
|
-
Model.
|
27
|
+
Model.where(:name => name.strip).first_or_create unless name.blank?
|
28
28
|
end
|
29
29
|
|
30
30
|
def domain
|
31
31
|
name = facts[:domain]
|
32
|
-
Domain.
|
32
|
+
Domain.where(:name => name).first_or_create unless name.blank?
|
33
33
|
end
|
34
34
|
|
35
35
|
def ip
|
@@ -24,7 +24,7 @@ module ForemanSalt
|
|
24
24
|
|
25
25
|
if @host.new_record? && !Setting[:create_new_host_when_report_is_uploaded]
|
26
26
|
logger.info("skipping report for #{@host} as its an unknown host and create_new_host_when_report_is_uploaded setting is disabled")
|
27
|
-
return
|
27
|
+
return ConfigReport.new
|
28
28
|
end
|
29
29
|
|
30
30
|
@host.salt_proxy_id ||= @proxy_id
|
@@ -36,9 +36,10 @@ module ForemanSalt
|
|
36
36
|
process_normal
|
37
37
|
end
|
38
38
|
|
39
|
+
@host.save(:validate => false)
|
40
|
+
@host.reload
|
39
41
|
@host.refresh_statuses
|
40
42
|
|
41
|
-
@host.save(:validate => false)
|
42
43
|
logger.info("Imported report for #{@host} in #{(Time.zone.now - start_time).round(2)} seconds")
|
43
44
|
end
|
44
45
|
|
@@ -130,16 +131,16 @@ module ForemanSalt
|
|
130
131
|
|
131
132
|
def process_normal
|
132
133
|
metrics = calculate_metrics
|
133
|
-
status =
|
134
|
+
status = ConfigReportStatusCalculator.new(:counters => metrics[:resources].slice(*::ConfigReport::METRIC)).calculate
|
134
135
|
|
135
|
-
@report =
|
136
|
+
@report = ConfigReport.new(:host => @host, :reported_at => start_time, :status => status, :metrics => metrics)
|
136
137
|
return @report unless @report.save
|
137
138
|
import_log_messages
|
138
139
|
end
|
139
140
|
|
140
141
|
def process_failures
|
141
|
-
status =
|
142
|
-
@report =
|
142
|
+
status = ConfigReportStatusCalculator.new(:counters => { 'failed' => @raw.size }).calculate
|
143
|
+
@report = ConfigReport.create(:host => @host, :reported_at => Time.zone.now, :status => status, :metrics => {})
|
143
144
|
|
144
145
|
source = Source.find_or_create('Salt')
|
145
146
|
@raw.each do |failure|
|
data/config/routes.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
scope :salt, :path => '/salt' do
|
3
3
|
constraints(:id => /[\w\.-]+/) do
|
4
|
-
match '/node/:id' => 'foreman_salt/minions#node'
|
5
|
-
match '/run/:id' => 'foreman_salt/minions#run'
|
4
|
+
match '/node/:id' => 'foreman_salt/minions#node', :via => :get
|
5
|
+
match '/run/:id' => 'foreman_salt/minions#run', :via => :get
|
6
6
|
end
|
7
7
|
|
8
8
|
resources :minions, :controller => 'foreman_salt/minions', :only => [] do
|
9
9
|
collection do
|
10
10
|
constraints(:id => /[^\/]+/) do
|
11
|
-
|
11
|
+
put 'salt_environment_selected'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/db/seeds.d/75-salt_seeds.rb
CHANGED
data/lib/foreman_salt/engine.rb
CHANGED
@@ -22,7 +22,9 @@ module ForemanSalt
|
|
22
22
|
end
|
23
23
|
|
24
24
|
initializer 'foreman_salt.load_app_instance_data' do |app|
|
25
|
-
|
25
|
+
ForemanSalt::Engine.paths['db/migrate'].existent.each do |path|
|
26
|
+
app.config.paths['db/migrate'] << path
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
initializer 'foreman_salt.assets.precompile' do |app|
|
data/lib/foreman_salt/plugin.rb
CHANGED
data/lib/foreman_salt/version.rb
CHANGED
@@ -45,8 +45,8 @@ module ForemanSalt
|
|
45
45
|
assert_response :success
|
46
46
|
|
47
47
|
@states.each do |env, states|
|
48
|
-
environment = ::ForemanSalt::SaltEnvironment.
|
49
|
-
|
48
|
+
environment = ::ForemanSalt::SaltEnvironment.find_by_name(env)
|
49
|
+
assert_empty environment.salt_modules.map(&:name) - states
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
data/test/test_plugin_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'test_helper'
|
|
4
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
|
-
find('
|
7
|
+
find('span.caret').click if dropdown
|
8
8
|
click_link(button_text)
|
9
9
|
end
|
10
10
|
end
|
@@ -56,11 +56,11 @@ module ForemanSalt
|
|
56
56
|
before do
|
57
57
|
@host = FactoryGirl.create(:host, :with_salt_proxy, :build => true)
|
58
58
|
@key_stub = stub("key")
|
59
|
-
ForemanSalt::SmartProxies::SaltKeys.expects(:find).with(@host.salt_proxy, @host.fqdn).returns(@key_stub)
|
59
|
+
ForemanSalt::SmartProxies::SaltKeys.expects(:find).at_least_once.with(@host.salt_proxy, @host.fqdn).returns(@key_stub)
|
60
60
|
end
|
61
61
|
|
62
62
|
test 'host key is accepted when host is built' do
|
63
|
-
@key_stub.expects(:accept).returns(true)
|
63
|
+
@key_stub.expects(:accept).at_least_once.returns(true)
|
64
64
|
assert @host.built
|
65
65
|
@host.run_callbacks(:commit) # callbacks don't run with Foreman's transactional fixtures
|
66
66
|
end
|
@@ -43,7 +43,7 @@ module ForemanSalt
|
|
43
43
|
parent = FactoryGirl.create :hostgroup, :with_salt_modules
|
44
44
|
child_one = FactoryGirl.create :hostgroup, :parent => parent
|
45
45
|
child_two = FactoryGirl.create :hostgroup, :parent => child_one
|
46
|
-
|
46
|
+
assert_empty parent.all_salt_modules - child_two.all_salt_modules
|
47
47
|
end
|
48
48
|
|
49
49
|
test 'inheritance when no parents have modules' do
|
@@ -18,6 +18,7 @@ module ForemanSalt
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'importing report updates host status' do
|
21
|
+
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
|
21
22
|
ForemanSalt::ReportImporter.import(@report)
|
22
23
|
assert Host.find_by_name(@host).get_status(HostStatus::ConfigurationStatus).error?
|
23
24
|
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:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Benjamin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -180,27 +180,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.4.
|
183
|
+
rubygems_version: 2.4.8
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: Foreman Plug-in for Salt
|
187
187
|
test_files:
|
188
|
+
- test/factories/foreman_salt_factories.rb
|
189
|
+
- test/integration/salt_autosign_test.rb
|
188
190
|
- test/integration/salt_module_test.rb
|
189
191
|
- test/integration/salt_environment_test.rb
|
190
|
-
- test/integration/salt_autosign_test.rb
|
191
192
|
- test/integration/salt_keys_test.rb
|
192
|
-
- test/
|
193
|
-
- test/unit/
|
193
|
+
- test/unit/highstate.json
|
194
|
+
- test/unit/report_importer_test.rb
|
194
195
|
- test/unit/grains_centos.json
|
195
196
|
- test/unit/host_extensions_test.rb
|
196
|
-
- test/unit/report_importer_test.rb
|
197
|
-
- test/unit/hostgroup_extensions_test.rb
|
198
197
|
- test/unit/salt_modules_test.rb
|
199
|
-
- test/unit/
|
198
|
+
- test/unit/grains_importer_test.rb
|
200
199
|
- test/unit/salt_keys_test.rb
|
201
|
-
- test/
|
202
|
-
- test/
|
203
|
-
- test/functional/api/v2/salt_states_controller_test.rb
|
200
|
+
- test/unit/hostgroup_extensions_test.rb
|
201
|
+
- test/test_plugin_helper.rb
|
204
202
|
- test/functional/api/v2/salt_keys_controller_test.rb
|
203
|
+
- test/functional/api/v2/salt_autosign_controller_test.rb
|
205
204
|
- test/functional/api/v2/salt_environments_controller_test.rb
|
206
|
-
- test/
|
205
|
+
- test/functional/api/v2/salt_states_controller_test.rb
|
206
|
+
- test/functional/minions_controller_test.rb
|