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

Migrate Nuage CloudSubnet default type to new subclass #215

Merged
merged 1 commit into from
Aug 24, 2018
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
24 changes: 24 additions & 0 deletions db/migrate/20180607084710_nuage_subclass_l3_cloud_subnet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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::CloudSubnet::L3')
end
end

def down
say_with_time('Reverting Nuage L3 subnet subclass to default subnet type') do
CloudSubnet.where(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet::L3')
.update_all(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet')
end

say_with_time('Reverting Nuage L2 subnet subclass to default subnet type') do
CloudSubnet.where(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet::L2')
.update_all(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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::CloudSubnet::L3')
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_l3 = subnet_stub.create!(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet::L3')
subnet_l2 = subnet_stub.create!(:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet::L2')

migrate
subnet_l3.reload
subnet_l2.reload

expect(subnet_l3.type).to eql('ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet')
expect(subnet_l2.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