foreman_salt 9.0.1 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb +18 -18
  3. data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +22 -21
  4. data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +23 -23
  5. data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +11 -9
  6. data/app/models/foreman_salt/concerns/host_managed_extensions.rb +25 -26
  7. data/db/migrate/20140813081913_add_salt_proxy_to_host_and_host_group.rb +1 -1
  8. data/db/migrate/20140817210214_create_salt_modules.rb +2 -2
  9. data/db/migrate/20140829210214_add_salt_modules_to_hostgroups.rb +1 -1
  10. data/db/migrate/20140920232200_create_salt_environments.rb +2 -2
  11. data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +1 -1
  12. data/db/migrate/20150411003302_add_environments_to_modules.rb +1 -1
  13. data/db/migrate/20150509094409_rename_join_tables.rb +1 -1
  14. data/db/migrate/20150509101505_add_primary_keys.rb +1 -1
  15. data/db/migrate/20161103104146_add_index_to_join_tables.rb +1 -1
  16. data/lib/foreman_salt/version.rb +1 -1
  17. data/test/factories/foreman_salt_factories.rb +6 -6
  18. data/test/functional/api/v2/salt_autosign_controller_test.rb +4 -4
  19. data/test/functional/api/v2/salt_environments_controller_test.rb +4 -4
  20. data/test/functional/api/v2/salt_keys_controller_test.rb +4 -4
  21. data/test/functional/api/v2/salt_states_controller_test.rb +13 -13
  22. data/test/functional/minions_controller_test.rb +3 -3
  23. data/test/integration/salt_autosign_test.rb +1 -1
  24. data/test/integration/salt_environment_test.rb +2 -2
  25. data/test/integration/salt_keys_test.rb +1 -1
  26. data/test/integration/salt_module_test.rb +5 -5
  27. data/test/test_plugin_helper.rb +3 -3
  28. data/test/unit/grains_importer_test.rb +3 -0
  29. data/test/unit/host_extensions_test.rb +12 -12
  30. data/test/unit/hostgroup_extensions_test.rb +17 -17
  31. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 505150b65e85f4508c1128ef4d00643acb1ee271aa27f4e1087aff29fe861a29
4
- data.tar.gz: 7cb8eba18f16129c2dcfc1b223ca3ca46c4c5d0043dc06b4a1467107cfe834c4
3
+ metadata.gz: c6a5c38ada1b7092ea56ff7da05ebdfd13bff174ddd00b04d61813ea3f18b367
4
+ data.tar.gz: c559363f1e3a18b955b3707dc410cb094e6b4e4556ca99c4ae059c7cad09adb1
5
5
  SHA512:
6
- metadata.gz: 2f0b9777d3f10bdeb52a50cf8cb62328cf350f78088e224f77a51c5ebd1d43ca4ddaf8029f2b8de33ba6c4ceda2986f40009cf2147710277327afec2d1b2a94c
7
- data.tar.gz: 72fee87317574fec91bab0ecff7f61280659318a5a38b79bff7c54b64c3c65f6d995b7089a6303c9f7449575da86790606c01c9249aa0373fc82de313a852d01
6
+ metadata.gz: 240c3e9a0d46d6cf4ddebe976129af37917a108d55be3aeb434262a9cddd824b06e0266f41cc528703acef7e0f6c4ea7db013fa9c5262de6004ed1820c0927f3
7
+ data.tar.gz: 9eeb42cebc16d142a157c12e11da6121974516cd022e0efcdef841dc94d30b740f532ab730e491c0bb7e7eb6fb1b3dc366ecffcad749732c574d0d1d896c82d9
@@ -3,8 +3,25 @@ module ForemanSalt
3
3
  module HostgroupsControllerExtensions
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ module Overrides
7
+ def load_vars_for_ajax
8
+ super
9
+ @obj = @hostgroup
10
+ @salt_environment ||= @hostgroup.salt_environment
11
+
12
+ if @salt_environment
13
+ @inherited_salt_modules = @salt_environment.salt_modules.where(:id => @hostgroup.inherited_salt_modules)
14
+ @salt_modules = @salt_environment.salt_modules - @inherited_salt_modules
15
+ else
16
+ @inherited_salt_modules = @salt_modules = []
17
+ end
18
+
19
+ @selected = @hostgroup.salt_modules || []
20
+ end
21
+ end
22
+
6
23
  included do
7
- alias_method_chain :load_vars_for_ajax, :salt_modules
24
+ prepend Overrides
8
25
  end
9
26
 
10
27
  def salt_environment_selected
@@ -18,23 +35,6 @@ module ForemanSalt
18
35
  logger.info 'environment_id is required to render states'
19
36
  end
20
37
  end
21
-
22
- private
23
-
24
- def load_vars_for_ajax_with_salt_modules
25
- load_vars_for_ajax_without_salt_modules
26
- @obj = @hostgroup
27
- @salt_environment ||= @hostgroup.salt_environment
28
-
29
- if @salt_environment
30
- @inherited_salt_modules = @salt_environment.salt_modules.where(:id => @hostgroup.inherited_salt_modules)
31
- @salt_modules = @salt_environment.salt_modules - @inherited_salt_modules
32
- else
33
- @inherited_salt_modules = @salt_modules = []
34
- end
35
-
36
- @selected = @hostgroup.salt_modules || []
37
- end
38
38
  end
