foreman_salt 10.1.0 → 10.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +1 -0
  4. data/app/controllers/foreman_salt/minions_controller.rb +1 -1
  5. data/app/controllers/foreman_salt/salt_environments_controller.rb +1 -1
  6. data/app/controllers/foreman_salt/salt_modules_controller.rb +4 -4
  7. data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +1 -1
  8. data/app/models/foreman_salt/concerns/host_managed_extensions.rb +2 -1
  9. data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +11 -13
  10. data/app/overrides/salt_environment_host_selector.rb +11 -6
  11. data/app/overrides/salt_environment_hostgroup_selector.rb +8 -5
  12. data/app/overrides/salt_proxy_selector.rb +12 -8
  13. data/app/services/foreman_salt/fact_parser.rb +7 -5
  14. data/app/services/foreman_salt/report_importer.rb +2 -0
  15. data/config/routes.rb +5 -7
  16. data/lib/foreman_salt/version.rb +1 -1
  17. data/test/factories/foreman_salt_factories.rb +1 -11
  18. data/test/functional/api/v2/salt_keys_controller_test.rb +1 -1
  19. data/test/functional/api/v2/salt_states_controller_test.rb +5 -5
  20. data/test/functional/minions_controller_test.rb +1 -1
  21. data/test/integration/salt_autosign_test.rb +7 -0
  22. data/test/integration/salt_environment_test.rb +1 -1
  23. data/test/integration/salt_keys_test.rb +9 -2
  24. data/test/integration/salt_module_test.rb +2 -6
  25. data/test/unit/grains_centos.json +4 -2
  26. data/test/unit/grains_importer_test.rb +2 -1
  27. data/test/unit/host_extensions_test.rb +18 -13
  28. data/test/unit/hostgroup_extensions_test.rb +17 -3
  29. data/test/unit/report_importer_test.rb +2 -2
  30. data/test/unit/salt_fact_parser_test.rb +46 -0
  31. data/test/unit/salt_keys_test.rb +3 -3
  32. data/test/unit/salt_modules_test.rb +1 -1
  33. metadata +17 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0d07824ea3e38fef2e9e0e6d29013dddc9e09d201144c0f2513e6afe482f8bb
4
- data.tar.gz: a6bb3c8d79328b30ed8c0191274e71034c3f78140bd278d89679872e60373407
3
+ metadata.gz: 45be269828ccb4c9b6990f04eb7d4bceb4080448199dd88c6058c2678892fa68
4
+ data.tar.gz: 6abed1b754f72ad653f460414b4c7dcbb4f4612e325f01709155597d3ea72e92
5
5
  SHA512:
6
- metadata.gz: 4f134063a3d744cdc69944c72de6cfb480758cd335b17448a207a818219f3426370500493fed8c449649631c7d54416d915c012730f021b0db5e271edfea81fc
7
- data.tar.gz: a576753c9fe866c74c360214f3b8ef235144c596cde0df4bc6702d5cae2da2b3f8fd3307e524527a107c470a8ad2549a13efe92a2f0ce160615dc693c89544d0
6
+ metadata.gz: 02e65952f994dd58c780d1221bbaae4e63820ab2d2bdf6c27418cd6447dcc449310de2fd25fd28c831d157a1a22cf5c0c68afe74d2952a69b484870bde86a0d2
7
+ data.tar.gz: 85bf905813499b17af6ab9af5e398d57e7e1039eede9b374c2e6a9e52a52684258c07c774f117347378ad4293c05180cbb16069f96bb0d33b7a917bcecd5f212
data/README.md CHANGED
@@ -13,6 +13,7 @@ This plug-in adds support for Salt to Foreman.
13
13
  | --------------- | --------------:|
14
14
  | <= 1.16 | 10.0.0 |
15
15
  | >= 1.17 | 10.1.0 |
16
+ | >= 1.21 | 10.2.0 |
16
17
 
17
18
  ## Documentation
18
19
 
@@ -18,6 +18,7 @@ module ForemanSalt
18
18
 
19
19
  def load_vars_for_ajax
20
20
  return unless @host
21
+
21
22
  @obj = @host
22
23
  @salt_environment = @host.salt_environment if @host
23
24
  @selected = @host.salt_modules
@@ -26,7 +26,7 @@ module ForemanSalt
26
26
 
27
27
  def run
28
28
  if @minion.saltrun!
