-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from agrare/fix_cinder_manager_query_cloud_vo…
…lumes Fix CloudVolume* STI types on older CinderManagers
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
db/migrate/20201202172818_fix_cinder_manager_cloud_volumes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
56 changes: 56 additions & 0 deletions
56
spec/migrations/20201202172818_fix_cinder_manager_cloud_volumes_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |