Skip to content

Commit

Permalink
Set manager_ref to file path for embedded scripts
Browse files Browse the repository at this point in the history
The manager_ref is typically used to track the "unique" attribute of an
object, for ansible_tower/awx the manager_ref is the job_template.id but
for embedded_ansible the manager_ref was nil and the name was set to the
file path.  Embedded Workflows copied this behavior, but it would be
preferable to match how the "external" automation managers operate and
also open up the `:name` column for a more user friendly name.
  • Loading branch information
agrare committed Nov 14, 2023
1 parent 7a159b6 commit 3e33249
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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

0 comments on commit 3e33249

Please sign in to comment.