-
Notifications
You must be signed in to change notification settings - Fork 54
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 #86 from jameswnl/workflow
Integrate with Tower Workflow
- Loading branch information
Showing
11 changed files
with
1,513 additions
and
15,223 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
app/models/manageiq/providers/ansible_tower/automation_manager/configuration_workflow.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 ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationWorkflow < | ||
ManageIQ::Providers::ExternalAutomationManager::ConfigurationWorkflow | ||
|
||
include ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ConfigurationWorkflow | ||
end |
31 changes: 31 additions & 0 deletions
31
...dels/manageiq/providers/ansible_tower/shared/automation_manager/configuration_workflow.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,31 @@ | ||
module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::ConfigurationWorkflow | ||
extend ActiveSupport::Concern | ||
|
||
include ProviderObjectMixin | ||
|
||
module ClassMethods | ||
def provider_collection(manager) | ||
manager.with_provider_connection do |connection| | ||
connection.api.workflow_job_templates | ||
end | ||
end | ||
end | ||
|
||
def run(vars = {}) | ||
options = vars.merge(merge_extra_vars(vars[:extra_vars])) | ||
|
||
with_provider_object do |jt| | ||
jt.launch(options) | ||
end | ||
end | ||
|
||
def merge_extra_vars(external) | ||
{:extra_vars => variables.merge(external || {}).to_json} | ||
end | ||
|
||
def provider_object(connection = nil) | ||
(connection || connection_source.connect).api.workflow_job_templates.find(manager_ref) | ||
end | ||
|
||
FRIENDLY_NAME = 'Ansible Tower Workflow Job Template'.freeze | ||
end |
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
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
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
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
7 changes: 7 additions & 0 deletions
7
...models/manageiq/providers/ansible_tower/automation_manager/configuration_workflow_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,7 @@ | ||
describe ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationWorkflow do | ||
let(:provider_with_authentication) { FactoryGirl.create(:provider_ansible_tower, :with_authentication) } | ||
let(:manager_with_authentication) { provider_with_authentication.managers.first } | ||
let(:manager_with_configuration_workflows) { FactoryGirl.create(:automation_manager_ansible_tower, :provider, :configuration_workflow) } | ||
|
||
it_behaves_like 'ansible configuration_workflow' | ||
end |
59 changes: 59 additions & 0 deletions
59
spec/support/ansible_shared/automation_manager/configuration_workflow.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,59 @@ | ||
require 'ansible_tower_client' | ||
require 'faraday' | ||
|
||
shared_examples_for "ansible configuration_workflow" do | ||
let(:api) { double(:api, :workflow_job_templates => double(:workflow_job_templates)) } | ||
let(:connection) { double(:connection, :api => api) } | ||
let(:job) { AnsibleTowerClient::WorkflowJob.new(connection.api, "id" => 1) } | ||
let(:workflow_job_template) { AnsibleTowerClient::WorkflowJobTemplate.new(connection.api, "limit" => "", "id" => 1, "url" => "api/workflow_job_templates/1/", "name" => "template", "description" => "description", "extra_vars" => {:instance_ids => ['i-3434']}) } | ||
let(:manager) { manager_with_configuration_workflows } | ||
context "#run" do | ||
before do | ||
allow_any_instance_of(Provider).to receive_messages(:connect => connection) | ||
allow(api.workflow_job_templates).to receive(:find) { workflow_job_template } | ||
end | ||
|
||
it "launches the referenced ansible workflow job template" do | ||
expect(workflow_job_template).to receive(:launch).with(:extra_vars => "{\"instance_ids\":[\"i-3434\"]}").and_return(job) | ||
expect(manager.configuration_workflows.first.run).to be_a AnsibleTowerClient::WorkflowJob | ||
end | ||
|
||
it "accepts different variables to launch a job template against" do | ||
added_extras = {:extra_vars => {:some_key => :some_value}} | ||
expect(workflow_job_template).to receive(:launch).with(:extra_vars=>"{\"instance_ids\":[\"i-3434\"],\"some_key\":\"some_value\"}").and_return(job) | ||
expect(manager.configuration_workflows.first.run(added_extras)).to be_a AnsibleTowerClient::WorkflowJob | ||
end | ||
end | ||
|
||
context "#merge_extra_vars" do | ||
it "merges internal and external hashes to send out to the tower gem" do | ||
config_workflow = manager.configuration_workflows.first | ||
external = {:some_key => :some_value} | ||
internal = config_workflow.variables | ||
expect(internal).to be_a Hash | ||
expect(config_workflow.merge_extra_vars(external)).to eq(:extra_vars => "{\"instance_ids\":[\"i-3434\"],\"some_key\":\"some_value\"}") | ||
end | ||
|
||
it "merges an internal hash and an empty hash to send out to the tower gem" do | ||
config_workflow = manager.configuration_workflows.first | ||
external = nil | ||
expect(config_workflow.merge_extra_vars(external)).to eq(:extra_vars => "{\"instance_ids\":[\"i-3434\"]}") | ||
end | ||
|
||
it "merges an empty internal hash and a hash to send out to the tower gem" do | ||
external = {:some_key => :some_value} | ||
internal = {} | ||
config_workflow = manager.configuration_workflows.first | ||
config_workflow.variables = internal | ||
expect(config_workflow.merge_extra_vars(external)).to eq(:extra_vars => "{\"some_key\":\"some_value\"}") | ||
end | ||
|
||
it "merges all empty arguments to send out to the tower gem" do | ||
external = nil | ||
internal = {} | ||
config_workflow = manager.configuration_workflows.first | ||
config_workflow.variables = internal | ||
expect(config_workflow.merge_extra_vars(external)).to eq(:extra_vars => "{}") | ||
end | ||
end | ||
end |
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
Oops, something went wrong.