foreman_salt 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDYxMGMzYTMxM2FjODk0NGY5YzU2YWFlYjZlZGIxOGM4OGMwYzQ1MQ==
5
- data.tar.gz: !binary |-
6
- ZWYxNGRiOWY2MmYxMjExNTJiYWM4N2ZlOTE3ZjBiZGJiNWIzOGExZg==
2
+ SHA1:
3
+ metadata.gz: a9a26aba67e387ba355bf4b358969f155e0e7550
4
+ data.tar.gz: c77ad3cab0e6f604f8e60964894d3345b01384ed
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YmU3NjEwNzA3NWMwOWQ0MDBhYTljOWMxOWZjNzliMTJlODc4NzRlOWVlN2Q5
10
- ZWY4MGNiNjlmNWNlNGMxNWVmYjU0YmQ1YjkyODhjYTY2YzM2ODIxYjNkYjc2
11
- MGQwNzI0NTFjNGUzZDQxOWU2YWQzZWQ1ZDgwZjJkNmYxN2MyMWQ=
12
- data.tar.gz: !binary |-
13
- NDA2MDM3Y2ZiMzE5NzUwOWMwY2QyYmE4YzFmY2YzNDIyYmE2NzM4YjM0ODc3
14
- NGE0MDdjMGJjYzA2MWIzOTg3NzRhNGUyMTdlZWVmN2M1ODAyYTAyZDY5YjM3
15
- NGI2NGI2MjZmYzA5NGU2ZTQ4NTA4YzgxYmJlMjI5Y2I2ODBlMTM=
6
+ metadata.gz: 9db5120fde1dff0fffad5b1cf5dbec81cf780669887447f379ba6109d2fd886f45b120a79d219b7b2f327cdd9d35d424e4cb09e1ba427b4441e8ed5124809e03
7
+ data.tar.gz: b36d148373832511ea50bbf3379f0f096f9a2fdcad94b62422cf7cb06526ddecafba58aeb83e1faa4c7c9c362b7a089b0514b5ec9454656401d9bc4a399ee41c
data/README.md CHANGED
@@ -4,7 +4,7 @@ This plug-in adds support for Salt to Foreman.
4
4
 
5
5
  ## Documentation
6
6
 