29
- notice _('Successfully executed, check log files for more details')
29
+ success _('Successfully executed, check log files for more details')
30
30
  else
31
31
  error @minion.errors[:base].to_sentence
32
32
  end
@@ -27,7 +27,7 @@ module ForemanSalt
27
27
 
28
28
  def update
29
29
  if @salt_environment.update_attributes(salt_environment_params)
30
- notice _('Successfully updated %s.' % @salt_environment.to_s)
30
+ success _('Successfully updated %s.' % @salt_environment.to_s)
31
31
  redirect_to salt_environments_path
32
32
  else
33
33
  process_error
@@ -31,7 +31,7 @@ module ForemanSalt
31
31
 
32
32
  def update
33
33
  if @salt_module.update_attributes(salt_module_params)
34
- notice _('Successfully updated %s.' % @salt_module.to_s)
34
+ success _('Successfully updated %s.' % @salt_module.to_s)
35
35
  redirect_to salt_modules_path
36
36
  else
37
37
  process_error
@@ -63,14 +63,14 @@ module ForemanSalt
63
63
  @deletes = result[:deletes]
64
64
 
65
65
  if @changes.empty?
66
- notice _('No changes found')
66
+ info _('No changes found')
67
67
  redirect_to salt_modules_path
68
68
  end
69
69
  end
70
70
 
71
71
  def apply_changes
72
72
  if params[:changed].blank?
73
- notice _('No changes found')
73
+ info _('No changes found')
74
74
  else
75
75
  params[:changed].each do |environment, states|
76
76
  next unless states[:add] || states[:remove]
@@ -80,7 +80,7 @@ module ForemanSalt
80
80
  end
81
81
 
82
82
  clean_orphans
83
- notice _('Successfully imported')
83
+ success _('Successfully imported')
84
84
  end
85
85
  redirect_to salt_modules_path
86
86
  end
@@ -3,7 +3,7 @@ module ForemanSalt
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module Overrides
6
- def proxy_actions(proxy, authorizer)
6
+ def feature_actions(proxy, authorizer)
7
7
  actions = super
8
8
 
9
9
  if proxy.has_feature?('Salt')
@@ -4,7 +4,7 @@ module ForemanSalt
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module Overrides
7
- def configuration
7
+ def configuration?
8
8
  super || !!salt_proxy
9
9
  end
10
10
 
@@ -49,6 +49,7 @@ module ForemanSalt
49
49
 
50
50
  def salt_modules_for_enc
51
51
  return [] unless salt_environment
52
+
52
53
  modules = salt_modules + (hostgroup ? hostgroup.all_salt_modules : [])
53
54
  ForemanSalt::SaltModule.in_environment(salt_environment).where(:id => modules).pluck("salt_modules.name").uniq
54
55
  end
@@ -28,31 +28,29 @@ module ForemanSalt
28
28
  end
29
29
 
30
30
  def salt_proxy
31
- return super unless ancestry.present?
32
- SmartProxy.find_by_id(inherited_salt_proxy_id)
33
- end
34
-
35
- def inherited_salt_proxy_id
36
31
  if ancestry.present?
37
- self[:salt_proxy_id] || self.class.sort_by_ancestry(ancestors.where('salt_proxy_id is not NULL')).last.try(:salt_proxy_id)
32
+ SmartProxy.with_features('Salt').find_by_id(inherited_salt_proxy_id)
38
33
  else
39
- salt_proxy_id
34
+ super
40
35
  end
41
36
  end
42
37
 
43
- def salt_environment
44
- return super unless ancestry.present?
45
- ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
38
+ def inherited_salt_proxy_id
39
+ self[:salt_proxy_id] || nested(:salt_proxy_id)
46
40
  end
47
41
 
48
- def inherited_salt_environment_id
42
+ def salt_environment
49
43
  if ancestry.present?
50
- self[:salt_environment_id] || self.class.sort_by_ancestry(ancestors.where('salt_environment_id is not NULL')).last.try(:salt_environment_id)
44
+ ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
51
45
  else
52
- salt_environment_id
46
+ super
53
47
  end
54
48
  end
55
49
 
50
+ def inherited_salt_environment_id
51
+ self[:salt_environment_id] || nested(:salt_environment_id)
52
+ end
53
+
56
54
  def salt_master
57
55
  salt_proxy.to_s
58
56
  end
@@ -1,9 +1,14 @@
1
1
  selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironment.all, :id, :name,
