forked from ManageIQ/manageiq-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#714 from agrare/fix_orchestration_stack_c…
…onfiguration_script_reference Fix OrchestrationStack#configuration_script reference
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
db/migrate/20240105173129_add_orchestration_stack_configuration_script.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,5 @@ | ||
class AddOrchestrationStackConfigurationScript < ActiveRecord::Migration[6.1] | ||
def change | ||
add_reference :orchestration_stacks, :configuration_script, :type => :bigint, :index => true | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
db/migrate/20240108211241_fix_orchestration_stack_configuration_script_reference.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,22 @@ | ||
class FixOrchestrationStackConfigurationScriptReference < ActiveRecord::Migration[6.1] | ||
class OrchestrationStack < ActiveRecord::Base | ||
include ActiveRecord::IdRegions | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
TYPES = %w[ManageIQ::Providers::Awx::AutomationManager::Job ManageIQ::Providers::AnsibleTower::AutomationManager::Job].freeze | ||
|
||
def up | ||
say_with_time("Fixing OrchestrationStack#configuration_script foreign key") do | ||
OrchestrationStack.in_my_region.where(:type => TYPES).update_all('configuration_script_id = orchestration_template_id') | ||
OrchestrationStack.in_my_region.where(:type => TYPES).update_all(:orchestration_template_id => nil) | ||
end | ||
end | ||
|
||
def down | ||
say_with_time("Resetting OrchestrationStack#configuration_script foreign key") do | ||
OrchestrationStack.in_my_region.where(:type => TYPES).update_all('orchestration_template_id = configuration_script_id') | ||
OrchestrationStack.in_my_region.where(:type => TYPES).update_all(:configuration_script_id => nil) | ||
end | ||
end | ||
end |
84 changes: 84 additions & 0 deletions
84
.../migrations/20240108211241_fix_orchestration_stack_configuration_script_reference_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,84 @@ | ||
require_migration | ||
|
||
class FixOrchestrationStackConfigurationScriptReference | ||
class ConfigurationScriptBase < ActiveRecord::Base | ||
include ActiveRecord::IdRegions | ||
self.table_name = "configuration_scripts" | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class OrchestrationTemplate < ActiveRecord::Base | ||
include ActiveRecord::IdRegions | ||
self.inheritance_column = :_type_disabled | ||
end | ||
end | ||
|
||
describe FixOrchestrationStackConfigurationScriptReference do | ||
let(:configuration_script_base_stub) { migration_stub(:ConfigurationScriptBase) } | ||
let(:orchestration_stack_stub) { migration_stub(:OrchestrationStack) } | ||
let(:orchestration_template_stub) { migration_stub(:OrchestrationTemplate) } | ||
|
||
migration_context :up do | ||
it "fixes AWX and AnsibleTower Jobs" do | ||
job_template = configuration_script_base_stub.create!(:type => "ConfigurationScript") | ||
|
||
awx_job = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::Awx::AutomationManager::Job", :orchestration_template_id => job_template.id) | ||
tower_job = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::Job", :orchestration_template_id => job_template.id) | ||
|
||
migrate | ||
|
||
awx_job.reload | ||
tower_job.reload | ||
|
||
expect(awx_job.configuration_script_id).to eq(job_template.id) | ||
expect(awx_job.orchestration_template_id).to be_nil | ||
|
||
expect(tower_job.configuration_script_id).to eq(job_template.id) | ||
expect(tower_job.orchestration_template_id).to be_nil | ||
end | ||
|
||
it "doesn't impact other Orchestration Stacks" do | ||
cloud_template = orchestration_template_stub.create! | ||
cloud_stack = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::CloudManager::OrchestrationStack", :orchestration_template_id => cloud_template.id) | ||
|
||
migrate | ||
|
||
cloud_stack.reload | ||
|
||
expect(cloud_stack.orchestration_template_id).to eq(cloud_template.id) | ||
expect(cloud_stack.configuration_script_id).to be_nil | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "resets AWX and AnsibleTower Jobs" do | ||
job_template = configuration_script_base_stub.create!(:type => "ConfigurationScript") | ||
|
||
awx_job = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::Awx::AutomationManager::Job", :configuration_script_id => job_template.id) | ||
tower_job = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::Job", :configuration_script_id => job_template.id) | ||
|
||
migrate | ||
|
||
awx_job.reload | ||
tower_job.reload | ||
|
||
expect(awx_job.configuration_script_id).to be_nil | ||
expect(awx_job.orchestration_template_id).to eq(job_template.id) | ||
|
||
expect(tower_job.configuration_script_id).to be_nil | ||
expect(tower_job.orchestration_template_id).to eq(job_template.id) | ||
end | ||
|
||
it "doesn't impact other Orchestration Stacks" do | ||
cloud_template = orchestration_template_stub.create! | ||
cloud_stack = orchestration_stack_stub.create!(:type => "ManageIQ::Providers::CloudManager::OrchestrationStack", :orchestration_template_id => cloud_template.id) | ||
|
||
migrate | ||
|
||
cloud_stack.reload | ||
|
||
expect(cloud_stack.orchestration_template_id).to eq(cloud_template.id) | ||
expect(cloud_stack.configuration_script_id).to be_nil | ||
end | ||
end | ||
end |