39
39
  end
40
40
  end
@@ -3,31 +3,32 @@ module ForemanSalt
3
3
  module HostsControllerExtensions
4
4
  extend ActiveSupport::Concern
5
5
 
6
- included do
7
- alias_method_chain :load_vars_for_ajax, :salt_modules
8
- alias_method_chain :process_hostgroup, :salt_modules
9
- end
6
+ module Overrides
7
+ def process_hostgroup
8
+ @hostgroup = Hostgroup.find(params[:host][:hostgroup_id]) if params[:host][:hostgroup_id].to_i > 0
9
+ return head(:not_found) unless @hostgroup
10
10
 
11
- def process_hostgroup_with_salt_modules
12
- @hostgroup = Hostgroup.find(params[:host][:hostgroup_id]) if params[:host][:hostgroup_id].to_i > 0
13
- return head(:not_found) unless @hostgroup
11
+ @salt_modules = @host.salt_modules if @host
12
+ @salt_environment = @host.salt_environment if @host
13
+ @inherited_salt_modules = @hostgroup.all_salt_modules
14
+ super
15
+ end
14
16
 
15
- @salt_modules = @host.salt_modules if @host
16
- @salt_environment = @host.salt_environment if @host
17
- @inherited_salt_modules = @hostgroup.all_salt_modules
18
- process_hostgroup_without_salt_modules
19
- end
17
+ private
20
18
 
21
- private
19
+ def load_vars_for_ajax
20
+ return unless @host
21
+ @obj = @host
22
+ @salt_environment = @host.salt_environment if @host
23
+ @selected = @host.salt_modules
24
+ @salt_modules = @host.salt_environment ? @salt_environment.salt_modules : []
25
+ @inherited_salt_modules = @host.hostgroup.all_salt_modules if @host.hostgroup
26
+ super
27
+ end
28
+ end
22
29
 
23
- def load_vars_for_ajax_with_salt_modules
24
- return unless @host
25
- @obj = @host
26
- @salt_environment = @host.salt_environment if @host
27
- @selected = @host.salt_modules
28
- @salt_modules = @host.salt_environment ? @salt_environment.salt_modules : []
29
- @inherited_salt_modules = @host.hostgroup.all_salt_modules if @host.hostgroup
30
- load_vars_for_ajax_without_salt_modules
30
+ included do
31
+ prepend Overrides
31
32
  end
32
33
  end
33
34
  end
@@ -2,37 +2,37 @@ module ForemanSalt
2
2
  module HostsHelperExtensions
3
3
  extend ActiveSupport::Concern
4
4
 
5
- included do
6
- alias_method_chain :host_title_actions, :salt
7
- alias_method_chain :show_appropriate_host_buttons, :salt
8
- alias_method_chain :overview_fields, :salt
9
- end
10
-
11
- def show_appropriate_host_buttons_with_salt(host)
12
- (show_appropriate_host_buttons_without_salt(host) +
5
+ module Overrides
6
+ def show_appropriate_host_buttons(host)
7
+ (super(host) +
13
8
  [(link_to_if_authorized(_('Salt ENC'), { :controller => :'foreman_salt/minions', :action => :node, :id => host },
14
9
  :title => _('Salt external nodes YAML dump'), :class => 'btn btn-default') unless host.salt_master.blank?)]).flatten.compact
15
- end
10
+ end
16
11
 
17
- def host_title_actions_with_salt(host)
18
- title_actions(
19
- button_group(
20
- if host.try(:salt_proxy)
21
- link_to_if_authorized(_('Run Salt'), { :controller => :'foreman_salt/minions', :action => :run, :id => host },
22
- :title => _('Trigger a state.highstate run on a node'), :class => 'btn btn-primary')
12
+ def host_title_actions(host)
13
+ title_actions(
14
+ button_group(
15
+ if host.try(:salt_proxy)
16
+ link_to_if_authorized(_('Run Salt'), { :controller => :'foreman_salt/minions', :action => :run, :id => host },
17
+ :title => _('Trigger a state.highstate run on a node'), :class => 'btn btn-primary')
23
18
  end
19
+ )
24
20
  )
25
- )
26
- host_title_actions_without_salt(host)
27
- end
21
+ super(host)
22
+ end
23
+
24
+ def overview_fields(host)
25
+ fields = super(host)
28
26
 
29
- def overview_fields_with_salt(host)
30
- fields = overview_fields_without_salt(host)
27
+ fields.insert(5, [_('Salt Master'), (link_to(host.salt_proxy, hosts_path(:search => "saltmaster = #{host.salt_proxy}")) if host.salt_proxy)])
28
+ fields.insert(6, [_('Salt Environment'), (link_to(host.salt_environment, hosts_path(:search => "salt_environment = #{host.salt_environment}")) if host.salt_environment)])
31
29
 
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)])
30
+ fields
31
+ end
32
+ end
34
33
 
