Skip to content

Commit

Permalink
Merge pull request #13720 from jameswnl/tower-migration
Browse files Browse the repository at this point in the history
Data Migration: Ansible Tower Configuration Manager type to Automation Manager
  • Loading branch information
bdunne authored Feb 2, 2017
2 parents a79d61b + ed1bb5f commit 53268b4
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class MigrateAnsibleTowerConfigurationManagerStiTypeToAutomationManager < ActiveRecord::Migration[5.0]
class ExtManagementSystem < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

class ConfigurationScript < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

class ConfiguredSystem < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

class Job < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

class EmsFolder < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

def up
say_with_time('Migrating STI type of ansible_tower configuration_managers to automation_managers') do
ExtManagementSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager'
)
end

say_with_time('Migrating STI type of ansible_tower configuration_scripts to be of automation_manager') do
ConfigurationScript.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript'
)
end

say_with_time('Migrating STI type of ansible_tower configured_systems to be of automation_manager') do
ConfiguredSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem'
)
end

say_with_time('Migrating STI type of ansible_tower jobs to be of automation_manager') do
Job.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::Job'
)
end

say_with_time('Migrating STI type of ansible_tower inventory_groups to be of automation_manager') do
EmsFolder.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::InventoryGroup').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::InventoryGroup'
)
end
end

def down
say_with_time('Migrating STI type of ansible_tower automation_managers to configuration_managers') do
ExtManagementSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager'
)
end

say_with_time('Migrating STI type of ansible_tower configuration_scripts to be of configuration_managers') do
ConfigurationScript.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript'
)
end

say_with_time('Migrating STI type of ansible_tower configured_systems to be of configuration_managers') do
ConfiguredSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem'
)
end

say_with_time('Migrating STI type of ansible_tower jobs to be of configuration_managers') do
Job.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::Job').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job'
)
end

say_with_time('Migrating STI type of ansible_tower inventory_groups to be of configuration_manager') do
EmsFolder.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::InventoryGroup').update_all(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::InventoryGroup'
)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require_migration

describe MigrateAnsibleTowerConfigurationManagerStiTypeToAutomationManager do
let(:ems_stub) { migration_stub(:ExtManagementSystem) }
let(:configuration_script_stub) { migration_stub(:ConfigurationScript) }
let(:configured_system_stub) { migration_stub(:ConfiguredSystem) }
let(:job_stub) { migration_stub(:Job) }
let(:inventory_group_stub) { migration_stub(:EmsFolder) }

migration_context :up do
context 'migrate_configuration_managers' do
it 'migrates Ansible Tower ConfigurationManager and others to be of AutomationManager type' do
manager = ems_stub.create!(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager')
script = configuration_script_stub.create!(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript'
)
system = configured_system_stub.create!(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem'
)
job = job_stub.create!(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job')
inventory_g = inventory_group_stub.create!(
:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager::InventoryGroup'
)

migrate

expect(manager.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager')
expect(script.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript')
expect(system.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem')
expect(job.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager::Job')
expect(inventory_g.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager::InventoryGroup')
end

it 'will not migrate things other than those of Ansible Tower ConfigurationManager' do
mananger = ems_stub.create!(:type => 'ManageIQ::Providers::SomeManager')
script = configuration_script_stub.create!(:type => 'ManageIQ::Providers::SomeManager::ConfigurationScript')
system = configured_system_stub.create!(:type => 'ManageIQ::Providers::SomeManager::ConfiguredSystem')
job = configured_system_stub.create!(:type => 'ManageIQ::Providers::SomeManager::Job')
inventory_g = inventory_group_stub.create!(:type => 'ManageIQ::Providers::SomeManager::InventoryGroup')

migrate

expect(mananger.reload.type).to eq('ManageIQ::Providers::SomeManager')
expect(script.reload.type).to eq('ManageIQ::Providers::SomeManager::ConfigurationScript')
expect(system.reload.type).to eq('ManageIQ::Providers::SomeManager::ConfiguredSystem')
expect(job.reload.type).to eq('ManageIQ::Providers::SomeManager::Job')
expect(inventory_g.reload.type).to eq('ManageIQ::Providers::SomeManager::InventoryGroup')
end
end
end

migration_context :down do
it 'migrates Ansible Tower AutomationManager to ConfigurationManager type' do
manager = ems_stub.create!(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager')
script = configuration_script_stub.create!(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript'
)
system = configured_system_stub.create!(
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem'
)
job = job_stub.create!(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::Job')
inventory_g = inventory_group_stub.create!(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::InventoryGroup')

migrate

expect(manager.reload.type).to eq('ManageIQ::Providers::AnsibleTower::ConfigurationManager')
expect(script.reload.type).to eq('ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript')
expect(system.reload.type).to eq('ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem')
expect(job.reload.type).to eq('ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job')
expect(inventory_g.reload.type).to eq('ManageIQ::Providers::AnsibleTower::ConfigurationManager::InventoryGroup')
end
end
end

0 comments on commit 53268b4

Please sign in to comment.