Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify when an Openstack VM has been relocated #14604

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ManageIQ::Providers::Openstack::CloudManager::Vm::Operations::Relocation
extend ActiveSupport::Concern

include ManageIQ::Providers::Openstack::HelperMethods

included do
supports :live_migrate do
unsupported_reason_add(:live_migrate, unsupported_reason(:control)) unless supports_control?
Expand All @@ -18,7 +20,14 @@ def raw_live_migrate(options = {})
block_migration = options[:block_migration] || false
disk_over_commit = options[:disk_over_commit] || false
with_provider_connection do |connection|
connection.live_migrate_server(ems_ref, hostname, block_migration, disk_over_commit)
begin
connection.live_migrate_server(ems_ref, hostname, block_migration, disk_over_commit)
rescue => ex
error_message = parse_error_message_from_fog_response(ex.to_s)
Notification.create(:type => :vm_cloud_live_migrate_error, :options => {:instance_name => name, :error_message => error_message})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we re-throw the exception?

So, the raw_power_state is not modified? (or any other side-effects)

Copy link
Contributor Author

@mansam mansam Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it absolutely should be reraised.

else
Notification.create(:type => :vm_cloud_live_migrate_success, :options => {:instance_name => name})
end
end
# Temporarily update state for quick UI response until refresh comes along
self.update_attributes!(:raw_power_state => "MIGRATING")
Expand All @@ -31,7 +40,14 @@ def raw_evacuate(options = {})
on_shared_storage = true if on_shared_storage.nil?
admin_password = options[:admin_password]
with_provider_connection do |connection|
connection.evacuate_server(ems_ref, hostname, on_shared_storage, admin_password)
begin
connection.evacuate_server(ems_ref, hostname, on_shared_storage, admin_password)
rescue => ex
error_message = parse_error_message_from_fog_response(ex.to_s)
Notification.create(:type => :vm_cloud_evacuate_error, :options => {:instance_name => name, :error_message => error_message})
else
Notification.create(:type => :vm_cloud_evacuate_success, :options => {:instance_name => name})
end
end
# Temporarily update state for quick UI response until refresh comes along
self.update_attributes!(:raw_power_state => "MIGRATING")
Expand Down
7 changes: 7 additions & 0 deletions app/models/manageiq/providers/openstack/helper_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ManageIQ::Providers::Openstack::HelperMethods
def parse_error_message_from_fog_response(exception)
exception_string = exception.to_s
matched_message = exception_string.match(/message\\\": \\\"(.*)\\\", /)
matched_message ? matched_message[1] : exception_string
end
end
20 changes: 20 additions & 0 deletions db/fixtures/notification_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,23 @@
:expires_in: 24.hours
:level: :info
:audience: superadmin
- :name: vm_cloud_live_migrate_success
:message: 'Live migrating Instance %{instance_name} completed successfully.'
:expires_in: 24.hours
:audience: global
:level: :success
- :name: vm_cloud_live_migrate_error
:message: 'Live migrating Instance %{instance_name} failed: %{error_message}'
:expires_in: 24.hours
:level: :error
:audience: global
- :name: vm_cloud_evacuate_success
:message: 'Evacuating Instance %{instance_name} completed successfully.'
:expires_in: 24.hours
:audience: global
:level: :success
- :name: vm_cloud_evacuate_error
:message: 'Evacuating Instance %{instance_name} failed: %{error_message}'
:expires_in: 24.hours
:level: :error
:audience: global
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@

describe "vm actions" do
context "#live_migrate" do
before do
NotificationType.seed
end

it "live migrates with default options" do
expect(handle).to receive(:live_migrate_server).with(vm.ems_ref, nil, false, false)
vm.live_migrate
Expand All @@ -66,6 +70,10 @@
end

context "evacuate" do
before do
NotificationType.seed
end

it "evacuates with default options" do
expect(handle).to receive(:evacuate_server).with(vm.ems_ref, nil, true, nil)
vm.evacuate
Expand Down