7
- Available in the Wiki https://github.com/theforeman/foreman_salt/wiki
7
+ See the [Foreman Salt manuals](http://theforeman.org/plugins/foreman_salt/) on the Foreman web site.
8
8
 
9
9
  ## Contributing
10
10
 
@@ -5,6 +5,7 @@ module ForemanSalt
5
5
  before_filter :find_resource, :except => [:index, :create]
6
6
 
7
7
  api :GET, '/salt_environments', N_('List all Salt environments')
8
+ param_group :search_and_pagination, ::Api::V2::BaseController
8
9
  def index
9
10
  @salt_environments = resource_scope_for_index
10
11
  end
@@ -5,6 +5,7 @@ module ForemanSalt
5
5
  before_filter :find_resource, :except => [:index]
6
6
 
7
7
  api :GET, '/salt_minions', N_('List all Salt Minions')
8
+ param_group :search_and_pagination, ::Api::V2::BaseController
8
9
  def index
9
10
  @salt_minions = resource_scope_for_index
10
11
  end
@@ -10,6 +10,7 @@ module ForemanSalt
10
10
 
11
11
  api :GET, '/salt_states', N_('List all Salt states')
12
12
  param :salt_environment_id, :identifier_dottable, :required => false, :desc => N_('Limit to a specific environment')
13
+ param_group :search_and_pagination, ::Api::V2::BaseController
13
14
  def index
14
15
  if @salt_environment
15
16
  @salt_states = resource_scope_for_index.joins(:salt_environments).where('salt_module_environments.salt_environment_id' => @salt_environment)
@@ -46,18 +47,19 @@ module ForemanSalt
46
47
 
47
48
  api :POST, '/salt_states/import/:smart_proxy_id', N_('Import states from a salt master')
48
49
  param :smart_proxy_id, :identifier_dottable, :required => true, :desc => N_('Salt Smart Proxy ID')
49
- param :salt_environment_ids, Array, :required => false, :desc => N_('Limit to a specific environments')
50
+ param :salt_environments, Array, :required => false, :desc => N_('Limit to a specific environments')
50
51
  param :actions, Array, :required => false, :desc => N_('Limit to specific actions: i.e. add, remove')
51
52
  param :dryrun, :bool, :required => false, :desc => N_('Dryrun only')
52
53
  def import
53
- states = fetch_states_from_proxy(@proxy, params[:salt_environment_ids])
54
+ states = fetch_states_from_proxy(@proxy, params[:salt_environments])
55
+
54
56
  unless params[:dryrun]
55
57
  states[:changes].each do |environment, state|
56
- if state[:add].any? && (params[:actions].blank? || params[:actions].include?('add'))
58
+ if state[:add].present? && (params[:actions].blank? || params[:actions].include?('add'))
57
59
  add_to_environment(state[:add], environment)
58
60
  end
59
61
 
60
- if state[:remove].any? && (params[:actions].blank? || params[:actions].include?('remove'))
62
+ if state[:remove].present? && (params[:actions].blank? || params[:actions].include?('remove'))
61
63
  remove_from_environment(state[:remove], environment)
62
64
  end
63
65
  end
@@ -74,7 +74,6 @@ module ForemanSalt
74
74
  else
75
75
  params[:changed].each do |environment, states|
76
76
  next unless states[:add] || states[:remove]
77
- environment = SaltEnvironment.find_or_create_by_name(environment)
78
77
 
79
78
  add_to_environment(JSON.load(states[:add]), environment) if states[:add]
80
79
  remove_from_environment(JSON.load(states[:remove]), environment) if states[:remove]
@@ -46,13 +46,17 @@ module ForemanSalt
46
46
  end
47
47
 
48
48
  def add_to_environment(states, environment)
49
+ environment = SaltEnvironment.find_or_create_by_name(environment)
50
+
49
51
  states.each do |state_name|
50
52
  state = SaltModule.find_or_create_by_name(state_name)
51
- state.salt_environments << SaltEnvironment.find(environment)
53
+ state.salt_environments << environment unless state.salt_environments.include? environment
52
54
  end
53
55
  end
54
56
 
55
57
  def remove_from_environment(states, environment)
58
+ return unless (environment = SaltEnvironment.find(environment))
59
+
56
60
  states.each do |state_name|
57
61
  state = SaltModule.find(state_name)
58
62
  state.salt_environments.delete(environment) if state
@@ -3,8 +3,9 @@ module ForemanSalt
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- alias_method_chain :host_title_actions, :salt_run
6
+ alias_method_chain :host_title_actions, :salt
7
7
  alias_method_chain :show_appropriate_host_buttons, :salt
8
+ alias_method_chain :overview_fields, :salt
8
9
  end
9
10
 
10
11
  def show_appropriate_host_buttons_with_salt(host)
@@ -13,7 +14,7 @@ module ForemanSalt
13
14
  :title => _('Salt external nodes YAML dump'), :class => 'btn btn-default') unless host.salt_master.blank?)]).flatten.compact
14
15
  end
15
16
 
16
- def host_title_actions_with_salt_run(host)
17
+ def host_title_actions_with_salt(host)
17
18
  title_actions(
18
19
  button_group(
19
20
  if host.try(:salt_proxy)
@@ -22,7 +23,16 @@ module ForemanSalt
22
23
  end
23
24
  )
24
25
  )
25
- host_title_actions_without_salt_run(host)
26
+ host_title_actions_without_salt(host)
27
+ end
28
+
29
+ def overview_fields_with_salt(host)
30
+ fields = overview_fields_without_salt(host)
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)])
34
+
35
+ fields
26
36
  end
27
37
  end
28
38
  end
@@ -16,6 +16,7 @@ module ForemanSalt
16
16
 
17
17
  scoped_search :in => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
18
18
  scoped_search :in => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
19
+ scoped_search :in => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
19
20
 
20
21
  validate :salt_modules_in_host_environment
21
22
  end
@@ -12,6 +12,7 @@ module ForemanSalt
12
12
 
13
13
  scoped_search :in => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
14
14
  scoped_search :in => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
15
+ scoped_search :in => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
15
16
  end
16
17
 
17
18
  def all_salt_modules
@@ -1,3 +1,7 @@
1
1
  object @salt_environment
2
2
 
3
- extends "foreman_salt/api/v2/salt_environments/base"
3
+ extends 'foreman_salt/api/v2/salt_environments/base'
4
+
5
+ child :salt_modules => :salt_states do
6
+ extends 'foreman_salt/api/v2/salt_states/base'
7
+ end
@@ -1,3 +1,3 @@
1
1
  object @salt_state