2
2
  { :include_blank => blank_or_inherit_f(f, :salt_environment) },
3
- { :label => _('Salt Environment'), :onchange => 'update_salt_states(this)', :'data-url' => salt_environment_selected_minions_path,
4
- :'data-host-id' => (@host || @hostgroup).id, :help_inline => :indicator} %>"
3
+ { :label => _('Salt Environment'),
4
+ :onchange => 'update_salt_states(this)',
5
+ :'data-url' => salt_environment_selected_minions_path,
6
+ :'data-host-id' => (@host || @hostgroup).id,
7
+ :help_inline => :indicator} %>"
5
8
 
6
- Deface::Override.new(:virtual_path => 'hosts/_form',
7
- :name => 'add_salt_environment_to_host',
8
- :insert_bottom => 'div#primary',
9
- :text => selector_text)
9
+ Deface::Override.new(
10
+ :virtual_path => 'hosts/_form',
11
+ :name => 'add_salt_environment_to_host',
12
+ :insert_bottom => 'div#primary',
13
+ :text => selector_text
14
+ )
@@ -1,9 +1,12 @@
1
1
  selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironment.all, :id, :name,
2
2
  { :include_blank => blank_or_inherit_f(f, :salt_environment) },
3
- { :label => _('Salt Environment'), :onchange => 'update_salt_states(this)', :'data-url' => salt_environment_selected_hostgroups_path,
3
+ { :label => _('Salt Environment'), :onchange => 'update_salt_states(this)',
4
+ :'data-url' => salt_environment_selected_hostgroups_path,
4
5
  :'data-host-id' => (@host || @hostgroup).id, :help_inline => :indicator} %>"
5
6
 
6
- Deface::Override.new(:virtual_path => 'hostgroups/_form',
7
- :name => 'add_salt_environment_to_hostgroup',
8
- :insert_bottom => 'div#primary',
9
- :text => selector_text)
7
+ Deface::Override.new(
8
+ :virtual_path => 'hostgroups/_form',
9
+ :name => 'add_salt_environment_to_hostgroup',
10
+ :insert_bottom => 'div#primary',
11
+ :text => selector_text
12
+ )
@@ -2,12 +2,16 @@ selector_text = "<%= select_f f, :salt_proxy_id, SmartProxy.unscoped.with_featur
2
2
  { :include_blank => blank_or_inherit_f(f, :salt_proxy) },
3
3
  { :label => _('Salt Master') } %>"
4
4
 
5
- Deface::Override.new(:virtual_path => 'hosts/_form',
6
- :name => 'add_salt_proxy_to_host',
7
- :insert_bottom => 'div#primary',
8
- :text => selector_text)
5
+ Deface::Override.new(
6
+ :virtual_path => 'hosts/_form',
7
+ :name => 'add_salt_proxy_to_host',
8
+ :insert_bottom => 'div#primary',
9
+ :text => selector_text
10
+ )
9
11
 
10
- Deface::Override.new(:virtual_path => 'hostgroups/_form',
11
- :name => 'add_salt_proxy_to_hostgroup',
12
- :insert_bottom => 'div#primary',
13
- :text => selector_text)
12
+ Deface::Override.new(
13
+ :virtual_path => 'hostgroups/_form',
14
+ :name => 'add_salt_proxy_to_hostgroup',
15
+ :insert_bottom => 'div#primary',
16
+ :text => selector_text
17
+ )
@@ -56,17 +56,18 @@ module ForemanSalt
56
56
 
57
57
  facts.each do |fact, value|
58
58
  next unless value && fact.to_s =~ /^ip_interfaces/
59
- (_, interface_name, _) = fact.split(FactName::SEPARATOR)
59
+
60
+ (_, interface_name) = fact.split(FactName::SEPARATOR)
60
61
 
61
62
  next if (IPAddr.new('fe80::/10').include?(value) rescue false)
62
-
63
+
63
64
  if !interface_name.blank? && interface_name != 'lo'
64
65
  interface = interfaces.fetch(interface_name, {})
65
66
  interface[:macaddress] = macs[interface_name]
66
- if Net::Validations::validate_ip6(value)
67
- interface[:ipaddress6] = value
67
+ if Net::Validations.validate_ip6(value)
68
+ interface[:ipaddress6] = value unless interface.include?(:ipaddress6)
68
69
  else
69
- interface[:ipaddress] = value
70
+ interface[:ipaddress] = value unless interface.include?(:ipaddress)
70
71
  end
71
72
  interfaces[interface_name] = interface
72
73
  end
@@ -101,6 +102,7 @@ module ForemanSalt
101
102
  @macs = {}
102
103
  facts.each do |fact, value|
103
104
  next unless value && fact.to_s =~ /^hwaddr_interfaces/
105
+
104
106
  data = fact.split(FactName::SEPARATOR)
105
107
  interface = data[1]
106
108
  macs[interface] = value
@@ -5,6 +5,7 @@ module ForemanSalt
5
5
 
6
6
  def self.import(raw, proxy_id = nil)
7
7
  fail ::Foreman::Exception.new(_('Invalid report')) unless raw.is_a?(Hash)
8
+
8
9
  raw.map do |host, report|
9
10
  importer = ForemanSalt::ReportImporter.new(host, report, proxy_id)
10
11
  importer.import
@@ -141,6 +142,7 @@ module ForemanSalt
141
142
 
142
143
  @report = ConfigReport.new(:host => @host, :reported_at => start_time, :status => status, :metrics => metrics)
143
144
  return @report unless @report.save
145
+
144
146
  import_log_messages
145
147
  end
146
148
 
data/config/routes.rb CHANGED
@@ -19,13 +19,11 @@ Rails.application.routes.draw do
19
19
  end
20
20
  end
21
21
 
22
- constraints :id => /[\w\.-]+/ do
23
- resources :salt_modules, :controller => 'foreman_salt/salt_modules' do
24
- collection do
25
- get 'import'
26
- get 'auto_complete_search'
27
- post 'apply_changes'
28
- end
22
+ resources :salt_modules, :controller => 'foreman_salt/salt_modules' do
23
+ collection do
24
+ get 'import'
25
+ get 'auto_complete_search'
26
+ post 'apply_changes'
29
27
  end
30
28
  end
31
29
 
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '10.1.0'
2
+ VERSION = '10.2.0'
3
3
  end
@@ -9,17 +9,7 @@ FactoryBot.define do
9
9
  end
10
10
 
11
11
  FactoryBot.modify do
12
- factory :host do
13
- trait :with_salt_proxy do
14
- salt_proxy { FactoryBot.build :smart_proxy, :with_salt_feature }
15
- end
16
- end
17
-
18
12
  factory :hostgroup do
19
- trait :with_salt_proxy do
20
- salt_proxy { FactoryBot.build :smart_proxy, :with_salt_feature }
21
- end
22
-
23
13
  trait :with_salt_modules do
24
14
  salt_environment { FactoryBot.build :salt_environment }
25
15
  salt_modules { FactoryBot.create_list :salt_module, 10, :salt_environments => [self.salt_environment] }
@@ -28,7 +18,7 @@ FactoryBot.modify do
28
18
 
29
19
  factory :smart_proxy do
30
20
  trait :with_salt_feature do
31
- features { [::Feature.where(:name => 'Salt').first_or_create] }
21
+ features { [::Feature.find_or_create_by(:name => 'Salt')] }
32
22
  end
33
23
  end
34
24
  end
@@ -15,7 +15,7 @@ class ::ForemanSalt::Api::V2::SaltKeysControllerTest < ActionController::TestCas
15
15
 
16
16
  test 'should update keys' do
17
17
  ProxyAPI::Salt.any_instance.expects(:key_accept).once.returns(true)
18
- put :update, params: { :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com', :key => { :state => 'accepted' } }
18
+ put :update, params: { :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com', :state => 'accepted' }
19
19
  assert_response :success
20
20
  end
21
21
 
@@ -52,7 +52,7 @@ class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestC
52
52
  test 'should import only from a given environment' do
53
53
  post :import, params: { :smart_proxy_id => @proxy.id, :salt_environments => ['env2'] }
54
54
  assert_response :success
55
- refute ::ForemanSalt::SaltEnvironment.where(:name => 'env1').first
55
+ assert_not ::ForemanSalt::SaltEnvironment.where(:name => 'env1').first
56
56
  assert ::ForemanSalt::SaltEnvironment.where(:name => 'env2').first
57
57
  end
58
58
 
@@ -70,15 +70,15 @@ class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestC
70
70
  state = FactoryBot.create :salt_module
71
71
  post :import, params: { :smart_proxy_id => @proxy.id, :actions => ['remove'] }
72
72
  assert_response :success
73
- refute ::ForemanSalt::SaltModule.where(:id => state).first
74
- refute ::ForemanSalt::SaltModule.where(:name => 'state1').first
73
+ assert_not ::ForemanSalt::SaltModule.where(:id => state).first
74
+ assert_not ::ForemanSalt::SaltModule.where(:name => 'state1').first
75
75
  end
76
76
 
77
77
  test 'dryrun should do nothing' do
78
78
  post :import, params: { :smart_proxy_id => @proxy.id, :dryrun => true }
79
79
  assert_response :success
80
- refute ::ForemanSalt::SaltModule.all.any?
81
- refute ::ForemanSalt::SaltEnvironment.all.any?
80
+ assert_not ::ForemanSalt::SaltModule.all.any?
81
+ assert_not ::ForemanSalt::SaltEnvironment.all.any?
82
82
  end
83
83
  end
84
84
  end
@@ -3,7 +3,7 @@ require 'test_plugin_helper'
3
3
  module ForemanSalt
4
4
  class MinionsControllerTest < ActionController::TestCase
5
5
  test 'salt smart proxy should get salt external node' do
6
- User.current = nil
6
+ User.current = User.anonymous_admin
7
7
  Setting[:restrict_registered_smart_proxies] = true
8
8
  Setting[:require_ssl_smart_proxies] = false
9
9
 
@@ -15,6 +15,13 @@ module ForemanSalt
15
15
  assert_row_button(smart_proxies_path, @proxy.name, 'Salt Autosign', true)
16
16
  end
17
17
 
18
+ test 'smart proxy details has autosign link' do
19
+ visit smart_proxy_path(@proxy)
20
+ assert page.has_link? "Salt Autosign"
21
+ click_link "Salt Autosign"
22
+ assert page.has_content?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
23
+ end
24
+
18
25
  test 'index page' do
19
26
  visit smart_proxy_salt_autosign_index_path(:smart_proxy_id => @proxy.id)
20
27
  assert find_link('Keys').visible?, 'Keys is not visible'
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
2
2
  require 'integration_test_helper'
3
3
 
4
4
  module ForemanSalt
5
- class SaltEnvironmentTest < ActionDispatch::IntegrationTest
5
+ class SaltEnvironmentTest < IntegrationTestWithJavascript
6
6
  test 'index page' do
7
7
  FactoryBot.create_list :salt_environment, 5
8
8
  assert_index_page(salt_environments_path, 'Salt Environment', 'New Salt Environment')
@@ -7,10 +7,10 @@ module ForemanSalt
7
7
  @proxy = FactoryBot.create :smart_proxy, :with_salt_feature
8
8
 
9
9
  ::ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
10
- 'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
10
+ 'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
11
11
  'saltclient01.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1' },
12
12
  'saltclient02.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c2' },
13
- 'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
13
+ 'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
14
14
  )