35
- fields
34
+ included do
35
+ prepend Overrides
36
36
  end
37
37
  end
38
38
  end
@@ -2,19 +2,21 @@ module ForemanSalt
2
2
  module SmartProxiesHelperExtensions
3
3
  extend ActiveSupport::Concern
4
4
 
5
- included do
6
- alias_method_chain :proxy_actions, :salt_proxy
7
- end
5
+ module Overrides
6
+ def proxy_actions(proxy, authorizer)
7
+ actions = super
8
8
 
9
- def proxy_actions_with_salt_proxy(proxy, authorizer)
10
- actions = proxy_actions_without_salt_proxy(proxy, authorizer)
9
+ if proxy.has_feature?('Salt')
10
+ actions << display_link_if_authorized(_('Salt Keys'), :controller => 'foreman_salt/salt_keys', :action => 'index', :smart_proxy_id => proxy)
11
+ actions << display_link_if_authorized(_('Salt Autosign'), :controller => 'foreman_salt/salt_autosign', :action => 'index', :smart_proxy_id => proxy)
12
+ end
11
13
 
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)
14
+ actions
15
15
  end
16
+ end
16
17
 
17
- actions
18
+ included do
19
+ prepend Overrides
18
20
  end
19
21
  end
20
22
  end
@@ -3,6 +3,30 @@ module ForemanSalt
3
3
  module HostManagedExtensions
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ module Overrides
7
+ def configuration
8
+ super || !!salt_proxy
9
+ end
10
+
11
+ def params
12
+ params = super
13
+ params['salt_master'] = salt_master unless salt_master.blank?
14
+ params
15
+ end
16
+
17
+ def smart_proxy_ids
18
+ ids = super
19
+ [salt_proxy, hostgroup.try(:salt_proxy)].compact.each do |proxy|
20
+ ids << proxy.id
21
+ end
22
+ ids
23
+ end
24
+
25
+ def inherited_attributes
26
+ super + %w(salt_proxy_id salt_environment_id)
27
+ end
28
+ end
29
+
6
30
  included do
7
31
  has_many :host_salt_modules, :foreign_key => :host_id, :class_name => '::ForemanSalt::HostSaltModule'
8
32
  has_many :salt_modules, :through => :host_salt_modules, :class_name => '::ForemanSalt::SaltModule'
@@ -10,10 +34,7 @@ module ForemanSalt
10
34
  belongs_to :salt_proxy, :class_name => 'SmartProxy'
11
35
  belongs_to :salt_environment, :class_name => 'ForemanSalt::SaltEnvironment'
12
36
 
13
- alias_method_chain :params, :salt_proxy
14
- alias_method_chain :smart_proxy_ids, :salt_proxy
15
- alias_method_chain :inherited_attributes, :salt
16
- alias_method_chain :configuration?, :salt
37
+ prepend Overrides
17
38
 
18
39
  scoped_search :relation => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
19
40
  scoped_search :relation => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
@@ -26,16 +47,6 @@ module ForemanSalt
26
47
  before_destroy :delete_salt_key, :if => ->(host) { host.salt_proxy }
27
48
  end
28
49
 
29
- def configuration_with_salt?
30
- configuration_without_salt? || !!salt_proxy
31
- end
32
-
33
- def params_with_salt_proxy
34
- params = params_without_salt_proxy
35
- params['salt_master'] = salt_master unless salt_master.blank?
36
- params
37
- end
38
-
39
50
  def salt_modules_for_enc
40
51
  return [] unless salt_environment
41
52
  modules = salt_modules + (hostgroup ? hostgroup.all_salt_modules : [])
@@ -58,18 +69,6 @@ module ForemanSalt
58
69
  false
59
70
  end
60
71
 
61
- def inherited_attributes_with_salt
62
- inherited_attributes_without_salt + %w(salt_proxy_id salt_environment_id)
63
- end
64
-
65
- def smart_proxy_ids_with_salt_proxy
66
- ids = smart_proxy_ids_without_salt_proxy
67
- [salt_proxy, hostgroup.try(:salt_proxy)].compact.each do |proxy|
68
- ids << proxy.id
69
- end
70
- ids
71
- end
72
-
73
72
  def salt_modules_in_host_environment
74
73
  return unless self.salt_modules.any?
75
74
 
@@ -1,4 +1,4 @@
1
- class AddSaltProxyToHostAndHostGroup < ActiveRecord::Migration
1
+ class AddSaltProxyToHostAndHostGroup < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  add_column :hosts, :salt_proxy_id, :integer
4
4
  add_column :hostgroups, :salt_proxy_id, :integer
@@ -1,8 +1,8 @@
1
- class CreateSaltModules < ActiveRecord::Migration
1
+ class CreateSaltModules < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table :salt_modules do |t|
4
4
  t.string :name, :default => '', :null => false
