foreman_salt 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6b22fef4003be237f6ba02e594fa8d583bc218f
4
- data.tar.gz: e30d40a831982a5c5f07c645ea8936b5be3ab2da
3
+ metadata.gz: 53e9c60ec9d9ffcbadae6c71eae62c4e545bd20f
4
+ data.tar.gz: 6dd19160007e09f75ed43082ebc446c848a260dd
5
5
  SHA512:
6
- metadata.gz: 2bbb4d5db09be8cc76f57375e61207e0f2a9758bd6ed7f6140234af2a34ec608329180f3001ff5ab7ee712b77b5e43ee1313629c33f0eb74c5fd091782238de1
7
- data.tar.gz: 51751be171370526cc4deace259268e790707084eef0f3bc88e17e2d74797b8702e86c808af8355f56a0e043f9f87193b7c39e4896fbd496a962948728e5359a
6
+ metadata.gz: 5553e760b7ba4c5ccbcb4694818f2cee361cb4bfa26717817aed8e1ae016d3b01207336745bf899f394e69fc2cc5d66f3ae0c27423d44d23ba183b0aaab64490
7
+ data.tar.gz: f4a10ec1a21cddb8134961584baca1ba768fd75f51c30a9ed9b94a28965e854fd3b660ae189eeab7b098374681c255ffb90c7385b22c2b344e3f45acf12dee94
@@ -28,7 +28,7 @@ module ForemanSalt
28
28
  param :id, :identifier_dottable, :required => true
29
29
  param_group :minion
30
30
  def update
31
- params[:minion][:salt_module_ids] = params[:minion].delete(:salt_state_ids)
31
+ params[:minion][:salt_module_ids] = params[:minion].delete(:salt_state_ids) if params[:minion]
32
32
  process_response @salt_minion.update_attributes(params[:minion])
33
33
  end
34
34
 
@@ -20,17 +20,16 @@ module ForemanSalt
20
20
  scoped_search :in => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
21
21
 
22
22
  validate :salt_modules_in_host_environment
23
+
24
+ after_build :delete_salt_key, :if => ->(host) { host.salt_proxy }
25
+ before_provision :accept_salt_key, :if => ->(host) { host.salt_proxy }
26
+ before_destroy :delete_salt_key, :if => ->(host) { host.salt_proxy }
23
27
  end
24
28
 
25
29
  def configuration_with_salt?
26
30
  configuration_without_salt? || !!salt_proxy
27
31
  end
28
32
 
29
- def handle_salt
30
- return true unless salt?
31
- set_salt_autosign
32
- end
33
-
34
33
  def params_with_salt_proxy
35
34
  params = params_without_salt_proxy
36
35
  params['salt_master'] = salt_master unless salt_master.blank?
@@ -82,6 +81,25 @@ module ForemanSalt
82
81
  errors.add(:base, _('Host must have an environment in order to set salt states'))
83
82
  end
84
83
  end
84
+
85
+ private
86
+
87
+ def accept_salt_key
88
+ begin
89
+ Rails.logger.info("Host #{fqdn} is built, accepting Salt key")
90
+ ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn).accept
91
+ rescue Foreman::Exception => e
92
+ Rails.logger.warn("Unable to accept key for #{fqdn}: #{e}")
93
+ end
94
+ end
95
+
96
+ def delete_salt_key
97
+ begin
98
+ ForemanSalt::SmartProxies::SaltKeys.find(salt_proxy, fqdn).delete
99
+ rescue Foreman::Exception => e
100
+ Rails.logger.warn("Unable to delete key for #{fqdn}: #{e}")
101
+ end
102
+ end
85
103
  end
86
104
  end
87
105
  end
@@ -8,11 +8,9 @@ begin
8
8
 
9
9
  # Model Extensions
10
10
  ::Host::Managed.send :include, ForemanSalt::Concerns::HostManagedExtensions
11
- ::Host::Managed.send :include, ForemanSalt::Concerns::Orchestration::Salt
12
11
  ::Hostgroup.send :include, ForemanSalt::Concerns::HostgroupExtensions
13
12
 
14
13
  # Controller Extensions
15
- ::UnattendedController.send :include, ForemanSalt::Concerns::UnattendedControllerExtensions
16
14
  ::HostsController.send :include, ForemanSalt::Concerns::HostsControllerExtensions
17
15
  ::HostgroupsController.send :include, ForemanSalt::Concerns::HostgroupsControllerExtensions
18
16
  rescue => e
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -51,5 +51,24 @@ module ForemanSalt
51
51
  host.salt_proxy = proxy
52
52
  assert host.configuration?
53
53
  end
54
+
55
+ context 'key handling' do
56
+ before do
57
+ @host = FactoryGirl.create(:host, :with_salt_proxy, :build => true)
58
+ @key_stub = stub("key")
59
+ ForemanSalt::SmartProxies::SaltKeys.expects(:find).with(@host.salt_proxy, @host.fqdn).returns(@key_stub)
60
+ end
61
+
62
+ test 'host key is accepted when host is built' do
63
+ @key_stub.expects(:accept).returns(true)
64
+ assert @host.built
65
+ @host.run_callbacks(:commit) # callbacks don't run with Foreman's transactional fixtures
66
+ end
67
+
68
+ test 'host key is deleted when host is removed' do
69
+ @key_stub.expects(:delete).returns(true)
70
+ assert @host.destroy
71
+ end
72
+ end
54
73
  end