15
15
  end
16
16
 
@@ -18,6 +18,13 @@ module ForemanSalt
18
18
  assert_row_button(smart_proxies_path, @proxy.name, 'Salt Keys', true)
19
19
  end
20
20
 
21
+ test 'smart proxy details has keys link' do
22
+ visit smart_proxy_path(@proxy)
23
+ assert page.has_link? "Salt Keys"
24
+ click_link "Salt Keys"
25
+ assert page.has_content?("Salt Keys on #{@proxy.hostname}"), 'Page title does not appear'
26
+ end
27
+
21
28
  test 'index page' do
22
29
  visit smart_proxy_salt_keys_path(:smart_proxy_id => @proxy.id)
23
30
  assert find_link('Autosign').visible?, 'Autosign is not visible'
@@ -2,18 +2,14 @@ require 'test_plugin_helper'
2
2
  require 'integration_test_helper'
3
3
 
4
4
  module ForemanSalt
5
- class SaltModuleTest < ActionDispatch::IntegrationTest
5
+ class SaltModuleTest < IntegrationTestWithJavascript
6
6
  setup do
7
- User.current = User.anonymous_admin
7
+ User.current = users :admin
8
8
 
9
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)
13
-
14
- # FIXME #12143
15
- FactoryBot.create(:permission, :name => 'view_salt_environments',
16
- :resource_type => 'ForemanSalt::SaltEnvironment')
17
13
  end
