foreman_discovery 16.0.0 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40c64a4f3c756e207293b6e5be67190294b9c4f2ab5054e08edd8d085718556f
4
- data.tar.gz: b22ef9bf418ac18e94170429e7368cb1c6f94b9b0d2290b60341a9415e908b01
3
+ metadata.gz: daf02841d730bd8c0bce174762bd59b42f323d1a971b40dc72a6bd5a32d350fd
4
+ data.tar.gz: 4c89487acc8feab8fdba5d76be4d8f54dc78970a0cff7b2b85945d6824890c9c
5
5
  SHA512:
6
- metadata.gz: d9f9013fa2d04e883da3c0c8c42b5a6e3552093323698359b8e9b70179f0284ccf35d633eac5720cc03fa79678af915b5eda3c7508be775b0836128ef6d738d8
7
- data.tar.gz: 688c8d68c1a87aff1fda0a00eef057daf0c35a06ce007746e568763e868c82ee718d15a51d1124cb9dc1a47498ec94bc7f33e62d986ba7ed23e3eb6babfd140f
6
+ metadata.gz: 662c55ac2db702681b11bddcffa199048c6c62e2cc8d2b81a374426a45f8a6659fadf1a56642bc3667e534c534983acf970c5e7e1e7ec9b804d7b97a3ce58692
7
+ data.tar.gz: 2b185dcda6bb7eaa610c58eed077f753e0e5f4fb537276adb4cd48b8d339a154931d6cbdec64ec1416e91137f97fb9479c5a05b0b89d39f1d2469b3a5bc6c5ac
@@ -137,12 +137,12 @@ class Host::Discovered < ::Host::Base
137
137
  subnet.present? && subnet.discovery.present?
138
138
  end
139
139
 
140
- def proxy_url
141
- proxied? ? subnet.discovery.url + "/discovery/#{self.ip}" : "https://#{self.ip}:8443"
140
+ def proxy_url(node_ip)
141
+ proxied? ? subnet.discovery.url + "/discovery/#{node_ip}" : "https://#{node_ip}:8443"
142
142
  end
143
143
 
144
144
  def refresh_facts
145
- facts = ::ForemanDiscovery::NodeAPI::Inventory.new(:url => proxy_url).facter
145
+ facts = ::ForemanDiscovery::NodeAPI::Inventory.new(:url => proxy_url(self.ip)).facter
146
146
  self.class.import_host facts
147
147
  import_facts facts
148
148
  rescue => e
@@ -150,20 +150,42 @@ class Host::Discovered < ::Host::Base
150
150
  raise ::Foreman::WrappedException.new(e, N_("Could not get facts from proxy %{url}: %{error}"), :url => proxy_url, :error => e)
151
151
  end
152
152
 
153
- def reboot
154
- resource = ::ForemanDiscovery::NodeAPI::Power.service(:url => proxy_url)
155
- resource.reboot
156
- rescue => e
157
- ::Foreman::Logging.exception("Unable to reboot #{name}", e)
158
- raise ::Foreman::WrappedException.new(e, N_("Unable to reboot %{name} via %{url}: %{msg}"), :name => name, :url => proxy_url, :msg => e.to_s)
153
+ def reboot(node_ip = nil)
154
+ # perform the action against the original lease as well as the new reservation
155
+ [node_ip || facts["discovery_bootip"] || facts["ipaddress"], self.ip].compact.each do |next_ip|
156
+ begin
157
+ node_url = proxy_url(next_ip)
158
+ logger.debug "Performing reboot call against #{node_url}"
159
+ resource = ::ForemanDiscovery::NodeAPI::Power.service(:url => node_url)
160
+ return true if resource.reboot
161
+ rescue => e
162
+ msg = N_("Unable to perform reboot on %{name} (%{url}): %{msg}")
163
+ ::Foreman::Logging.exception(msg % { :name => name, :url => node_url, :msg => e.to_s }, e)
164
+ if next_ip == self.ip
165
+ raise ::Foreman::WrappedException.new(e, msg, :name => name, :url => node_url, :msg => e.to_s)
166
+ end
167
+ end
168
+ end
169
+ false
159
170
  end
160
171
 
