Skip to content

Commit

Permalink
Merge pull request #538 from agrare/fix_cinder_manager_query_cloud_vo…
Browse files Browse the repository at this point in the history
…lumes

Fix CloudVolume* STI types on older CinderManagers
  • Loading branch information
Fryguy authored Dec 7, 2020
2 parents 6ff1d59 + 5924e11 commit 4fe4f3b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
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

0 comments on commit 4fe4f3b

Please sign in to comment.