18
14
 
19
15
  test 'index page' do
@@ -51,6 +51,7 @@
51
51
  "defaultencoding": "UTF8",
52
52
  "path": "/sbin:/usr/sbin:/bin:/usr/bin",
53
53
  "ip_interfaces::eth0::0": "10.7.13.141",
54
+ "ip_interfaces::eth0::1": "10.7.23.141",
54
55
  "manufacturer": "Red Hat",
55
56
  "fqdn": "saltclient01.example.com",
56
57
  "os": "CentOS",
@@ -95,8 +96,9 @@
95
96
  "osrelease": "6.5",
96
97
  "num_cpus": 1,
97
98
  "virtual": "kvm",
98
- "ipv4::0": "10.7.13.141",
99
- "ipv4::1": "127.0.0.1",
99
+ "ipv4::0": "10.7.23.141",
100
+ "ipv4::1": "10.7.13.141",
101
+ "ipv4::2": "127.0.0.1",
100
102
  "_type": "foreman_salt",
101
103
  "nodename": "saltclient01.example.com",
102
104
  "os_family": "RedHat",
@@ -6,7 +6,8 @@ module ForemanSalt
6
6
  allow_transactions_for_any_importer
7
7
 
8
8
  setup do
9
- User.current = User.find_by_login 'admin'
9
+ disable_orchestration
10
+ User.current = users :admin
10
11
  Setting[:create_new_host_when_facts_are_uploaded] = true
11
12
 
12
13
  Operatingsystem.where(:name => 'CentOS', :major => '6', :minor => '5').delete_all
@@ -3,27 +3,32 @@ require 'test_plugin_helper'
3
3
  module ForemanSalt
4
4
  class HostExtensionsTest < ActiveSupport::TestCase
5
5
  setup do
6
- User.current = User.find_by_login 'admin'
6
+ User.current = users :admin
7
+ @proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
7
8
  end
8
9
 
9
10
  test 'host has a salt smart proxy' do
10
- host = FactoryBot.create :host, :with_salt_proxy
11
+ host = FactoryBot.create :host
12
+ host.salt_proxy = @proxy
11
13
  assert host.salt_proxy.has_feature? 'Salt'
12
14
  end
13
15
 
14
16
  test 'smart_proxy_ids returns salt smart proxy' do
15
- host = FactoryBot.create :host, :with_salt_proxy
17
+ host = FactoryBot.create :host
18
+ host.salt_proxy = @proxy
16
19
  assert host.smart_proxy_ids.include? host.salt_proxy_id
17
20
  end
18
21
 
19
22
  test 'host params includes salt_master' do
20
- host = FactoryBot.create :host, :with_salt_proxy
23
+ host = FactoryBot.create :host
24
+ host.salt_proxy = @proxy
21
25
  assert host.params.key? 'salt_master'
22
26
  assert_equal host.params['salt_master'], host.salt_master
23
27
  end
24
28
 
25
29
  test 'host inherits salt proxy from host group' do
26
- hostgroup = FactoryBot.create :hostgroup, :with_salt_proxy
30
+ hostgroup = FactoryBot.create :hostgroup
31
+ hostgroup.salt_proxy = @proxy
27
32
  host = FactoryBot.create :host, :hostgroup => hostgroup
28
33
  host.set_hostgroup_defaults
29
34
  assert_equal host.salt_proxy, hostgroup.salt_proxy
@@ -36,25 +41,25 @@ module ForemanSalt
36
41
  state = FactoryBot.create :salt_module
37
42
  other_environment.salt_modules << state
38
43
 
39
- host = FactoryBot.create :host, :with_salt_proxy, :salt_environment => hosts_environment
44
+ host = FactoryBot.create :host, :salt_environment => hosts_environment
45
+ host.salt_proxy = @proxy
40
46
  host.salt_modules = [state]
41
47
 
42
- refute host.save
48
+ assert_not host.save
43
49
  assert host.errors.full_messages.include? 'Salt states must be in the environment of the host'
44
50
  end
45
51
 
46
52
  test '#configuration? considers salt' do
47
53
  host = FactoryBot.build(:host)
48
- proxy = FactoryBot.build(:smart_proxy)
49
-
50
- refute host.configuration?
51
- host.salt_proxy = proxy
54
+ assert_not host.configuration?
55
+ host.salt_proxy = @proxy
52
56
  assert host.configuration?
53
57
  end
54
58
 
55
59
  context 'key handling' do
56
60
  before do
57
- @host = FactoryBot.create(:host, :with_salt_proxy, :managed, :build => true)
61
+ @host = FactoryBot.create(:host, :managed, :build => true)
62
+ @host.salt_proxy = @proxy
58
63
  @key_stub = stub("key")
