Skip to content

Commit

Permalink
Merge pull request ManageIQ#17037 from carbonin/add_notification_on_f…
Browse files Browse the repository at this point in the history
…ailed_registration

Raise a notification when registration fails
  • Loading branch information
bdunne authored Feb 26, 2018
2 parents 89cd2bc + 7d7840e commit d4e6e61
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ gem "hamlit", "~>2.7.0"
gem "highline", "~>1.6.21", :require => false
gem "inifile", "~>3.0", :require => false
gem "kubeclient", "~>2.4.0", :require => false # For scaling pods at runtime
gem "linux_admin", "~>1.2.0", :require => false
gem "linux_admin", "~>1.2.1", :require => false
gem "log_decorator", "~>0.1", :require => false
gem "manageiq-api-client", "~>0.1.0", :require => false
gem "manageiq-messaging", :require => false, :git => "https://github.com/ManageIQ/manageiq-messaging", :branch => "master"
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_server/update_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def attempt_registration
configure_yum_proxy
# HACK: #enable_repos is not always successful immediately after #attach_products, retry to ensure they are enabled.
5.times { repos_enabled? ? break : enable_repos }
rescue LinuxAdmin::SubscriptionManagerError => e
_log.error("Registration Failed: #{e.message}")
Notification.create(:type => "server_registration_error", :options => {:server_name => MiqServer.my_server.name})
raise
end

def register
Expand Down
5 changes: 5 additions & 0 deletions db/fixtures/notification_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,8 @@
:expires_in: 24.hours
:level: :error
:audience: global
- :name: server_registration_error
:message: 'Registration failed for server %{server_name}'
:expires_in: 24.hours
:level: :error
:audience: superadmin
11 changes: 11 additions & 0 deletions spec/models/miq_server/update_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@

@server.attempt_registration
end

it "should raise a notification if registration fails" do
NotificationType.seed
result = AwesomeSpawn::CommandResult.new("stuff", "things", "more things", 1)
err = LinuxAdmin::SubscriptionManagerError.new("things", result)
expect(@server).to receive(:register).and_raise(err)
expect { @server.attempt_registration }.to raise_error(LinuxAdmin::SubscriptionManagerError)

note = Notification.find_by(:notification_type_id => NotificationType.find_by(:name => "server_registration_error").id)
expect(note.options.keys).to include(:server_name)
end
end

context "#register" do
Expand Down

0 comments on commit d4e6e61

Please sign in to comment.