foreman_salt 3.0.2 → 4.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/app/assets/javascripts/foreman_salt/states.js +6 -4
  4. data/app/controllers/foreman_salt/api/v2/jobs_controller.rb +4 -4
  5. data/app/controllers/foreman_salt/minions_controller.rb +9 -9
  6. data/app/controllers/foreman_salt/state_importer.rb +1 -1
  7. data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +2 -2
  8. data/app/models/foreman_salt/concerns/host_managed_extensions.rb +5 -0
  9. data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +2 -2
  10. data/app/models/foreman_salt/concerns/orchestration/salt.rb +1 -1
  11. data/app/models/foreman_salt/host_salt_module.rb +1 -1
  12. data/app/models/foreman_salt/salt_environment.rb +2 -3
  13. data/app/models/foreman_salt/salt_module.rb +2 -3
  14. data/app/overrides/salt_environment_host_selector.rb +1 -1
  15. data/app/overrides/salt_environment_hostgroup_selector.rb +1 -1
  16. data/app/overrides/salt_proxy_selector.rb +2 -2
  17. data/app/services/foreman_salt/fact_importer.rb +1 -1
  18. data/app/services/foreman_salt/report_importer.rb +7 -9
  19. data/app/services/foreman_salt/smart_proxies/salt_keys.rb +3 -3
  20. data/db/seeds.d/{75-salt-seeds.rb → 75-salt_seeds.rb} +0 -0
  21. data/lib/foreman_salt/engine.rb +13 -152
  22. data/lib/foreman_salt/extensions.rb +20 -0
  23. data/lib/foreman_salt/plugin.rb +134 -0
  24. data/lib/foreman_salt/version.rb +1 -1
  25. data/test/factories/foreman_salt_factories.rb +1 -1
  26. data/test/functional/api/v2/salt_states_controller_test.rb +3 -3
  27. data/test/integration/salt_module_test.rb +5 -1
  28. data/test/unit/host_extensions_test.rb +9 -0
  29. data/test/unit/report_importer_test.rb +1 -1
  30. metadata +12 -11
  31. data/app/helpers/concerns/foreman_salt/layout_helper_extensions.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 044d6bcb7bb23ae885d02d14977aa289a86566ad
4
- data.tar.gz: e3fdf276fedaf50ef67ea0128be66aeaa522ee3d
3
+ metadata.gz: f6b22fef4003be237f6ba02e594fa8d583bc218f
4
+ data.tar.gz: e30d40a831982a5c5f07c645ea8936b5be3ab2da
5
5
  SHA512:
6
- metadata.gz: 9b307a6679849af4beec034ab1a0e1957790845959b18458d483dec84b4d7dbd83fb4515749902d2149b3631be472d5b599d3e214e2a2d7d8dfcc86cc861922c
7
- data.tar.gz: ad68170d5cd1c6cde132c80cba7d768d6b0b3d3dcdb5449415d5f37f6ecd75c88eb8883f0dc3742834832442571e8bf80dc19be5f97ffb90490f63a67181b6f2
6
+ metadata.gz: 2bbb4d5db09be8cc76f57375e61207e0f2a9758bd6ed7f6140234af2a34ec608329180f3001ff5ab7ee712b77b5e43ee1313629c33f0eb74c5fd091782238de1
7
+ data.tar.gz: 51751be171370526cc4deace259268e790707084eef0f3bc88e17e2d74797b8702e86c808af8355f56a0e043f9f87193b7c39e4896fbd496a962948728e5359a
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  [![Build Status](https://img.shields.io/jenkins/s/http/ci.theforeman.org/test_plugin_foreman_salt_master.svg)](http://ci.theforeman.org/job/test_plugin_foreman_salt_master)
2
+ [![Gem Version](https://img.shields.io/gem/v/foreman_salt.svg)](https://rubygems.org/gems/foreman_salt)
2
3
  [![Code Climate](https://codeclimate.com/github/theforeman/foreman_salt/badges/gpa.svg)](https://codeclimate.com/github/theforeman/foreman_salt)
3
4
  [![GPL License](https://img.shields.io/github/license/theforeman/foreman_salt.svg)](https://github.com/theforeman/foreman_salt/blob/master/LICENSE)
4
5
 
5
6
  # Foreman Salt Plug-in
6
7
 
7
- This plug-in adds support for Salt to Foreman.
8
+ This plug-in adds support for Salt to Foreman.
8
9
 
9
10
  ## Documentation
10
11
 
@@ -3,18 +3,20 @@ $(document).on( "ContentLoad", function() {
3
3
  });
4
4
 
5
5
  function update_salt_states(element) {
6
- var host_id = $("form").data('id')
6
+ var host_id = $("form").data('id');
7
7
  var env_id = $('select[name*=salt_environment_id]').val();
8
8
  var url = $(element).attr('data-url');
9
9
  var data = $("form").serialize().replace('method=put', 'method=post');
10
10
 
11
11
  if (url.match('hostgroups')) {
12
- data = data + '&hostgroup_id=' + host_id
12
+ data = data + '&hostgroup_id=' + host_id;
13
13
  } else {
14
- data = data + '&host_id=' + host_id
14
+ data = data + '&host_id=' + host_id;
15
15
  }
16
16
 
17
- if (env_id == "") return;
17
+ if (!env_id) {
18
+ return;
19
+ }
18
20
 
19
21
  $(element).indicator_show();
20
22
  $.ajax({
@@ -39,10 +39,10 @@ module ForemanSalt
39
39
 
40
40
  def action_permission
41
41
  case params[:action]
42
- when 'upload'
43
- :create
44
- else
45
- super
42
+ when 'upload'
43
+ :create
44
+ else
45
+ super
46
46
  end
47
47
  end
48
48
  end
@@ -20,7 +20,7 @@ module ForemanSalt
20
20
  end
21
21
  rescue
22
22
  logger.warn "Failed to generate external nodes for #{@minion} with #{$ERROR_INFO}"
23
- render :text => _('Unable to generate output, Check log files\n'), :status => 412 and return
23
+ render(:text => _('Unable to generate output, Check log files\n'), :status => 412) && return
24
24
  end
25
25
 
26
26
  def run
@@ -44,14 +44,14 @@ module ForemanSalt
44
44
 
45
45
  def action_permission
46
46
  case params[:action]
47
- when 'run'
48
- :saltrun
49
- when 'node'
50
- :view
51
- when 'salt_environment_selected'
52
- :edit
53
- else
54
- super
47
+ when 'run'
48
+ :saltrun
49
+ when 'node'
50
+ :view
51
+ when 'salt_environment_selected'
52
+ :edit
53
+ else
54
+ super
55
55
  end
56
56
  end
57
57
 
@@ -18,7 +18,7 @@ module ForemanSalt
18
18
 
19
19
  environments ||= new.keys + old.keys
20
20
 
21
- environments.each do |environment|
21
+ environments.each do |environment| # rubocop:disable Style/Next
22
22
  old_states = old[environment] || []
23
23
  new_states = new[environment] || []
24
24
 
@@ -29,8 +29,8 @@ module ForemanSalt
29
29
  def overview_fields_with_salt(host)
30
30
  fields = overview_fields_without_salt(host)
31
31
 
32
- fields.insert(5, [_("Salt Master"), (link_to(host.salt_proxy, hosts_path(:search => "saltmaster = #{host.salt_proxy}")) if host.salt_proxy)])
33
- fields.insert(6, [_("Salt Environment"), (link_to(host.salt_environment, hosts_path(:search => "salt_environment = #{host.salt_environment}")) if host.salt_environment)])
32
+ fields.insert(5, [_('Salt Master'), (link_to(host.salt_proxy, hosts_path(:search => "saltmaster = #{host.salt_proxy}")) if host.salt_proxy)])
33
+ fields.insert(6, [_('Salt Environment'), (link_to(host.salt_environment, hosts_path(:search => "salt_environment = #{host.salt_environment}")) if host.salt_environment)])
34
34
 
35
35
  fields
36
36
  end
@@ -13,6 +13,7 @@ module ForemanSalt
13
13
  alias_method_chain :params, :salt_proxy
14
14
  alias_method_chain :set_hostgroup_defaults, :salt_proxy
15
15
  alias_method_chain :smart_proxy_ids, :salt_proxy
16
+ alias_method_chain :configuration?, :salt
16
17
 
17
18
  scoped_search :in => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
18
19
  scoped_search :in => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
@@ -21,6 +22,10 @@ module ForemanSalt
21
22
  validate :salt_modules_in_host_environment
22
23
  end
23
24
 
25
+ def configuration_with_salt?
26
+ configuration_without_salt? || !!salt_proxy
27
+ end
28
+
24
29
  def handle_salt
25
30
  return true unless salt?
26
31
  set_salt_autosign
@@ -34,7 +34,7 @@ module ForemanSalt
34
34
 
35
35
  def inherited_salt_proxy_id
36
36
  if ancestry.present?
37
- read_attribute(:salt_proxy_id) || self.class.sort_by_ancestry(ancestors.where('salt_proxy_id is not NULL')).last.try(:salt_proxy_id)
37
+ self[:salt_proxy_id] || self.class.sort_by_ancestry(ancestors.where('salt_proxy_id is not NULL')).last.try(:salt_proxy_id)
38
38
  else
39
39
  salt_proxy_id
40
40
  end
@@ -47,7 +47,7 @@ module ForemanSalt
47
47
 
48
48
  def inherited_salt_environment_id
49
49
  if ancestry.present?
50
- read_attribute(:salt_environment_id) || self.class.sort_by_ancestry(ancestors.where('salt_environment_id is not NULL')).last.try(:salt_environment_id)
50
+ self[:salt_environment_id] || self.class.sort_by_ancestry(ancestors.where('salt_environment_id is not NULL')).last.try(:salt_environment_id)
51
51
  else
52
52
  salt_environment_id
53
53
  end
@@ -29,7 +29,7 @@ module ForemanSalt
29
29
 
30
30
  def queue_update_salt_autosign
31
31
  # Host has been built --> remove auto sign
32
- if old.build? and !build?
32
+ if old.build? && !build?
33
33
  queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign])
34
34
  end
35
35
  end
@@ -1,6 +1,6 @@
1
1
  module ForemanSalt
2
2
  class HostSaltModule < ActiveRecord::Base
3
- belongs_to :host, :class_name => "Host::Managed", :foreign_key => :host_id
3
+ belongs_to :host, :class_name => 'Host::Managed', :foreign_key => :host_id
4
4
  belongs_to :salt_module
5
5
  end
6
6
  end
@@ -1,6 +1,5 @@
1
1
  module ForemanSalt
2
2
  class SaltEnvironment < ActiveRecord::Base
3
- include Taxonomix
4
3
  include Authorizable
5
4
  extend FriendlyId
6
5
  friendly_id :name
@@ -21,8 +20,8 @@ module ForemanSalt
21
20
  _('Salt environment')
22
21
  end
23
22
 
24
- def self.permission_name(action)
25
- "#{action}_salt_environments"
23
+ def self.permission_name
24
+ 'salt_environments'
26
25
  end
27
26
 
28
27
  private
@@ -1,6 +1,5 @@
1
1
  module ForemanSalt
2
2
  class SaltModule < ActiveRecord::Base
3
- include Taxonomix
4
3
  include Authorizable
5
4
  extend FriendlyId
6
5
  friendly_id :name
@@ -43,8 +42,8 @@ module ForemanSalt
43
42
  _('Salt state')
44
43
  end
45
44
 
46
- def self.permission_name(action)
47
- "#{action}_salt_modules"
45
+ def self.permission_name
46
+ 'salt_modules'
48
47
  end
49
48
  end
50
49
  end
@@ -6,4 +6,4 @@ selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironm
6
6
  Deface::Override.new(:virtual_path => 'hosts/_form',
7
7
  :name => 'add_salt_environment_to_host',
8
8
  :insert_bottom => 'div#primary',
9
- :text => selector_text)
9
+ :text => selector_text)
@@ -6,4 +6,4 @@ selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironm
6
6
  Deface::Override.new(:virtual_path => 'hostgroups/_form',
7
7
  :name => 'add_salt_environment_to_hostgroup',
8
8
  :insert_bottom => 'div#primary',
9
- :text => selector_text)
9
+ :text => selector_text)
@@ -5,9 +5,9 @@ selector_text = "<%= select_f f, :salt_proxy_id, SmartProxy.unscoped.with_featur
5
5
  Deface::Override.new(:virtual_path => 'hosts/_form',
6
6
  :name => 'add_salt_proxy_to_host',
7
7
  :insert_bottom => 'div#primary',
8
- :text => selector_text)
8
+ :text => selector_text)
9
9
 
10
10
  Deface::Override.new(:virtual_path => 'hostgroups/_form',
11
11
  :name => 'add_salt_proxy_to_hostgroup',
12
12
  :insert_bottom => 'div#primary',
13
- :text => selector_text)
13
+ :text => selector_text)
@@ -75,7 +75,7 @@ module ForemanSalt
75
75
  hash.each do |fact_name, value|
76
76
  name_parts = fact_name.split(FactName::SEPARATOR)
77
77
 
78
- name_parts.inject([]) do |memo, name|
78
+ name_parts.inject([]) do |memo, name| # rubocop:disable Style/EachWithObject
79
79
  memo += [name]
80
80
  key = memo.join(FactName::SEPARATOR)
81
81
  new_facts[key] ||= name_parts == memo ? value : nil
@@ -1,10 +1,10 @@
1
1
  module ForemanSalt
2
- class ReportImporter
2
+ class ReportImporter # rubocop:disable Metrics/ClassLength
3
3
  delegate :logger, :to => :Rails
4
4
  attr_reader :report
5
5
 
6
6
  def self.import(raw, proxy_id = nil)
7
- raise ::Foreman::Exception.new(_('Invalid report')) unless raw.is_a?(Hash)
7
+ fail ::Foreman::Exception.new(_('Invalid report')) unless raw.is_a?(Hash)
8
8
  raw.map do |host, report|
9
9
  importer = ForemanSalt::ReportImporter.new(host, report, proxy_id)
10
10
  importer.import
@@ -36,8 +36,10 @@ module ForemanSalt
36
36
  process_normal
37
37
  end
38
38
 
39
+ @host.refresh_statuses
40
+
39
41
  @host.save(:validate => false)
40
- logger.info("Imported report for #{@host} in #{(Time.now - start_time).round(2)} seconds")
42
+ logger.info("Imported report for #{@host} in #{(Time.zone.now - start_time).round(2)} seconds")
41
43
  end
42
44
 
43
45
  private
@@ -130,8 +132,6 @@ module ForemanSalt
130
132
  metrics = calculate_metrics
131
133
  status = ReportStatusCalculator.new(:counters => metrics[:resources].slice(*::Report::METRIC)).calculate
132
134
 
133
- @host.puppet_status = status
134
-
135
135
  @report = Report.new(:host => @host, :reported_at => start_time, :status => status, :metrics => metrics)
136
136
  return @report unless @report.save
137
137
  import_log_messages
@@ -139,9 +139,7 @@ module ForemanSalt
139
139
 
140
140
  def process_failures
141
141
  status = ReportStatusCalculator.new(:counters => { 'failed' => @raw.size }).calculate
142
- @report = Report.create(:host => @host, :reported_at => Time.now, :status => status, :metrics => {})
143
-
144
- @host.puppet_status = status
142
+ @report = Report.create(:host => @host, :reported_at => Time.zone.now, :status => status, :metrics => {})
145
143
 
146
144
  source = Source.find_or_create('Salt')
147
145
  @raw.each do |failure|
@@ -151,7 +149,7 @@ module ForemanSalt
151
149
  end
152
150
 
153
151
  def start_time
154
- @start_time ||= Time.now
152
+ @start_time ||= Time.zone.now
155
153
  end
156
154
  end
157
155
  end
@@ -8,7 +8,7 @@ module ForemanSalt
8
8
 
9
9
  class << self
10
10
  def all(proxy)
11
- raise ::Foreman::Exception.new(N_('Must specify a Smart Proxy to use')) if proxy.nil?
11
+ fail ::Foreman::Exception.new(N_('Must specify a Smart Proxy to use')) if proxy.nil?
12
12
 
13
13
  unless (keys = Rails.cache.read("saltkeys_#{proxy.id}"))
14
14
  api = ProxyAPI::Salt.new(:url => proxy.url)
@@ -31,14 +31,14 @@ module ForemanSalt
31
31
  end
32
32
 
33
33
  def accept
34
- raise ::Foreman::Exception.new(N_('unable to re-accept an accepted key')) unless state == 'unaccepted'
34
+ fail ::Foreman::Exception.new(N_('unable to re-accept an accepted key')) unless state == 'unaccepted'
35
35
  proxy = SmartProxy.find(smart_proxy_id)
36
36
  Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production?
37
37
  ProxyAPI::Salt.new(:url => proxy.url).key_accept name
38
38
  end
39
39
 
40
40
  def reject
41
- raise ::Foreman::Exception.new(N_('unable to reject an accepted key')) unless state == 'unaccepted'
41
+ fail ::Foreman::Exception.new(N_('unable to reject an accepted key')) unless state == 'unaccepted'
42
42
  proxy = SmartProxy.find(smart_proxy_id)
43
43
  Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production?
44
44
  ProxyAPI::Salt.new(:url => proxy.url).key_reject name
File without changes
@@ -11,181 +11,42 @@ module ForemanSalt
11
11
  config.autoload_paths += Dir["#{config.root}/app/services"]
12
12
  config.autoload_paths += Dir["#{config.root}/app/lib"]
13
13
 
14
- initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
14
+ initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do
15
15
  ForemanTasks.dynflow.require!
16
16
  end
17
17
 
18
18
  initializer 'foreman_salt.load_default_settings', :before => :load_config_initializers do
19
- require_dependency File.expand_path('../../../app/models/setting/salt.rb', __FILE__) if (Setting.table_exists? rescue(false))
19
+ if (Setting.table_exists? rescue(false))
20
+ require_dependency File.expand_path('../../../app/models/setting/salt.rb', __FILE__)
21
+ end
20
22
  end
21
23
 
22
24
  initializer 'foreman_salt.load_app_instance_data' do |app|
23
25
  app.config.paths['db/migrate'] += ForemanSalt::Engine.paths['db/migrate'].existent
24
26
  end
25
27
 
26
- initializer "foreman_salt.assets.precompile" do |app|
28
+ initializer 'foreman_salt.assets.precompile' do |app|
27
29
  app.config.assets.precompile += %w(foreman_salt/states.js)
28
30
  end
29
31
 
30
32
  initializer 'foreman_salt.configure_assets', :group => :assets do
31
- SETTINGS[:foreman_salt] = {:assets => {:precompile => ['foreman_salt/states.js']}}
33
+ SETTINGS[:foreman_salt] = {
34
+ :assets => {
35
+ :precompile => ['foreman_salt/states.js']
36
+ }
37
+ }
32
38
  end
33
39
 
34
40
  initializer 'foreman_salt.apipie' do
35
41
  Apipie.configuration.checksum_path += ['/salt/api/']
36
42
  end
37
43
 
38
- initializer 'foreman_salt.register_plugin', :after => :finisher_hook do |_app|
39
- Foreman::Plugin.register :foreman_salt do
40
- requires_foreman '>= 1.9'
41
-
42
- apipie_documented_controllers ["#{ForemanSalt::Engine.root}/app/controllers/foreman_salt/api/v2/*.rb"]
43
-
44
- ## Menus
45
- menu :top_menu, :salt_environments,
46
- :url_hash => { :controller => :'foreman_salt/salt_environments', :action => :index },
47
- :caption => 'Environments',
48
- :parent => :configure_menu,
49
- :after => :common_parameters
50
-
51
- menu :top_menu, :salt_modules,
52
- :url_hash => { :controller => :'foreman_salt/salt_modules', :action => :index },
53
- :caption => 'States',
54
- :parent => :configure_menu,
55
- :after => :common_parameters
56
-
57
- divider :top_menu, :parent => :configure_menu,
58
- :caption => 'Salt',
59
- :after => :common_parameters
60
-
61
- # Permissions
62
- security_block :foreman_salt do |_map|
63
- permission :destroy_smart_proxies_salt_autosign,
64
- { :'foreman_salt/salt_autosign' => [:destroy],
65
- :'foreman_salt/api/v2/salt_autosign' => [:destroy] },
66
- :resource_type => 'SmartProxy'
67
-
68
- permission :create_smart_proxies_salt_autosign,
69
- { :'foreman_salt/salt_autosign' => [:new, :create],
70
- :'foreman_salt/api/v2/salt_autosign' => [:create] },
71
- :resource_type => 'SmartProxy'
72
-
73
- permission :view_smart_proxies_salt_autosign,
74
- { :'foreman_salt/salt_autosign' => [:index],
75
- :'foreman_salt/api/v2/salt_autosign' => [:index] },
76
- :resource_type => 'SmartProxy'
77
-
78
- permission :create_salt_environments,
79
- { :'foreman_salt/salt_environments' => [:new, :create],
80
- :'foreman_salt/api/v2/salt_environments' => [:create] },
81
- :resource_type => 'ForemanSalt::SaltEnvironment'
82
-
83
- permission :view_salt_environments,
84
- { :'foreman_salt/salt_environments' => [:index, :show, :auto_complete_search],
85
- :'foreman_salt/api/v2/salt_environments' => [:index, :show] },
86
- :resource_type => 'ForemanSalt::SaltEnvironment'
87
-
88
- permission :edit_salt_environments,
89
- { :'foreman_salt/salt_environments' => [:update, :edit] },
90
- :resource_type => 'ForemanSalt::SaltEnvironment'
91
-
92
- permission :destroy_salt_environments,
93
- { :'foreman_salt/salt_environments' => [:destroy],
94
- :'foreman_salt/api/v2/salt_environments' => [:destroy] },
95
- :resource_type => 'ForemanSalt::SaltEnvironment'
96
-
97
- permission :create_reports,
98
- { :'foreman_salt/api/v2/jobs' => [:upload] },
99
- :resource_type => 'Report'
100
-
101
- permission :saltrun_hosts,
102
- { :'foreman_salt/minions' => [:run] },
103
- :resource_type => 'Host'
104
-
105
- permission :edit_hosts,
106
- { :'foreman_salt/api/v2/salt_minions' => [:update],
107
- :'foreman_salt/minions' => [:salt_environment_selected] },
108
- :resource_type => 'Host'
109
-
110
- permission :view_hosts,
111
- { :'foreman_salt/minions' => [:node],
112
- :'foreman_salt/api/v2/salt_minions' => [:index, :show] },
113
- :resource_type => 'Host'
114
-
115
- permission :edit_hostgroups,
116
- { :hostgroups => [:salt_environment_selected] },
117
- :resource_type => 'Hostgroup'
118
-
119
- permission :view_smart_proxies_salt_keys,
120
- { :'foreman_salt/salt_keys' => [:index],
121
- :'foreman_salt/api/v2/salt_keys' => [:index] },
122
- :resource_type => 'SmartProxy'
123
-
124
- permission :destroy_smart_proxies_salt_keys,
125
- { :'foreman_salt/salt_keys' => [:destroy],
126
- :'foreman_salt/api/v2/salt_keys' => [:destroy] },
127
- :resource_type => 'SmartProxy'
128
-
129
- permission :edit_smart_proxies_salt_keys,
130
- { :'foreman_salt/salt_keys' => [:accept, :reject],
131
- :'foreman_salt/api/v2/salt_keys' => [:update] },
132
- :resource_type => 'SmartProxy'
133
-
134
- permission :create_salt_modules,
135
- { :'foreman_salt/salt_modules' => [:new, :create],
136
- :'foreman_salt/api/v2/salt_states' => [:create] },
137
- :resource_type => 'ForemanSalt::SaltModule'
138
-
139
- permission :import_salt_modules,
140
- { :'foreman_salt/salt_modules' => [:import, :apply_changes],
141
- :'foreman_salt/api/v2/salt_states' => [:import] },
142
- :resource_type => 'ForemanSalt::SaltModule'
143
-
144
- permission :view_salt_modules,
145
- { :'foreman_salt/salt_modules' => [:index, :show, :auto_complete_search],
146
- :'foreman_salt/api/v2/salt_states' => [:index, :show] },
147
- :resource_type => 'ForemanSalt::SaltModule'
148
-
149
- permission :edit_salt_modules,
150
- { :'foreman_salt/salt_modules' => [:update, :edit] },
151
- :resource_type => 'ForemanSalt::SaltModule'
152
-
153
- permission :destroy_salt_modules,
154
- { :'foreman_salt/salt_modules' => [:destroy],
155
- :'foreman_salt/api/v2/salt_states' => [:destroy] },
156
- :resource_type => 'ForemanSalt::SaltModule'
157
- end
158
-
159
- ## Roles
160
- role 'Salt admin', [:saltrun_hosts, :create_salt_modules, :view_salt_modules, :edit_salt_modules, :destroy_salt_modules,
161
- :view_smart_proxies_salt_keys, :destroy_smart_proxies_salt_keys, :edit_smart_proxies_salt_keys,
162
- :create_smart_proxies_salt_autosign, :view_smart_proxies_salt_autosign, :destroy_smart_proxies_salt_autosign,
163
- :create_salt_environments, :view_salt_environments, :edit_salt_environments, :destroy_salt_environments]
164
- end
44
+ initializer 'foreman_salt.register_plugin', :after => :finisher_hook do
45
+ require 'foreman_salt/plugin'
165
46
  end
166
47
 
167
48
  config.to_prepare do
168
- begin
169
- ::FactImporter.register_fact_importer(:foreman_salt, ForemanSalt::FactImporter)
170
- ::FactParser.register_fact_parser(:foreman_salt, ForemanSalt::FactParser)
171
-
172
- # Helper Extensions
173
- ::HostsHelper.send :include, ForemanSalt::HostsHelperExtensions
174
- ::SmartProxiesHelper.send :include, ForemanSalt::SmartProxiesHelperExtensions
175
- ::LayoutHelper.send :include, ForemanSalt::LayoutHelperExtensions
176
-
177
- # Model Extensions
178
- ::Host::Managed.send :include, ForemanSalt::Concerns::HostManagedExtensions
179
- ::Host::Managed.send :include, ForemanSalt::Concerns::Orchestration::Salt
180
- ::Hostgroup.send :include, ForemanSalt::Concerns::HostgroupExtensions
181
-
182
- # Controller Extensions
183
- ::UnattendedController.send :include, ForemanSalt::Concerns::UnattendedControllerExtensions
184
- ::HostsController.send :include, ForemanSalt::Concerns::HostsControllerExtensions
185
- ::HostgroupsController.send :include, ForemanSalt::Concerns::HostgroupsControllerExtensions
186
- rescue => e
187
- puts "ForemanSalt: skipping engine hook (#{e})"
188
- end
49
+ require 'foreman_salt/extensions'
189
50
  end
190
51
  end
191
52
  end
@@ -0,0 +1,20 @@
1
+ begin
2
+ ::FactImporter.register_fact_importer(:foreman_salt, ForemanSalt::FactImporter)
3
+ ::FactParser.register_fact_parser(:foreman_salt, ForemanSalt::FactParser)
4
+
5
+ # Helper Extensions
6
+ ::HostsHelper.send :include, ForemanSalt::HostsHelperExtensions
7
+ ::SmartProxiesHelper.send :include, ForemanSalt::SmartProxiesHelperExtensions
8
+
9
+ # Model Extensions
10
+ ::Host::Managed.send :include, ForemanSalt::Concerns::HostManagedExtensions
11
+ ::Host::Managed.send :include, ForemanSalt::Concerns::Orchestration::Salt
12
+ ::Hostgroup.send :include, ForemanSalt::Concerns::HostgroupExtensions
13
+
14
+ # Controller Extensions
15
+ ::UnattendedController.send :include, ForemanSalt::Concerns::UnattendedControllerExtensions
16
+ ::HostsController.send :include, ForemanSalt::Concerns::HostsControllerExtensions
17
+ ::HostgroupsController.send :include, ForemanSalt::Concerns::HostgroupsControllerExtensions
18
+ rescue => e
19
+ puts "ForemanSalt: skipping engine hook (#{e})"
20
+ end
@@ -0,0 +1,134 @@
1
+ Foreman::Plugin.register :foreman_salt do
2
+ requires_foreman '>= 1.10'
3
+
4
+ apipie_documented_controllers ["#{ForemanSalt::Engine.root}/app/controllers/foreman_salt/api/v2/*.rb"]
5
+
6
+ # Menus
7
+ menu :top_menu, :salt_environments,
8
+ :url_hash => { :controller => :'foreman_salt/salt_environments', :action => :index },
9
+ :caption => 'Environments',
10
+ :parent => :configure_menu,
11
+ :after => :common_parameters
12
+
13
+ menu :top_menu, :salt_modules,
14
+ :url_hash => { :controller => :'foreman_salt/salt_modules', :action => :index },
15
+ :caption => 'States',
16
+ :parent => :configure_menu,
17
+ :after => :common_parameters
18
+
19
+ divider :top_menu, :parent => :configure_menu,
20
+ :caption => 'Salt',
21
+ :after => :common_parameters
22
+
23
+ # Permissions
24
+ security_block :foreman_salt do
25
+ permission :destroy_smart_proxies_salt_autosign,
26
+ { :'foreman_salt/salt_autosign' => [:destroy],
27
+ :'foreman_salt/api/v2/salt_autosign' => [:destroy] },
28
+ :resource_type => 'SmartProxy'
29
+
30
+ permission :create_smart_proxies_salt_autosign,
31
+ { :'foreman_salt/salt_autosign' => [:new, :create],
32
+ :'foreman_salt/api/v2/salt_autosign' => [:create] },
33
+ :resource_type => 'SmartProxy'
34
+
35
+ permission :view_smart_proxies_salt_autosign,
36
+ { :'foreman_salt/salt_autosign' => [:index],
37
+ :'foreman_salt/api/v2/salt_autosign' => [:index] },
38
+ :resource_type => 'SmartProxy'
39
+
40
+ permission :create_salt_environments,
41
+ { :'foreman_salt/salt_environments' => [:new, :create],
42
+ :'foreman_salt/api/v2/salt_environments' => [:create] },
43
+ :resource_type => 'ForemanSalt::SaltEnvironment'
44
+
45
+ permission :view_salt_environments,
46
+ { :'foreman_salt/salt_environments' => [:index, :show, :auto_complete_search],
47
+ :'foreman_salt/api/v2/salt_environments' => [:index, :show] },
48
+ :resource_type => 'ForemanSalt::SaltEnvironment'
49
+
50
+ permission :edit_salt_environments,
51
+ { :'foreman_salt/salt_environments' => [:update, :edit] },
52
+ :resource_type => 'ForemanSalt::SaltEnvironment'
53
+
54
+ permission :destroy_salt_environments,
55
+ { :'foreman_salt/salt_environments' => [:destroy],
56
+ :'foreman_salt/api/v2/salt_environments' => [:destroy] },
57
+ :resource_type => 'ForemanSalt::SaltEnvironment'
58
+
59
+ permission :create_reports,
60
+ { :'foreman_salt/api/v2/jobs' => [:upload] },
61
+ :resource_type => 'Report'
62
+
63
+ permission :saltrun_hosts,
64
+ { :'foreman_salt/minions' => [:run] },
65
+ :resource_type => 'Host'
66
+
67
+ permission :edit_hosts,
68
+ { :'foreman_salt/api/v2/salt_minions' => [:update],
69
+ :'foreman_salt/minions' => [:salt_environment_selected] },
70
+ :resource_type => 'Host'
71
+
72
+ permission :view_hosts,
73
+ { :'foreman_salt/minions' => [:node],
74
+ :'foreman_salt/api/v2/salt_minions' => [:index, :show] },
75
+ :resource_type => 'Host'
76
+
77
+ permission :edit_hostgroups,
78
+ { :hostgroups => [:salt_environment_selected] },
79
+ :resource_type => 'Hostgroup'
80
+
81
+ permission :view_smart_proxies_salt_keys,
82
+ { :'foreman_salt/salt_keys' => [:index],
83
+ :'foreman_salt/api/v2/salt_keys' => [:index] },
84
+ :resource_type => 'SmartProxy'
85
+
86
+ permission :destroy_smart_proxies_salt_keys,
87
+ { :'foreman_salt/salt_keys' => [:destroy],
88
+ :'foreman_salt/api/v2/salt_keys' => [:destroy] },
89
+ :resource_type => 'SmartProxy'
90
+
91
+ permission :edit_smart_proxies_salt_keys,
92
+ { :'foreman_salt/salt_keys' => [:accept, :reject],
93
+ :'foreman_salt/api/v2/salt_keys' => [:update] },
94
+ :resource_type => 'SmartProxy'
95
+
96
+ permission :create_salt_modules,
97
+ { :'foreman_salt/salt_modules' => [:new, :create],
98
+ :'foreman_salt/api/v2/salt_states' => [:create] },
99
+ :resource_type => 'ForemanSalt::SaltModule'
100
+
101
+ permission :import_salt_modules,
102
+ { :'foreman_salt/salt_modules' => [:import, :apply_changes],
103
+ :'foreman_salt/api/v2/salt_states' => [:import] },
104
+ :resource_type => 'ForemanSalt::SaltModule'
105
+
106
+ permission :view_salt_modules,
107
+ { :'foreman_salt/salt_modules' => [:index, :show, :auto_complete_search],
108
+ :'foreman_salt/api/v2/salt_states' => [:index, :show] },
109
+ :resource_type => 'ForemanSalt::SaltModule'
110
+
111
+ permission :edit_salt_modules,
112
+ { :'foreman_salt/salt_modules' => [:update, :edit] },
113
+ :resource_type => 'ForemanSalt::SaltModule'
114
+
115
+ permission :destroy_salt_modules,
116
+ { :'foreman_salt/salt_modules' => [:destroy],
117
+ :'foreman_salt/api/v2/salt_states' => [:destroy] },
118
+ :resource_type => 'ForemanSalt::SaltModule'
119
+ end
120
+
121
+ # Roles
122
+ role 'Salt admin', [:saltrun_hosts, :create_salt_modules,
123
+ :view_salt_modules, :edit_salt_modules,
124
+ :destroy_salt_modules,
125
+ :view_smart_proxies_salt_keys,
126
+ :destroy_smart_proxies_salt_keys,
127
+ :edit_smart_proxies_salt_keys,
128
+ :create_smart_proxies_salt_autosign,
129
+ :view_smart_proxies_salt_autosign,
130
+ :destroy_smart_proxies_salt_autosign,
131
+ :create_salt_environments, :view_salt_environments,
132
+ :edit_salt_environments,
133
+ :destroy_salt_environments]
134
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '3.0.2'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -28,7 +28,7 @@ FactoryGirl.modify do
28
28
 
29
29
  factory :smart_proxy do
30
30
  trait :with_salt_feature do
31
- features { [::Feature.find_or_create_by_name('Salt')] }
31
+ features { [::Feature.find_or_create_by_name('Salt')] }
32
32
  end
33
33
  end
34
34
  end
@@ -33,8 +33,8 @@ module ForemanSalt
33
33
  context 'importing' do
34
34
  setup do
35
35
  @proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
36
- @states = {'env1' => %w(state1 state2 state3),
37
- 'env2' => %w(state1 state2)}
36
+ @states = { 'env1' => %w(state1 state2 state3),
37
+ 'env2' => %w(state1 state2) }
38
38
 
39
39
  ::ProxyAPI::Salt.any_instance.stubs(:states_list).returns(@states)
40
40
  end
@@ -73,7 +73,7 @@ module ForemanSalt
73
73
  assert_response :success
74
74
  refute ::ForemanSalt::SaltModule.where(:id => state).first
75
75
  refute ::ForemanSalt::SaltModule.where(:name => 'state1').first
76
- end
76
+ end
77
77
 
78
78
  test 'dryrun should do nothing' do
79
79
  post :import, :smart_proxy_id => @proxy.id, :dryrun => true
@@ -6,9 +6,13 @@ module ForemanSalt
6
6
  User.current = User.anonymous_admin
7
7
 
8
8
  states = %w(state1 state2 state3 state4)
9
- state_list = {'env1' => states, 'env2' => states}
9
+ state_list = { 'env1' => states, 'env2' => states }
10
10
 
11
11
  ::ProxyAPI::Salt.any_instance.stubs(:states_list).returns(state_list)
12
+
13
+ # FIXME #12143
14
+ FactoryGirl.create(:permission, :name => 'view_salt_environments',
15
+ :resource_type => 'ForemanSalt::SaltEnvironment')
12
16
  end
13
17
 
14
18
  test 'index page' do
@@ -42,5 +42,14 @@ module ForemanSalt
42
42
  refute host.save
43
43
  assert host.errors.full_messages.include? 'Salt states must be in the environment of the host'
44
44
  end
45
+
46
+ test '#configuration? considers salt' do
47
+ host = FactoryGirl.build(:host)
48
+ proxy = FactoryGirl.build(:smart_proxy)
49
+
50
+ refute host.configuration?
51
+ host.salt_proxy = proxy
52
+ assert host.configuration?
53
+ end
45
54
  end
46
55
  end
@@ -19,7 +19,7 @@ module ForemanSalt
19
19
 
20
20
  test 'importing report updates host status' do
21
21
  ForemanSalt::ReportImporter.import(@report)
22
- assert_equal Host.find_by_name(@host).host_status, 'Error'
22
+ assert Host.find_by_name(@host).get_status(HostStatus::ConfigurationStatus).error?
23
23
  end
24
24
 
25
25
  test 'importing report has correct status' do
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.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: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - <
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<"
24
+ - - <
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: foreman-tasks
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.7.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.1
41
41
  description: Foreman Plug-in for Salt
@@ -67,7 +67,6 @@ files:
67
67
  - app/controllers/foreman_salt/salt_modules_controller.rb
68
68
  - app/controllers/foreman_salt/state_importer.rb
69
69
  - app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb
70
- - app/helpers/concerns/foreman_salt/layout_helper_extensions.rb
71
70
  - app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb
72
71
  - app/helpers/foreman_salt/salt_keys_helper.rb
73
72
  - app/helpers/foreman_salt/salt_modules_helper.rb
@@ -137,9 +136,11 @@ files:
137
136
  - db/migrate/20150411003302_add_environments_to_modules.rb
138
137
  - db/migrate/20150509094409_rename_join_tables.rb
139
138
  - db/migrate/20150509101505_add_primary_keys.rb
140
- - db/seeds.d/75-salt-seeds.rb
139
+ - db/seeds.d/75-salt_seeds.rb
141
140
  - lib/foreman_salt.rb
142
141
  - lib/foreman_salt/engine.rb
142
+ - lib/foreman_salt/extensions.rb
143
+ - lib/foreman_salt/plugin.rb
143
144
  - lib/foreman_salt/version.rb
144
145
  - lib/tasks/foreman_salt_tasks.rake
145
146
  - test/factories/foreman_salt_factories.rb
@@ -171,17 +172,17 @@ require_paths:
171
172
  - lib
172
173
  required_ruby_version: !ruby/object:Gem::Requirement
173
174
  requirements:
174
- - - ">="
175
+ - - '>='
175
176
  - !ruby/object:Gem::Version
176
177
  version: '0'
177
178
  required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  requirements:
179
- - - ">="
180
+ - - '>='
180
181
  - !ruby/object:Gem::Version
181
182
  version: '0'
182
183
  requirements: []
183
184
  rubyforge_project:
184
- rubygems_version: 2.4.5
185
+ rubygems_version: 2.4.8
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: Foreman Plug-in for Salt
@@ -1,20 +0,0 @@
1
- module ForemanSalt
2
- module LayoutHelperExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- alias_method_chain :authorized_associations_permission_name, :salt
7
- end
8
-
9
- # Foreman tries to magically guess permission names, but it doesn't work
10
- # with plugins. #11408 ForemanSalt models that require permissions provide
11
- # a self.permission_name method
12
- def authorized_associations_permission_name_with_salt(klass)
13
- if klass.respond_to?(:permission_name)
14
- klass.permission_name(:view)
15
- else
16
- authorized_associations_permission_name_without_salt(klass)
17
- end
18
- end
19
- end
20
- end