55
74
  end
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: 4.0.0
4
+ version: 4.0.1
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-10-12 00:00:00.000000000 Z
11
+ date: 2015-10-25 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
@@ -59,7 +59,6 @@ files:
59
59
  - app/controllers/foreman_salt/application_controller.rb
60
60
  - app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
61
61
  - app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb
62
- - app/controllers/foreman_salt/concerns/unattended_controller_extensions.rb
63
62
  - app/controllers/foreman_salt/minions_controller.rb
64
63
  - app/controllers/foreman_salt/salt_autosign_controller.rb
65
64
  - app/controllers/foreman_salt/salt_environments_controller.rb
@@ -74,7 +73,6 @@ files:
74
73
  - app/lib/proxy_api/salt.rb
75
74
  - app/models/foreman_salt/concerns/host_managed_extensions.rb
76
75
  - app/models/foreman_salt/concerns/hostgroup_extensions.rb
77
- - app/models/foreman_salt/concerns/orchestration/salt.rb
78
76
  - app/models/foreman_salt/fact_name.rb
79
77
  - app/models/foreman_salt/host_salt_module.rb
80
78
  - app/models/foreman_salt/hostgroup_salt_module.rb
@@ -172,17 +170,17 @@ require_paths:
172
170
  - lib
173
171
  required_ruby_version: !ruby/object:Gem::Requirement
174
172
  requirements:
175
- - - '>='
173
+ - - ">="
176
174
  - !ruby/object:Gem::Version
177
175
  version: '0'
178
176
  required_rubygems_version: !ruby/object:Gem::Requirement
179
177
  requirements:
180
- - - '>='
178
+ - - ">="
181
179
  - !ruby/object:Gem::Version
182
180
  version: '0'
183
181
  requirements: []
184
182
  rubyforge_project:
185
- rubygems_version: 2.4.8
183
+ rubygems_version: 2.4.5
186
184
  signing_key:
187
185
  specification_version: 4
188
186
  summary: Foreman Plug-in for Salt
@@ -1,18 +0,0 @@
1
- module ForemanSalt
2
- module Concerns
3
- module UnattendedControllerExtensions
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- before_filter :handle_salt, :only => [:provision]
8
- end
9
-
10
- private
11
-
12
- def handle_salt
13
- return true if @spoof
14
- render(:text => _('Failed to set autosign for host. Terminating the build!'), :status => 500) unless @host.respond_to?(:handle_salt) && @host.handle_salt
15
- end
16
- end
17
- end
18
- end
@@ -1,75 +0,0 @@
1
- module ForemanSalt
2
- module Concerns
3
- module Orchestration
4
- module Salt
5
- extend ActiveSupport::Concern
6
- include ::Orchestration
7
-
8
- included do
9
- after_validation :queue_salt_autosign
10
- before_destroy :queue_salt_destroy
11
- end
12
-
13
- def salt?
14
- name.present? && salt_proxy.present?
15
- end
16
-
17
- def initialize_salt
18
- @salt_api ||= ProxyAPI::Salt.new :url => salt_proxy.url
19
- end
20
-
21
- def queue_salt_autosign
22
- return unless salt? && errors.empty?
23
- new_record? ? queue_set_salt_autosign : queue_update_salt_autosign
24
- end
25
-
26
- def queue_set_salt_autosign
27
- # do nothing - we'll set autosign at the last second: when a host requests a provision URL
28
- end
29
-
30
- def queue_update_salt_autosign
31
- # Host has been built --> remove auto sign
32
- if old.build? && !build?
33
- queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign])
34
- end
35
- end
36
-
37
- def queue_salt_destroy
38
- return unless salt? && errors.empty?
39
- queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign])
40
- queue.create(:name => _('Delete existing salt key for %s') % self, :priority => 50, :action => [self, :del_salt_key])
41
- end
42
-
43
- def queue_del_salt_autosign
44
- return unless salt? && errors.empty?
45
- queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign])
46
- end
47
-
48
- def set_salt_autosign
49
- logger.info "Create autosign entry for #{name}"
50
- initialize_salt
51
- del_salt_key # if there's already an existing key
52
- @salt_api.autosign_create name
53
- rescue => e
54
- failure _("Failed to create %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
55
- end
56
-
57
- def del_salt_autosign
58
- logger.info "Remove autosign entry for #{name}"
59
- initialize_salt
60
- @salt_api.autosign_remove name
61
- rescue => e
62
- failure _("Failed to remove %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
63
- end
64
-
65
- def del_salt_key
66
- logger.info "Delete salt key for #{name}"
67
- initialize_salt
68
- @salt_api.key_delete name
69
- rescue => e
70
- failure _("Failed to delete %{name}'s Salt key: %{e}") % { :name => name, :e => e }
71
- end
72
- end
73
- end
74
- end
75
- end