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

Fix CloudVolume* STI types on older CinderManagers #538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 57 additions & 0 deletions db/migrate/20201202172818_fix_cinder_manager_cloud_volumes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class FixCinderManagerCloudVolumes < ActiveRecord::Migration[5.2]
class CloudVolume < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

class CloudVolumeBackup < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

class CloudVolumeSnapshot < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

class CloudVolumeType < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

def up
[CloudVolume, CloudVolumeBackup, CloudVolumeSnapshot, CloudVolumeType].each do |klass|
klass_name = klass.name.sub("FixCinderManagerCloudVolumes::", "")

old_type = "#{openstack_klass}::#{klass_name}"
new_type = "#{cinder_klass}::#{klass_name}"

say_with_time("Fixing OpenStack #{klass_name} STI class") do
klass.in_my_region.where(:type => old_type).update_all(:type => new_type)
end
end
end

def down
[CloudVolume, CloudVolumeBackup, CloudVolumeSnapshot, CloudVolumeType].each do |klass|
klass_name = klass.name.sub("FixCinderManagerCloudVolumes::", "")

old_type = "#{cinder_klass}::#{klass_name}"
new_type = "#{openstack_klass}::#{klass_name}"

say_with_time("Resetting OpenStack #{klass_name} STI class") do
klass.in_my_region.where(:type => old_type).update_all(:type => new_type)
end
end
end

private

def cinder_klass
"ManageIQ::Providers::Openstack::StorageManager::CinderManager".freeze
end

def openstack_klass
"ManageIQ::Providers::Openstack::CloudManager".freeze
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require_migration

RSpec.describe FixCinderManagerCloudVolumes do
let(:cloud_volume_stub) { migration_stub(:CloudVolume) }
let(:cloud_volume_snapshot_stub) { migration_stub(:CloudVolumeSnapshot) }
let(:cloud_volume_backup_stub) { migration_stub(:CloudVolumeBackup) }
let(:cloud_volume_type_stub) { migration_stub(:CloudVolumeType) }

migration_context :up do
it "Fixes the STI class of OpenStack Cloud Volumes, Backups, Snapshots, and Types" do
cloud_volume = cloud_volume_stub.create!(
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolume"
)
cloud_volume_snapshot = cloud_volume_snapshot_stub.create!(
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolumeSnapshot"
)
cloud_volume_backup = cloud_volume_backup_stub.create!(
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolumeBackup"
)
cloud_volume_type = cloud_volume_type_stub.create!(
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolumeType"
)

migrate

expect(cloud_volume.reload.type).to eq("ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolume")
expect(cloud_volume_snapshot.reload.type).to eq("ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeSnapshot")
expect(cloud_volume_backup.reload.type).to eq("ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeBackup")
expect(cloud_volume_type.reload.type).to eq("ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeType")
end
end

migration_context :down do
it "Resets the STI class of OpenStack Cloud Volumes, Backups, Snapshots, and Types" do
cloud_volume = cloud_volume_stub.create!(
:type => "ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolume"
)
cloud_volume_snapshot = cloud_volume_snapshot_stub.create!(
:type => "ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeSnapshot"
)
cloud_volume_backup = cloud_volume_backup_stub.create!(
:type => "ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeBackup"
)
cloud_volume_type = cloud_volume_type_stub.create!(
:type => "ManageIQ::Providers::Openstack::StorageManager::CinderManager::CloudVolumeType"
)

migrate

expect(cloud_volume.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolume")
expect(cloud_volume_snapshot.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolumeSnapshot")
expect(cloud_volume_backup.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolumeBackup")
expect(cloud_volume_type.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolumeType")
end
end
end