59
64
  ForemanSalt::SmartProxies::SaltKeys.expects(:find).at_least_once.with(@host.salt_proxy, @host.fqdn).returns(@key_stub)
60
65
  end
@@ -66,7 +71,7 @@ module ForemanSalt
66
71
  end
67
72
 
68
73
  test 'host key is deleted when host is removed' do
69
- @key_stub.expects(:delete).returns(true)
74
+ @key_stub.expects(:delete).at_least_once.returns(true)
70
75
  assert @host.destroy
71
76
  end
72
77
  end
@@ -3,11 +3,13 @@ require 'test_plugin_helper'
3
3
  module ForemanSalt
4
4
  class HostgroupExtensionsTest < ActiveSupport::TestCase
5
5
  setup do
6
- User.current = User.find_by_login 'admin'
6
+ User.current = users :admin
7
+ @proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
7
8
  end
8
9
 
9
10
  test 'host group has a salt smart proxy' do
10
- hostgroup = FactoryBot.create :hostgroup, :with_salt_proxy
11
+ hostgroup = FactoryBot.create :hostgroup
12
+ hostgroup.salt_proxy = @proxy
11
13
  assert hostgroup.salt_proxy.features.map(&:name).include? 'Salt'
12
14
  end
13
15
 
@@ -19,11 +21,23 @@ module ForemanSalt
19
21
 
20
22
  test 'child host group inherits salt proxy from child parent' do
21
23
  parent = FactoryBot.create :hostgroup
22
- child_one = FactoryBot.create :hostgroup, :with_salt_proxy, :parent => parent
24
+ child_one = FactoryBot.create :hostgroup, :parent => parent
25
+ child_one.salt_proxy = @proxy
26
+ child_one.reload
23
27
  child_two = FactoryBot.create :hostgroup, :parent => child_one
24
28
  assert_equal child_two.salt_proxy, child_one.salt_proxy
25
29
  end
26
30
 
31
+ test 'child host group inherits salt environment from child parent' do
32
+ environment = FactoryBot.create :salt_environment
33
+ parent = FactoryBot.create :hostgroup
34
+ child_one = FactoryBot.create :hostgroup, :parent => parent
35
+ child_one.salt_environment = environment
36
+ child_one.reload
37
+ child_two = FactoryBot.create :hostgroup, :parent => child_one
38
+ assert_equal child_two.salt_environment, child_one.salt_environment
39
+ end
40
+
27
41
  test 'child and parent salt modules are combined' do
28
42
  environment = FactoryBot.create :salt_environment
29
43
  parent = FactoryBot.create :hostgroup, :with_salt_modules, :salt_environment => environment
@@ -3,7 +3,7 @@ require 'test_plugin_helper'
3
3
  module ForemanSalt
4
4
  class ReportImporterTest < ActiveSupport::TestCase
5
5
  setup do
6
- User.current = User.find_by_login 'admin'
6
+ User.current = users :admin
7
7
  Setting[:create_new_host_when_facts_are_uploaded] = true
8
8
 
9
9
  @report = JSON.parse(File.read(File.join(Engine.root, 'test', 'unit', 'highstate.json')))
@@ -12,7 +12,7 @@ module ForemanSalt
12
12
  end
13
13
 
14
14
  test 'importing report creates a host' do
15
- refute Host.find_by_name(@host)
15
+ assert_not Host.find_by_name(@host)
16
16
  ForemanSalt::ReportImporter.import(@report)
17
17
  assert Host.find_by_name(@host)
18
18
  end
