Skip to content

Commit

Permalink
Merge pull request #343 from rundeck-plugins/rse808-error-handler-not…
Browse files Browse the repository at this point in the history
…triggered-on-ansible-inlineplaybookstep

RSE-824: Fix: Error handler not working as expected with Ansible Node Step
  • Loading branch information
ltamaster authored Oct 19, 2023
2 parents f636c70 + c76ee04 commit 7fd1cb2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ dependencies {
pluginLibs 'com.google.code.gson:gson:2.10.1'
implementation('org.rundeck:rundeck-core:4.16.0-rc1-20230815')
implementation 'org.codehaus.groovy:groovy-all:3.0.9'

testImplementation platform("org.spockframework:spock-bom:2.0-groovy-3.0")
testImplementation "org.spockframework:spock-core"
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

task copyToLib(type: Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public void executeNodeStep(
configuration.put(AnsibleDescribable.ANSIBLE_DEBUG,"False");
}

AnsibleRunnerBuilder
builder = new AnsibleRunnerBuilder(context.getExecutionContext(), context.getFramework(), context.getNodes(), configuration);
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context.getExecutionContext(), context.getFramework(), context.getNodes(), configuration);

try {
runner = builder.buildAnsibleRunner();
Expand All @@ -96,12 +95,12 @@ public void executeNodeStep(
} catch (AnsibleException e) {
Map<String,Object> failureData = new HashMap<>();
failureData.put("message",e.getMessage());
failureData.put("ansible-config", builder.getConfigFile());
failureData.put("ansible-config", configuration);
throw new NodeStepException(e.getMessage(), e, e.getFailureReason(), failureData, e.getMessage());
} catch (Exception e) {
Map<String,Object> failureData = new HashMap<>();
failureData.put("message",e.getMessage());
failureData.put("ansible-config", builder.getConfigFile());
failureData.put("ansible-config", configuration);
throw new NodeStepException(e.getMessage(),e, AnsibleException.AnsibleFailureReason.AnsibleError, failureData, e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.rundeck.plugins.ansible.plugin

import com.dtolabs.rundeck.core.common.Framework
import com.dtolabs.rundeck.core.common.INodeEntry
import com.dtolabs.rundeck.core.common.INodeSet
import com.dtolabs.rundeck.core.execution.ExecutionContext
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException
import com.dtolabs.rundeck.plugins.step.NodeStepPlugin
import com.dtolabs.rundeck.plugins.step.PluginStepContext
import org.junit.jupiter.api.Assertions
import spock.lang.Specification


class AnsiblePlaybookInlineWorkflowNodeStepSpec extends Specification{

void "failure data should not include null values when throwing"(){
given:
NodeStepPlugin plugin = new AnsiblePlaybookInlineWorkflowNodeStep()
INodeEntry node = Mock(INodeEntry){
getNodename() >> 'localhost'
}

PluginStepContext context = Mock(PluginStepContext){
getDataContext() >> ['job': ['loglevel':'INFO']]
getExecutionContext() >> Mock(ExecutionContext){
getDataContext() >> [:]
}
getFramework() >> Mock(Framework)
getNodes() >> Mock(INodeSet){
getNodes() >> []
}
}

Map<String, Object> configuration = [
'ansible-playbook' : 'path/to/playbook'
]

when:
plugin.executeNodeStep(context, configuration, node)

then:
NodeStepException e = thrown(NodeStepException)
e.getFailureData().each { String key, Object value ->
Assertions.assertNotNull(value, "Value for key ${key} should not be null")
}
}
}

0 comments on commit 7fd1cb2

Please sign in to comment.