From 6863e801aecc4d793b49fb8d798d7b6fbb0d810c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Ple=C5=A1ko?= Date: Thu, 7 Jun 2018 09:36:19 +0200 Subject: [PATCH] Migrate Nuage CloudSubnet default type to new subclass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nuage inventory was recently updated to fetch two types of CloudSubnets: ``` - ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3 - ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL2 ``` Before only CloudSubnetL3 were inventoried using default type CloudSubnet. With this migration we make sure that this default type is converted to CloudSubnetL3 type because persister won't modify STI type per se. Signed-off-by: Miha Pleško --- ...07084710_nuage_subclass_l3_cloud_subnet.rb | 19 ++++++++ ...710_nuage_subclass_l3_cloud_subnet_spec.rb | 45 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 db/migrate/20180607084710_nuage_subclass_l3_cloud_subnet.rb create mode 100644 spec/migrations/20180607084710_nuage_subclass_l3_cloud_subnet_spec.rb diff --git a/db/migrate/20180607084710_nuage_subclass_l3_cloud_subnet.rb b/db/migrate/20180607084710_nuage_subclass_l3_cloud_subnet.rb new file mode 100644 index 000000000..e9d2143ff --- /dev/null +++ b/db/migrate/20180607084710_nuage_subclass_l3_cloud_subnet.rb @@ -0,0 +1,19 @@ +class NuageSubclassL3CloudSubnet < ActiveRecord::Migration[5.0] + class CloudSubnet < ActiveRecord::Base + self.inheritance_column = :_type_disabled + end + + def up + say_with_time('Migrating Nuage default subnet type to L3 subnet subclass') do + CloudSubnet.where(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet') + .update_all(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3') + end + end + + def down + say_with_time('Reverting Nuage L3 subnet subclass to default subnet type') do + CloudSubnet.where(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3') + .update_all(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet') + end + end +end diff --git a/spec/migrations/20180607084710_nuage_subclass_l3_cloud_subnet_spec.rb b/spec/migrations/20180607084710_nuage_subclass_l3_cloud_subnet_spec.rb new file mode 100644 index 000000000..4078fe0f2 --- /dev/null +++ b/spec/migrations/20180607084710_nuage_subclass_l3_cloud_subnet_spec.rb @@ -0,0 +1,45 @@ +require_migration + +describe NuageSubclassL3CloudSubnet do + let(:subnet_stub) { migration_stub :CloudSubnet } + + migration_context :up do + it 'migrates base Nuage type' do + subnet = subnet_stub.create!(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet') + + migrate + subnet.reload + + expect(subnet.type).to eql('ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3') + end + + it 'doesnt modify other subnets' do + subnet = subnet_stub.create!(:type => 'CloudSubnet') + + migrate + subnet.reload + + expect(subnet.type).to eql('CloudSubnet') + end + end + + migration_context :down do + it 'restores base Nuage type' do + subnet = subnet_stub.create!(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3') + + migrate + subnet.reload + + expect(subnet.type).to eql('ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet') + end + + it 'doesnt modify other subnets' do + subnet = subnet_stub.create!(:type => 'CloudSubnet') + + migrate + subnet.reload + + expect(subnet.type).to eql('CloudSubnet') + end + end +end