@@ -0,0 +1,46 @@
1
+ require 'test_plugin_helper'
2
+
3
+ module ForemanSalt
4
+ class SaltFactsParserTest < ActiveSupport::TestCase
5
+ attr_reader :importer
6
+
7
+ def setup
8
+ grains = JSON.parse(File.read(File.join(Engine.root, 'test', 'unit', 'grains_centos.json')))
9
+ @importer = FactParser.new grains["facts"]
10
+ User.current = users :admin
11
+ end
12
+
13
+ test "should return list of interfaces" do
14
+ assert importer.interfaces.present?
15
+ assert_not_nil importer.suggested_primary_interface(FactoryBot.build(:host))
16
+ assert importer.interfaces.key?(importer.suggested_primary_interface(FactoryBot.build(:host)).first)
17
+ end
18
+
19
+ test "should set operatingsystem correctly" do
20
+ os = importer.operatingsystem
21
+ assert os.present?
22
+ assert_equal 'CentOS', os.name
23
+ assert_equal '6', os.major
24
+ assert_equal '5', os.minor
25
+ assert_equal 'CentOS 6.5', os.title
26
+ end
27
+
28
+ test "should set domain correctly" do
29
+ domain = importer.domain
30
+ assert domain.present?
31
+ assert_equal 'example.com', domain.name
32
+ end
33
+
34
+ test "should set ip correctly" do
35
+ assert_equal '10.7.13.141', importer.ip
36
+ end
37
+
38
+ test "should set primary_interface correctly" do
39
+ assert_equal 'eth0', importer.primary_interface
40
+ end
41
+
42
+ test "should set mac correctly" do
43
+ assert_equal '52:54:00:35:30:2a', importer.mac
44
+ end
45
+ end
46
+ end
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
2
2
 
3
3
  class SaltKeysTest < ActiveSupport::TestCase
4
4
  setup do
5
- User.current = User.find_by_login 'admin'
5
+ User.current = users :admin
6
6
 
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] }
@@ -10,10 +10,10 @@ class SaltKeysTest < ActiveSupport::TestCase
10
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
- 'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
13
+ 'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
14
14
  'saltclient01.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1' },
15
15
  'saltclient02.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c2' },
16
- 'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
16
+ 'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
17
17
  )
18
18
  end
19
19
 
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
2
2
 
3
3
  class SaltModulesTest < ActiveSupport::TestCase
4
4
  setup do
5
- User.current = User.find_by_login 'admin'
5
+ User.current = users :admin
6
6
  end
7
7
 
8
8
  test 'salt module has a valid name' do
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: 10.1.0
4
+ version: 10.2.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: 2018-07-13 00:00:00.000000000 Z
11
+ date: 2019-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -161,6 +161,7 @@ files:
161
161
  - test/unit/host_extensions_test.rb
162
162
  - test/unit/hostgroup_extensions_test.rb
163
163
  - test/unit/report_importer_test.rb
164
+ - test/unit/salt_fact_parser_test.rb
164
165
  - test/unit/salt_keys_test.rb
165
166
  - test/unit/salt_modules_test.rb
166
167
  homepage: https://github.com/theforeman/foreman_salt
@@ -183,27 +184,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  version: '0'
184
185
  requirements: []
185
186
  rubyforge_project:
186
- rubygems_version: 2.7.7
187
+ rubygems_version: 2.7.6
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Foreman Plug-in for Salt
190
191
  test_files:
191
192
  - test/integration/salt_environment_test.rb
193
+ - test/integration/salt_module_test.rb
192
194
  - test/integration/salt_autosign_test.rb
193
195
  - test/integration/salt_keys_test.rb
194
- - test/integration/salt_module_test.rb
195
- - test/functional/minions_controller_test.rb
196
- - test/functional/api/v2/salt_autosign_controller_test.rb
197
- - test/functional/api/v2/salt_environments_controller_test.rb
198
- - test/functional/api/v2/salt_keys_controller_test.rb
199
- - test/functional/api/v2/salt_states_controller_test.rb
200
- - test/test_plugin_helper.rb
201
196
  - test/factories/foreman_salt_factories.rb
202
- - test/unit/host_extensions_test.rb
203
- - test/unit/report_importer_test.rb
204
- - test/unit/grains_centos.json
197
+ - test/unit/grains_importer_test.rb
198
+ - test/unit/hostgroup_extensions_test.rb
205
199
  - test/unit/highstate.json
200
+ - test/unit/salt_fact_parser_test.rb
206
201
  - test/unit/salt_modules_test.rb
207
- - test/unit/hostgroup_extensions_test.rb
202
+ - test/unit/grains_centos.json
203
+ - test/unit/report_importer_test.rb
208
204
  - test/unit/salt_keys_test.rb
209
- - test/unit/grains_importer_test.rb
205
+ - test/unit/host_extensions_test.rb
206
+ - test/test_plugin_helper.rb
207
+ - test/functional/minions_controller_test.rb
208
+ - test/functional/api/v2/salt_autosign_controller_test.rb
209
+ - test/functional/api/v2/salt_states_controller_test.rb
210
+ - test/functional/api/v2/salt_environments_controller_test.rb
211
+ - test/functional/api/v2/salt_keys_controller_test.rb