-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13720 from jameswnl/tower-migration
Data Migration: Ansible Tower Configuration Manager type to Automation Manager
- Loading branch information
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...70131160216_migrate_ansible_tower_configuration_manager_sti_type_to_automation_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
73 changes: 73 additions & 0 deletions
73
...160216_migrate_ansible_tower_configuration_manager_sti_type_to_automation_manager_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |