Skip to content

Commit

Permalink
Merge pull request ManageIQ#530 from agrare/fix_cloud_volume_sti_subc…
Browse files Browse the repository at this point in the history
…lass

Update the GCE CloudVolume STI class
  • Loading branch information
Fryguy authored Nov 6, 2020
2 parents 3f38b53 + 5c10013 commit f0953eb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
30 changes: 30 additions & 0 deletions db/migrate/20201103143405_fix_google_cloud_volume_sti.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class FixGoogleCloudVolumeSti < ActiveRecord::Migration[5.2]
class ExtManagementSystem < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

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

belongs_to :ext_management_system,
:foreign_key => :ems_id,
:class_name => "FixGoogleCloudVolumeSti::ExtManagementSystem"
end

GOOGLE_CLOUD_KLASS = "ManageIQ::Providers::Google::CloudManager".freeze
GOOGLE_CLOUD_VOLUME_KLASS = "ManageIQ::Providers::Google::CloudManager::CloudVolume".freeze

def up
gce_relation = ExtManagementSystem.in_my_region.where(:type => GOOGLE_CLOUD_KLASS)
CloudVolume.in_my_region.where(:type => nil, :ext_management_system => gce_relation)
.update_all(:type => GOOGLE_CLOUD_VOLUME_KLASS)
end

def down
gce_relation = ExtManagementSystem.in_my_region.where(:type => GOOGLE_CLOUD_KLASS)
CloudVolume.in_my_region.where(:type => GOOGLE_CLOUD_VOLUME_KLASS, :ext_management_system => gce_relation)
.update_all(:type => nil)
end
end
55 changes: 55 additions & 0 deletions spec/migrations/20201103143405_fix_google_cloud_volume_sti_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require_migration

RSpec.describe FixGoogleCloudVolumeSti do
let(:ems_stub) { migration_stub(:ExtManagementSystem) }
let(:volume_stub) { migration_stub(:CloudVolume) }

migration_context :up do
it "Fixes the STI class of Google Cloud Volumes" do
gce = ems_stub.create!(:type => "ManageIQ::Providers::Google::CloudManager")
volume = volume_stub.create!(:ext_management_system => gce, :type => nil)

migrate

expect(volume.reload.type).to eq("ManageIQ::Providers::Google::CloudManager::CloudVolume")
end

it "Doesn't impact non-Google Cloud volumes" do
osp = ems_stub.create!(:type => "ManageIQ::Providers::Openstack::CloudManager")
volume = volume_stub.create!(
:ext_management_system => osp,
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolume"
)

migrate

expect(volume.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolume")
end
end

migration_context :down do
it "Fixes the STI class of Google Cloud Volumes" do
gce = ems_stub.create!(:type => "ManageIQ::Providers::Google::CloudManager")
volume = volume_stub.create!(
:ext_management_system => gce,
:type => "ManageIQ::Providers::Google::CloudManager::CloudVolume"
)

migrate

expect(volume.reload.type).to be_nil
end

it "Doesn't impact non-Google Cloud volumes" do
osp = ems_stub.create!(:type => "ManageIQ::Providers::Openstack::CloudManager")
volume = volume_stub.create!(
:ext_management_system => osp,
:type => "ManageIQ::Providers::Openstack::CloudManager::CloudVolume"
)

migrate

expect(volume.reload.type).to eq("ManageIQ::Providers::Openstack::CloudManager::CloudVolume")
end
end
end

0 comments on commit f0953eb

Please sign in to comment.