161
- def kexec json
162
- resource = ::ForemanDiscovery::NodeAPI::Power.service(:url => proxy_url)
163
- resource.kexec json
164
- rescue => e
165
- ::Foreman::Logging.exception("Unable to perform kexec on #{name}", e)
166
- raise ::Foreman::WrappedException.new(e, N_("Unable to perform kexec on %{name} via %{url}: %{msg}"), :name => name, :url => proxy_url, :msg => e.to_s)
172
+ def kexec(json, node_ip = nil)
173
+ # perform the action against the original lease as well as the new reservation
174
+ [node_ip || facts["discovery_bootip"] || facts["ipaddress"], self.ip].compact.each do |next_ip|
175
+ begin
176
+ node_url = proxy_url(next_ip)
177
+ logger.debug "Performing kexec call against #{node_url}"
178
+ resource = ::ForemanDiscovery::NodeAPI::Power.service(:url => node_url)
179
+ return true if resource.kexec(json)
180
+ rescue => e
181
+ msg = N_("Unable to perform kexec on %{name} (%{url}): %{msg}")
182
+ ::Foreman::Logging.exception(msg % { :name => name, :url => node_url, :msg => e.to_s }, e)
183
+ if next_ip == self.ip
184
+ raise ::Foreman::WrappedException.new(e, msg, :name => name, :url => node_url, :msg => e.to_s)
185
+ end
186
+ end
187
+ end
188
+ false
167
189
  end
168
190
 
169
191
  def self.model_name
@@ -27,7 +27,7 @@ module Host::ManagedExtensions
27
27
  end
28
28
 
29
29
  def setReboot
30
- old.becomes(Host::Discovered).reboot
30
+ old.becomes(Host::Discovered).reboot(facts["discovery_bootip"] || facts["ipaddress"])
31
31
  # It is too late to report error in the post_queue, we catch them and
32
32
  # continue. If flash is implemented for new hosts (http://projects.theforeman.org/issues/10559)
33
33
  # we can report the error to the user perhaps.
@@ -1,3 +1,3 @@
1
1
  module ForemanDiscovery
2
- VERSION = "16.0.0"
2
+ VERSION = "16.0.1"
3
3
  end
@@ -183,7 +183,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
183
183
  def test_reboot_failure
184
184
  @request.env["HTTP_REFERER"] = discovered_hosts_url
185
185
  host = discover_host_from_facts(@facts)
186
- ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(false)
186
+ ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).twice.returns(false)
187
187
  post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
188
188
  assert_redirected_to discovered_hosts_url
189
189
  assert_equal "Failed to reboot host #{host.name}", flash[:error]
@@ -195,7 +195,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
195
195
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).raises("request failed")
196
196
  post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
197
197
  assert_redirected_to discovered_hosts_url
198
- assert_match(/ERF50-4973/, flash[:error])
198
+ assert_match(/ERF50-9494/, flash[:error])
199
199
  end
200
200
 
201
201
  def test_auto_provision_success
@@ -271,7 +271,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
271
271
  def test_multiple_reboot_failure
272
272
  @request.env["HTTP_REFERER"] = discovered_hosts_url
273
273
  host = discover_host_from_facts(@facts)
274
- ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(false)
274
+ ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).twice.returns(false)
275
275
  post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
276
276
  assert_redirected_to discovered_hosts_url
277
277
  assert_equal "Errors during reboot: #{host.name}: failed to reboot", flash[:error]
@@ -284,7 +284,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
284
284
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).raises("request failed")
285
285
  post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
286
286
  assert_redirected_to discovered_hosts_url
287
- assert_match(/ERF50-4973/, flash[:error])
287
+ assert_match(/ERF50-9494/, flash[:error])
288
288
  assert_nil flash[:success]
289
289
  end
290
290
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.0.0
4
+ version: 16.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aditi Puntambekar
@@ -69,7 +69,7 @@ authors:
69
69
  autorequire:
70
70
  bindir: bin
71
71
  cert_chain: []
72
- date: 2019-11-05 00:00:00.000000000 Z
72
+ date: 2019-11-26 00:00:00.000000000 Z
73
73
  dependencies: []
74
74
  description: MaaS Discovery Plugin engine for Foreman
75
75
  email: gsutclif@redhat.com