5
- t.timestamps
5
+ t.timestamps :null => true
6
6
  end
7
7
 
8
8
  create_table 'hosts_salt_modules', :id => false do |t|
@@ -1,4 +1,4 @@
1
- class AddSaltModulesToHostgroups < ActiveRecord::Migration
1
+ class AddSaltModulesToHostgroups < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table 'hostgroups_salt_modules', :id => false do |t|
4
4
  t.column :hostgroup_id, :integer
@@ -1,8 +1,8 @@
1
- class CreateSaltEnvironments < ActiveRecord::Migration
1
+ class CreateSaltEnvironments < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table :salt_environments do |t|
4
4
  t.string :name, :default => '', :null => false
5
- t.timestamps
5
+ t.timestamps :null => true
6
6
  end
7
7
 
8
8
  add_column :hosts, :salt_environment_id, :integer
@@ -1,4 +1,4 @@
1
- class FixIncorrectReportMetrics < ActiveRecord::Migration
1
+ class FixIncorrectReportMetrics < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  Report.all.each do |report|
4
4
  next unless report.metrics && report.metrics['time']
@@ -1,4 +1,4 @@
1
- class AddEnvironmentsToModules < ActiveRecord::Migration
1
+ class AddEnvironmentsToModules < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  create_table 'salt_module_environments' do |t|
4
4
  t.references :salt_module
@@ -1,4 +1,4 @@
1
- class RenameJoinTables < ActiveRecord::Migration
1
+ class RenameJoinTables < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  rename_table :hosts_salt_modules, :host_salt_modules
4
4
  rename_table :hostgroups_salt_modules, :hostgroup_salt_modules
@@ -1,4 +1,4 @@
1
- class AddPrimaryKeys < ActiveRecord::Migration
1
+ class AddPrimaryKeys < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :host_salt_modules, :id, :primary_key
4
4
  add_column :hostgroup_salt_modules, :id, :primary_key
@@ -1,4 +1,4 @@
1
- class AddIndexToJoinTables < ActiveRecord::Migration
1
+ class AddIndexToJoinTables < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_index :host_salt_modules, :host_id
4
4
  add_index :host_salt_modules, :salt_module_id
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '9.0.1'
2
+ VERSION = '10.0.0'
3
3
  end
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :salt_module, :class => 'ForemanSalt::SaltModule' do
3
3
  sequence(:name) { |n| "module#{n}" }
4
4
  end
@@ -8,21 +8,21 @@ FactoryGirl.define do
8
8
  end
9
9
  end
10
10
 
11
- FactoryGirl.modify do
11
+ FactoryBot.modify do
12
12
  factory :host do
13
13
  trait :with_salt_proxy do
14
- salt_proxy { FactoryGirl.build :smart_proxy, :with_salt_feature }
14
+ salt_proxy { FactoryBot.build :smart_proxy, :with_salt_feature }
15
15
  end
16
16
  end
17
17
 
18
18
  factory :hostgroup do
19
19
  trait :with_salt_proxy do
20
- salt_proxy { FactoryGirl.build :smart_proxy, :with_salt_feature }
20
+ salt_proxy { FactoryBot.build :smart_proxy, :with_salt_feature }
21
21
  end
22
22
 
23
23
  trait :with_salt_modules do
24
- salt_environment { FactoryGirl.build :salt_environment }
25
- salt_modules { FactoryGirl.create_list :salt_module, 10, :salt_environments => [self.salt_environment] }
24
+ salt_environment { FactoryBot.build :salt_environment }
25
+ salt_modules { FactoryBot.create_list :salt_module, 10, :salt_environments => [self.salt_environment] }
26
26
  end
27
27
  end
28
28
 
@@ -2,24 +2,24 @@ require 'test_plugin_helper'
2
2
 
3
3
  class ::ForemanSalt::Api::V2::SaltAutosignControllerTest < ActionController::TestCase
4
4
  setup do
5
- @proxy = FactoryGirl.create(:smart_proxy, :with_salt_feature)
5
+ @proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
6
6
  ProxyAPI::Salt.any_instance.stubs(:autosign_list).returns((%w(foo bar baz)))
7
7
  end
8
8
 
9
9
  test 'should get index' do
10
- get :index, :smart_proxy_id => @proxy.id
10
+ get :index, params: { :smart_proxy_id => @proxy.id }
11
11
  assert_response :success
12
12
  end
13
13
 
14
14
  test 'should create autosign' do
15
15
  ProxyAPI::Salt.any_instance.expects(:autosign_create).once.returns(true)
