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

[WIP] Set manager_ref to file path for embedded ConfigurationScripts #711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SetManagerRefEmbeddedConfigurationScripts < ActiveRecord::Migration[6.1]
class ConfigurationScript < ActiveRecord::Base
include ActiveRecord::IdRegions
self.inheritance_column = :_type_disabled
end

EMBEDDED_CONFIGURATION_SCRIPT_TYPES = %w[
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook
ManageIQ::Providers::Workflows::AutomationManager::Workflow
].freeze

def up
ConfigurationScript.in_my_region.where(:type => EMBEDDED_CONFIGURATION_SCRIPT_TYPES).update_all("manager_ref = name")
end

def down
ConfigurationScript.in_my_region.where(:type => EMBEDDED_CONFIGURATION_SCRIPT_TYPES).update_all(:manager_ref => nil)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require_migration

describe SetManagerRefEmbeddedConfigurationScripts do
let(:configuration_script_stub) { migration_stub(:ConfigurationScript) }

migration_context :up do
it "sets the manager_ref for embedded type configuration_scripts" do
embedded_ansible_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook", :name => "project/my_playbook.yaml")
mbedded_workflows_workflow = configuration_script_stub.create!(:type => "ManageIQ::Providers::Workflows::AutomationManager::Workflow", :name => "workflows/my_workflow.yaml")

migrate

expect(embedded_ansible_playbook.reload.manager_ref).to eq("project/my_playbook.yaml")
expect(mbedded_workflows_workflow.reload.manager_ref).to eq("workflows/my_workflow.yaml")
end

it "doesn't impact non-embedded configuration_scripts" do
ansible_tower_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::Playbook", :name => "project/my_playbook.yaml", :manager_ref => "123")
awx_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::Awx::AutomationManager::Playbook", :name => "project/my_playbook.yaml", :manager_ref => "123")

migrate

expect(ansible_tower_playbook.reload.manager_ref).to eq("123")
expect(awx_playbook.reload.manager_ref).to eq("123")
end
end

migration_context :down do
it "sets the manager_ref back to nil for embedded type configuration_scripts" do
embedded_ansible_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook", :name => "project/my_playbook.yaml")
mbedded_workflows_workflow = configuration_script_stub.create!(:type => "ManageIQ::Providers::Workflows::AutomationManager::Workflow", :name => "workflows/my_workflow.yaml")

migrate

expect(embedded_ansible_playbook.reload.manager_ref).to be_nil
expect(mbedded_workflows_workflow.reload.manager_ref).to be_nil
end

it "doesn't impact non-embedded configuration_scripts" do
ansible_tower_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::Playbook", :name => "project/my_playbook.yaml", :manager_ref => "123")
awx_playbook = configuration_script_stub.create!(:type => "ManageIQ::Providers::Awx::AutomationManager::Playbook", :name => "project/my_playbook.yaml", :manager_ref => "123")

migrate

expect(ansible_tower_playbook.reload.manager_ref).to eq("123")
expect(awx_playbook.reload.manager_ref).to eq("123")
end
end
end