2
2
 
3
- attributes :id, :name
3
+ attributes :id, :name, :salt_environment
@@ -1,3 +1,12 @@
1
1
  object @salt_state
2
2
 
3
- extends "foreman_salt/api/v2/salt_states/base"
3
+ extends 'foreman_salt/api/v2/salt_states/base'
4
+
5
+ child :hostgroups do
6
+ extends 'api/v2/hostgroups/base'
7
+ end
8
+
9
+ child :salt_environments do
10
+ extends 'foreman_salt/api/v2/salt_environments/base'
11
+ end
12
+
@@ -37,7 +37,7 @@ module ForemanSalt
37
37
 
38
38
  initializer 'foreman_salt.register_plugin', :after => :finisher_hook do |_app|
39
39
  Foreman::Plugin.register :foreman_salt do
40
- requires_foreman '>= 1.8'
40
+ requires_foreman '>= 1.9'
41
41
 
42
42
  apipie_documented_controllers ["#{ForemanSalt::Engine.root}/app/controllers/foreman_salt/api/v2/*.rb"]
43
43
 
@@ -167,7 +167,7 @@ module ForemanSalt
167
167
  config.to_prepare do
168
168
  begin
169
169
  ::FactImporter.register_fact_importer(:foreman_salt, ForemanSalt::FactImporter)
170
- ::FactParser.register_fact_importer(:foreman_salt, ForemanSalt::FactParser)
170
+ ::FactParser.register_fact_parser(:foreman_salt, ForemanSalt::FactParser)
171
171
 
172
172
  # Helper Extensions
173
173
  ::HostsHelper.send :include, ForemanSalt::HostsHelperExtensions
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -29,5 +29,58 @@ module ForemanSalt
29
29
  end
30
30
  assert_response :success
31
31
  end
32
+
33
+ context 'importing' do
34
+ setup do
35
+ @proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
36
+ @states = {'env1' => %w(state1 state2 state3),
37
+ 'env2' => %w(state1 state2)}
38
+
39
+ ::ProxyAPI::Salt.any_instance.stubs(:states_list).returns(@states)
40
+ end
41
+
42
+ test 'should import' do
43
+ post :import, :smart_proxy_id => @proxy.id
44
+
45
+ assert_response :success
46
+
47
+ @states.each do |env, states|
48
+ environment = ::ForemanSalt::SaltEnvironment.find(env)
49
+ assert_blank environment.salt_modules.map(&:name) - states
50
+ end
51
+ end
52
+
53
+ test 'should import only from a given environment' do
54
+ post :import, :smart_proxy_id => @proxy.id, :salt_environments => ['env2']
55
+ assert_response :success
56
+ refute ::ForemanSalt::SaltEnvironment.where(:name => 'env1').first
57
+ assert ::ForemanSalt::SaltEnvironment.where(:name => 'env2').first
58
+ end
59
+
60
+ test 'should limit actions to add' do
61
+ env = FactoryGirl.create :salt_environment
62
+ state = FactoryGirl.create :salt_module, :salt_environments => [env]
63
+
64
+ post :import, :smart_proxy_id => @proxy.id, :actions => ['add']
65
+ assert_response :success
66
+ assert ::ForemanSalt::SaltModule.where(:id => state).first
67
+ assert ::ForemanSalt::SaltModule.where(:name => 'state1').first
68
+ end
69
+
70
+ test 'should limit actions to remove' do
71
+ state = FactoryGirl.create :salt_module
72
+ post :import, :smart_proxy_id => @proxy.id, :actions => ['remove']
73
+ assert_response :success
74
+ refute ::ForemanSalt::SaltModule.where(:id => state).first
75
+ refute ::ForemanSalt::SaltModule.where(:name => 'state1').first
76
+ end
77
+
78
+ test 'dryrun should do nothing' do
79
+ post :import, :smart_proxy_id => @proxy.id, :dryrun => true
80
+ assert_response :success
81
+ refute ::ForemanSalt::SaltModule.all.any?
82
+ refute ::ForemanSalt::SaltEnvironment.all.any?
83
+ end
84
+ end
32
85
  end
33
86
  end
@@ -2,8 +2,17 @@ require 'test_plugin_helper'
2
2
 