16
- post :create, :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com'
16
+ post :create, params: { :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com' }
17
17
  assert_response :success
18
18
  end
19
19
 
20
20
  test 'should delete autosign' do
21
21
  ProxyAPI::Salt.any_instance.expects(:autosign_remove).once.returns(true)
22
- delete :destroy, :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com'
22
+ delete :destroy, params: { :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com' }
23
23
  assert_response :success
24
24
  end
25
25
  end
@@ -2,20 +2,20 @@ require 'test_plugin_helper'
2
2
 
3
3
  class ::ForemanSalt::Api::V2::SaltEnvironmentsControllerTest < ActionController::TestCase
4
4
  test 'should get index' do
5
- get :index, {}
5
+ get :index
6
6
  assert_response :success
7
7
  assert_template 'api/v2/salt_environments/index'
8
8
  end
9
9
 
10
10
  test 'should show environment' do
11
11
  environment = ForemanSalt::SaltEnvironment.create(:name => 'foo')
12
- get :show, :id => environment.id
12
+ get :show, params: { :id => environment.id }
13
13
  assert_response :success
14
14
  assert_template 'api/v2/salt_environments/show'
15
15
  end
16
16
 
17
17
  test 'should create environment' do
18
- post :create, :environment => { :name => 'unicorn' }
18
+ post :create, params: { :environment => { :name => 'unicorn' } }
19
19
  assert_response :success
20
20
  assert ForemanSalt::SaltEnvironment.find_by_name('unicorn')
21
21
  assert_template 'api/v2/salt_environments/create'
@@ -24,7 +24,7 @@ class ::ForemanSalt::Api::V2::SaltEnvironmentsControllerTest < ActionController:
24
24
  test 'should delete environment' do
25
25
  environment = ForemanSalt::SaltEnvironment.create(:name => 'foo.bar.baz')
26
26
  assert_difference('ForemanSalt::SaltEnvironment.count', -1) do
27
- delete :destroy, :id => environment.id
27
+ delete :destroy, params: { :id => environment.id }
28
28
  end
29
29
  assert_response :success
30
30
  end
@@ -2,26 +2,26 @@ require 'test_plugin_helper'
2
2
 
3
3
  class ::ForemanSalt::Api::V2::SaltKeysControllerTest < ActionController::TestCase
4
4
  setup do
5
- @proxy = FactoryGirl.create(:smart_proxy, :with_salt_feature)
5
+ @proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
6
6
 
7
7
  ProxyAPI::Salt.any_instance.stubs(:key_list).returns('saltstack.example.com' => { 'state' => 'unaccepted',
8
8
  'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' })
9
9
  end
10
10
 
11
11
  test 'should get index' do
12
- get :index, :smart_proxy_id => @proxy.id
12
+ get :index, params: { :smart_proxy_id => @proxy.id }
13
13
  assert_response :success
14
14
  end
15
15
 
16
16
  test 'should update keys' do
17
17
  ProxyAPI::Salt.any_instance.expects(:key_accept).once.returns(true)
18
- put :update, :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', :key => { :state => 'accepted' } }
19
19
  assert_response :success
20
20
  end
21
21
 
22
22
  test 'should delete keys' do
23
23
  ProxyAPI::Salt.any_instance.expects(:key_delete).once.returns(true)
24
- delete :destroy, :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com'
24
+ delete :destroy, params: { :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com' }
25
25
  assert_response :success
26
26
  end
27
27
  end
@@ -2,20 +2,20 @@ require 'test_plugin_helper'
2
2
 
3
3
  class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestCase
4
4
  test 'should get index' do
5
- get :index, {}
5
+ get :index
6
6
  assert_response :success
7
7
  assert_template 'api/v2/salt_states/index'
8
8
  end
9
9
 
10
10
  test 'should show state' do
11
11
  state = ForemanSalt::SaltModule.create(:name => 'foo.bar.baz')
12
- get :show, :id => state.id
12
+ get :show, params: { :id => state.id }
13
13
  assert_response :success
14
14
  assert_template 'api/v2/salt_states/show'
15
15
  end
16
16
 
17
17
  test 'should create state' do
18
- post :create, :state => { :name => 'unicorn' }
18
+ post :create, params: { :state => { :name => 'unicorn' } }
19
19
  assert_response :success
20
20
  assert ForemanSalt::SaltModule.find_by_name('unicorn')
21
21
  assert_template 'api/v2/salt_states/create'
@@ -24,14 +24,14 @@ class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestC
24
24
  test 'should delete state' do
25
25
  state = ForemanSalt::SaltModule.create(:name => 'foo.bar.baz')
26
26
  assert_difference('ForemanSalt::SaltModule.count', -1) do
27
- delete :destroy, :id => state.id
27
+ delete :destroy, params: { :id => state.id }
28
28
  end
29
29
  assert_response :success
30
30
  end
31
31
 
32
32
  context 'importing' do
33
33
  setup do
34
- @proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
34
+ @proxy = FactoryBot.create :smart_proxy, :with_salt_feature
35
35
  @states = { 'env1' => %w(state1 state2 state3),
36
36
  'env2' => %w(state1 state2) }
37
37
 
@@ -39,7 +39,7 @@ class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestC
39
39
  end
40
40
 
41
41
  test 'should import' do
42
- post :import, :smart_proxy_id => @proxy.id
42
+ post :import, params: { :smart_proxy_id => @proxy.id }
43
43
 
44
44
  assert_response :success
45
45
 
@@ -50,32 +50,32 @@ class ::ForemanSalt::Api::V2::SaltStatesControllerTest < ActionController::TestC
50
50
  end
51
51
 
52
52
  test 'should import only from a given environment' do
53
- post :import, :smart_proxy_id => @proxy.id, :salt_environments => ['env2']
53
+ post :import, params: { :smart_proxy_id => @proxy.id, :salt_environments => ['env2'] }
54
54
  assert_response :success
55
55
  refute ::ForemanSalt::SaltEnvironment.where(:name => 'env1').first
56
56
  assert ::ForemanSalt::SaltEnvironment.where(:name => 'env2').first
57
57
  end
58
58
 
59
59
  test 'should limit actions to add' do
60
- env = FactoryGirl.create :salt_environment
61
- state = FactoryGirl.create :salt_module, :salt_environments => [env]
60
+ env = FactoryBot.create :salt_environment
61
+ state = FactoryBot.create :salt_module, :salt_environments => [env]
62
62
 
63
- post :import, :smart_proxy_id => @proxy.id, :actions => ['add']
63
+ post :import, params: { :smart_proxy_id => @proxy.id, :actions => ['add'] }
64
64
  assert_response :success
65
65
  assert ::ForemanSalt::SaltModule.where(:id => state).first
66
66
  assert ::ForemanSalt::SaltModule.where(:name => 'state1').first
67
67
  end
68
68
 
69
69
  test 'should limit actions to remove' do
70
- state = FactoryGirl.create :salt_module
71
- post :import, :smart_proxy_id => @proxy.id, :actions => ['remove']
70
+ state = FactoryBot.create :salt_module
71
+ post :import, params: { :smart_proxy_id => @proxy.id, :actions => ['remove'] }
72
72
  assert_response :success
73
73
  refute ::ForemanSalt::SaltModule.where(:id => state).first
74
74
  refute ::ForemanSalt::SaltModule.where(:name => 'state1').first
75
75
  end
76
76
 
77
77
  test 'dryrun should do nothing' do
78
- post :import, :smart_proxy_id => @proxy.id, :dryrun => true
78
+ post :import, params: { :smart_proxy_id => @proxy.id, :dryrun => true }
79
79
  assert_response :success
80
80
  refute ::ForemanSalt::SaltModule.all.any?
81
81
  refute ::ForemanSalt::SaltEnvironment.all.any?
@@ -7,11 +7,11 @@ module ForemanSalt
7
7
  Setting[:restrict_registered_smart_proxies] = true
8
8
  Setting[:require_ssl_smart_proxies] = false
9
9
 
10
- proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
10
+ proxy = FactoryBot.create :smart_proxy, :with_salt_feature
11
11
  Resolv.any_instance.stubs(:getnames).returns([proxy.to_s])
12
12
 
13
- host = FactoryGirl.create :host
14
- get :node, :id => host, :format => 'yml'
13
+ host = FactoryBot.create :host
14
+ get :node, params: { :id => host, :format => 'yml' }
15
15
  assert_response :success
16
16
  end
17
17
  end
@@ -4,7 +4,7 @@ require 'integration_test_helper'
4
4
  module ForemanSalt
5
5
  class SaltKeysTest < ActionDispatch::IntegrationTest
6
6
  setup do
7
- @proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
7
+ @proxy = FactoryBot.create :smart_proxy, :with_salt_feature
8
8
 
9
9
  ::ProxyAPI::Salt.any_instance.stubs(:autosign_list).returns(
10
10
  ['foo.example.com']
@@ -4,7 +4,7 @@ require 'integration_test_helper'
4
4
  module ForemanSalt
5
5
  class SaltEnvironmentTest < ActionDispatch::IntegrationTest
6
6
  test 'index page' do
7
- FactoryGirl.create_list :salt_environment, 5
7
+ FactoryBot.create_list :salt_environment, 5
8
8
  assert_index_page(salt_environments_path, 'Salt Environment', 'New Salt Environment')
9
9
  end
10
10
 
@@ -16,7 +16,7 @@ module ForemanSalt
16
16
  end
17
17
 
18
18
  test 'edit page' do
19
- salt_environment = FactoryGirl.create :salt_environment
19
+ salt_environment = FactoryBot.create :salt_environment
20
20
  visit salt_environments_path
21
21
  click_link salt_environment.name
22
22
  fill_in 'foreman_salt_salt_environment_name', :with => 'some_other_name'
@@ -4,7 +4,7 @@ require 'integration_test_helper'
4
4
  module ForemanSalt
5
5
  class SaltKeysTest < ActionDispatch::IntegrationTest
6
6
  setup do
7
- @proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
7
+ @proxy = FactoryBot.create :smart_proxy, :with_salt_feature
8
8
 
9
9
  ::ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
10
10
  'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
@@ -12,12 +12,12 @@ module ForemanSalt
12
12
  ::ProxyAPI::Salt.any_instance.stubs(:states_list).returns(state_list)
13
13
 
14
14
  # FIXME #12143
15
- FactoryGirl.create(:permission, :name => 'view_salt_environments',
15
+ FactoryBot.create(:permission, :name => 'view_salt_environments',
16
16
  :resource_type => 'ForemanSalt::SaltEnvironment')
17
17
  end
18
18
 
19
19
  test 'index page' do
20
- FactoryGirl.create_list :salt_module, 5
20
+ FactoryBot.create_list :salt_module, 5
21
21
  assert_index_page(salt_modules_path, 'Salt State', 'New Salt State')
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ module ForemanSalt
29
29
  end
30
30
 
31
31
  test 'edit page' do
32
- salt_module = FactoryGirl.create :salt_module
32
+ salt_module = FactoryBot.create :salt_module
33
33
  visit salt_modules_path
34
34
  click_link salt_module.name
35
35
  fill_in :foreman_salt_salt_module_name, :with => 'some_other_name'
@@ -38,8 +38,8 @@ module ForemanSalt
38
38
  end
39
39
 
40
40
  test 'import states' do
41
- proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
42
- state = FactoryGirl.create :salt_module, :salt_environments => [FactoryGirl.create(:salt_environment)]
41
+ proxy = FactoryBot.create :smart_proxy, :with_salt_feature
42
+ state = FactoryBot.create :salt_module, :salt_environments => [FactoryBot.create(:salt_environment)]
43
43
 
44
44
  visit salt_modules_path
45
45
  click_link "Import from #{proxy.name}"
@@ -9,6 +9,6 @@ def assert_row_button(index_path, link_text, button_text, dropdown = false)
9
9
  end
10
10
  end
11
11
 
12
- # Add plugin to FactoryGirl's paths
13
- FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
14
- FactoryGirl.reload
12
+ # Add plugin to FactoryBot's paths
13
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
14
+ FactoryBot.reload
@@ -2,6 +2,9 @@ require 'test_plugin_helper'
2
2
 
3
3
  module ForemanSalt
4
4
  class GrainsImporterTest < ActiveSupport::TestCase
5
+ include FactImporterIsolation
6
+ allow_transactions_for_any_importer
7
+
5
8
  setup do
6
9
  User.current = User.find_by_login 'admin'
7
10
  Setting[:create_new_host_when_facts_are_uploaded] = true
@@ -7,36 +7,36 @@ module ForemanSalt
7
7
  end
8
8
 
9
9
  test 'host has a salt smart proxy' do
10
- host = FactoryGirl.create :host, :with_salt_proxy
10
+ host = FactoryBot.create :host, :with_salt_proxy
11
11
  assert host.salt_proxy.has_feature? 'Salt'
12
12
  end
13
13
 
14
14
  test 'smart_proxy_ids returns salt smart proxy' do
15
- host = FactoryGirl.create :host, :with_salt_proxy
15
+ host = FactoryBot.create :host, :with_salt_proxy
16
16
  assert host.smart_proxy_ids.include? host.salt_proxy_id
17
17
  end
18
18
 
19
19
  test 'host params includes salt_master' do
20
- host = FactoryGirl.create :host, :with_salt_proxy
20
+ host = FactoryBot.create :host, :with_salt_proxy
21
21
  assert host.params.key? 'salt_master'
22
22
  assert_equal host.params['salt_master'], host.salt_master
23
23
  end
24
24
 
25
25
  test 'host inherits salt proxy from host group' do
26
- hostgroup = FactoryGirl.create :hostgroup, :with_salt_proxy
27
- host = FactoryGirl.create :host, :hostgroup => hostgroup
26
+ hostgroup = FactoryBot.create :hostgroup, :with_salt_proxy
27
+ host = FactoryBot.create :host, :hostgroup => hostgroup
28
28
  host.set_hostgroup_defaults
29
29
  assert_equal host.salt_proxy, hostgroup.salt_proxy
30
30
  end
31
31
 
32
32
  test 'host does not accept salt modules outside its environment' do
33
- hosts_environment = FactoryGirl.create :salt_environment
34
- other_environment = FactoryGirl.create :salt_environment
33
+ hosts_environment = FactoryBot.create :salt_environment
34
+ other_environment = FactoryBot.create :salt_environment
35
35
 
36
- state = FactoryGirl.create :salt_module
36
+ state = FactoryBot.create :salt_module
37
37
  other_environment.salt_modules << state
38
38
 
39
- host = FactoryGirl.create :host, :with_salt_proxy, :salt_environment => hosts_environment
39
+ host = FactoryBot.create :host, :with_salt_proxy, :salt_environment => hosts_environment
40
40
  host.salt_modules = [state]
41
41
 
42
42
  refute host.save
@@ -44,8 +44,8 @@ module ForemanSalt
44
44
  end
45
45
 
46
46
  test '#configuration? considers salt' do
47
- host = FactoryGirl.build(:host)
48
- proxy = FactoryGirl.build(:smart_proxy)
47
+ host = FactoryBot.build(:host)
48
+ proxy = FactoryBot.build(:smart_proxy)
49
49
 
50
50
  refute host.configuration?
51
51
  host.salt_proxy = proxy
@@ -54,7 +54,7 @@ module ForemanSalt
54
54
 
55
55
  context 'key handling' do
56
56
  before do
57
- @host = FactoryGirl.create(:host, :with_salt_proxy, :managed, :build => true)
57
+ @host = FactoryBot.create(:host, :with_salt_proxy, :managed, :build => true)
58
58
  @key_stub = stub("key")
59
59
  ForemanSalt::SmartProxies::SaltKeys.expects(:find).at_least_once.with(@host.salt_proxy, @host.fqdn).returns(@key_stub)
60
60
  end
@@ -7,49 +7,49 @@ module ForemanSalt
7
7
  end
8
8
 
9
9
  test 'host group has a salt smart proxy' do
10
- hostgroup = FactoryGirl.create :hostgroup, :with_salt_proxy
10
+ hostgroup = FactoryBot.create :hostgroup, :with_salt_proxy
11
11
  assert hostgroup.salt_proxy.features.map(&:name).include? 'Salt'
12
12
  end
13
13
 
14
14
  test 'nested host group inherits salt modules from parent' do
15
- parent = FactoryGirl.create :hostgroup, :with_salt_modules
16
- child = FactoryGirl.create :hostgroup, :parent => parent
15
+ parent = FactoryBot.create :hostgroup, :with_salt_modules
16
+ child = FactoryBot.create :hostgroup, :parent => parent
17
17
  assert_equal [], parent.all_salt_modules - child.all_salt_modules
18
18
  end
19
19
 
20
20
  test 'child host group inherits salt proxy from child parent' do
21
- parent = FactoryGirl.create :hostgroup
22
- child_one = FactoryGirl.create :hostgroup, :with_salt_proxy, :parent => parent
23
- child_two = FactoryGirl.create :hostgroup, :parent => child_one
21
+ parent = FactoryBot.create :hostgroup
22
+ child_one = FactoryBot.create :hostgroup, :with_salt_proxy, :parent => parent
23
+ child_two = FactoryBot.create :hostgroup, :parent => child_one
24
24
  assert_equal child_two.salt_proxy, child_one.salt_proxy
25
25
  end
26
26
 
27
27
  test 'child and parent salt modules are combined' do
28
- environment = FactoryGirl.create :salt_environment
29
- parent = FactoryGirl.create :hostgroup, :with_salt_modules, :salt_environment => environment
30
- child = FactoryGirl.create :hostgroup, :with_salt_modules, :salt_environment => environment, :parent => parent
28
+ environment = FactoryBot.create :salt_environment
29
+ parent = FactoryBot.create :hostgroup, :with_salt_modules, :salt_environment => environment
30
+ child = FactoryBot.create :hostgroup, :with_salt_modules, :salt_environment => environment, :parent => parent
31
31
 
32
32
  total = parent.salt_modules.count + child.salt_modules.count
33
33
  assert_equal total, child.all_salt_modules.count
34
34
  end
35
35
 
36
36
  test 'child doesnt get modules from outside its environment' do
37
- parent = FactoryGirl.create :hostgroup, :with_salt_modules
38
- child = FactoryGirl.create :hostgroup, :with_salt_modules, :parent => parent
37
+ parent = FactoryBot.create :hostgroup, :with_salt_modules
38
+ child = FactoryBot.create :hostgroup, :with_salt_modules, :parent => parent
39
39
  assert_equal child.salt_modules.count, child.all_salt_modules.count
40
40
  end
41
41
 
42
42
  test 'inheritance when only parent has modules' do
43
- parent = FactoryGirl.create :hostgroup, :with_salt_modules
44
- child_one = FactoryGirl.create :hostgroup, :parent => parent
45
- child_two = FactoryGirl.create :hostgroup, :parent => child_one
43
+ parent = FactoryBot.create :hostgroup, :with_salt_modules
44
+ child_one = FactoryBot.create :hostgroup, :parent => parent
45
+ child_two = FactoryBot.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
50
- parent = FactoryGirl.create :hostgroup
51
- child_one = FactoryGirl.create :hostgroup, :parent => parent
52
- child_two = FactoryGirl.create :hostgroup, :with_salt_modules, :parent => child_one
50
+ parent = FactoryBot.create :hostgroup
51
+ child_one = FactoryBot.create :hostgroup, :parent => parent
52
+ child_two = FactoryBot.create :hostgroup, :with_salt_modules, :parent => child_one
53
53
  assert child_two.all_salt_modules.any?
54
54
  end
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.1
4
+ version: 10.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Benjamin
@@ -202,8 +202,8 @@ test_files:
202
202
  - test/unit/highstate.json
203
203
  - test/unit/salt_keys_test.rb
204
204
  - test/unit/salt_modules_test.rb
205
- - test/unit/report_importer_test.rb
206
205
  - test/unit/grains_importer_test.rb
207
206
  - test/unit/host_extensions_test.rb
208
207
  - test/unit/hostgroup_extensions_test.rb
208
+ - test/unit/report_importer_test.rb
209
209
  - test/test_plugin_helper.rb