Skip to content

Commit

Permalink
Merge pull request #557 from nasark/workflow_template_support
Browse files Browse the repository at this point in the history
Use Ansible Workflow/Job Template Common Parent Class
  • Loading branch information
agrare committed Sep 19, 2024
2 parents 1aeec82 + d32c864 commit 4e555e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module MiqAeEngine
class MiqAeAnsibleTemplateMethod < MiqAeAnsibleMethodBase
TEMPLATE_CLASS = ManageIQ::Providers::ExternalAutomationManager::ConfigurationScript
TEMPLATE_CLASS = ManageIQ::Providers::AutomationManager::ConfigurationScript

private

Expand Down
41 changes: 39 additions & 2 deletions spec/miq_ae_ansible_template_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let(:miq_task) { FactoryBot.create(:miq_task) }
let(:manager) { FactoryBot.create(:automation_manager_ansible_tower) }
let(:template) { FactoryBot.create(:ansible_configuration_script, :manager => manager) }
let(:workflow_template) { FactoryBot.create(:ansible_configuration_workflow, :manager => manager) }

let(:workspace) do
double("MiqAeEngine::MiqAeWorkspaceRuntime", :root => root_object,
Expand Down Expand Up @@ -106,7 +107,7 @@
end
end

context "regular method" do
context "regular method with jobs" do
before do
allow(described_class::TEMPLATE_CLASS).to receive(:find).and_return(template)
allow(template).to receive(:run_with_miq_job).and_return(miq_task.id)
Expand All @@ -133,7 +134,7 @@
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "template launch fails" do
it "job template launch fails" do
expect(template).to receive(:run_with_miq_job).and_raise("Bamm Bamm Rubble")

at = described_class.new(aem, obj, inputs)
Expand All @@ -142,6 +143,42 @@
end
end

context "regular method with workflows" do
before do
allow(described_class::TEMPLATE_CLASS).to receive(:find).and_return(workflow_template)
allow(workflow_template).to receive(:run_with_miq_job).and_return(miq_task.id)
allow(MiqRegion).to receive(:my_region).and_return(FactoryBot.create(:miq_region))
allow(AutomateWorkspace).to receive(:create).and_return(aw)
allow(MiqTask).to receive(:wait_for_taskid).and_return(miq_task)
allow(workspace).to receive(:update_workspace)
end

it "success" do
miq_task.update_status(MiqTask::STATE_FINISHED, MiqTask::STATUS_OK, "Done")

at = described_class.new(aem, obj, inputs)
at.run

expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "method fails" do
miq_task.update_status(MiqTask::STATE_FINISHED, MiqTask::STATUS_ERROR, "Done")

at = described_class.new(aem, obj, inputs)
expect { at.run }.to raise_exception(MiqAeException::Error)
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "workflow template launch fails" do
expect(workflow_template).to receive(:run_with_miq_job).and_raise("Bamm Bamm Rubble")

at = described_class.new(aem, obj, inputs)
expect { at.run }.to raise_exception(MiqAeException::Error)
expect { aw.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end
end

context "state machine" do
before do
root_hash['ae_state_started'] = Time.zone.now.utc.to_s
Expand Down

0 comments on commit 4e555e6

Please sign in to comment.