3
3
  module ForemanSalt
4
4
  class SaltModuleTest < ActionDispatch::IntegrationTest
5
+ setup do
6
+ User.current = User.anonymous_admin
7
+
8
+ states = %w(state1 state2 state3 state4)
9
+ state_list = {'env1' => states, 'env2' => states}
10
+
11
+ ::ProxyAPI::Salt.any_instance.stubs(:states_list).returns(state_list)
12
+ end
13
+
5
14
  test 'index page' do
6
- FactoryGirl.create_list :salt_module, 50
15
+ FactoryGirl.create_list :salt_module, 5
7
16
  assert_index_page(salt_modules_path, 'Salt State', 'New Salt State')
8
17
  end
9
18
 
@@ -22,5 +31,25 @@ module ForemanSalt
22
31
  assert_submit_button(salt_modules_path)
23
32
  assert page.has_link? 'some_other_name'
24
33
  end
34
+
35
+ test 'import states' do
36
+ proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
37
+ state = FactoryGirl.create :salt_module, :salt_environments => [FactoryGirl.create(:salt_environment)]
38
+
39
+ visit salt_modules_path
40
+ click_link "Import from #{proxy.name}"
41
+
42
+ assert page.has_selector?('td', :text => 'env1'), 'Could not find env1 on importer page'
43
+ assert page.has_selector?('td', :text => 'Add'), 'Could not find env1 on importer page'
44
+ assert page.has_selector?('td', :text => 'state1, state2, state3, and state4'), 'Could not find states on importer page'
45
+
46
+ assert page.has_selector?('td', :text => 'Remove'), 'Could not find remove on importer page'
47
+ assert page.has_selector?('td', :text => state.name), 'Could not find state to remove'
48
+
49
+ all('input.state_check').each { |checkbox| check(checkbox[:id]) }
50
+
51
+ click_button 'Update'
52
+ assert page.has_link? 'state1'
53
+ end
25
54
  end
26
55
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.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-05-10 00:00:00.000000000 Z
11
+ date: 2015-07-06 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: '1.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: '1.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
- version: 0.6.9
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
- version: 0.6.9
40
+ version: 0.7.1
41
41
  description: Foreman Plug-in for Salt
42
42
  email:
43
43
  - stephen@redhat.com
@@ -170,37 +170,37 @@ require_paths:
170
170
  - lib
171
171
  required_ruby_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ! '>='
173
+ - - ">="
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.2.2
183
+ rubygems_version: 2.4.5
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Foreman Plug-in for Salt
187
187
  test_files:
188
+ - test/integration/salt_module_test.rb
189
+ - test/integration/salt_environment_test.rb
190
+ - test/integration/salt_autosign_test.rb
191
+ - test/integration/salt_keys_test.rb
192
+ - test/test_plugin_helper.rb
193
+ - test/unit/grains_importer_test.rb
194
+ - test/unit/grains_centos.json
195
+ - test/unit/host_extensions_test.rb
196
+ - test/unit/report_importer_test.rb
197
+ - test/unit/hostgroup_extensions_test.rb
198
+ - test/unit/salt_modules_test.rb
199
+ - test/unit/highstate.json
200
+ - test/unit/salt_keys_test.rb
188
201
  - test/functional/minions_controller_test.rb
189
- - test/functional/api/v2/salt_states_controller_test.rb
190
202
  - test/functional/api/v2/salt_autosign_controller_test.rb
203
+ - test/functional/api/v2/salt_states_controller_test.rb
191
204
  - test/functional/api/v2/salt_keys_controller_test.rb
192
205
  - test/functional/api/v2/salt_environments_controller_test.rb
193
206
  - test/factories/foreman_salt_factories.rb
194
- - test/unit/salt_keys_test.rb
195
- - test/unit/host_extensions_test.rb
196
- - test/unit/grains_centos.json
197
- - test/unit/grains_importer_test.rb
198
- - test/unit/hostgroup_extensions_test.rb
199
- - test/unit/report_importer_test.rb
200
- - test/unit/salt_modules_test.rb
201
- - test/unit/highstate.json
202
- - test/test_plugin_helper.rb
203
- - test/integration/salt_keys_test.rb
204
- - test/integration/salt_environment_test.rb
205
- - test/integration/salt_autosign_test.rb
206
- - test/integration/salt_module_test.rb