Skip to content

Commit fadc2aa

Browse files
authored
Merge pull request #355 from rundeck-plugins/add-plugin-group
add plugin group
2 parents 366b40f + c86b7ad commit fadc2aa

20 files changed

+700
-226
lines changed

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ ext.pluginClassNames = [
1515
'com.rundeck.plugins.ansible.plugin.AnsibleModuleWorkflowStep',
1616
'com.rundeck.plugins.ansible.plugin.AnsiblePlaybookWorflowNodeStep',
1717
'com.rundeck.plugins.ansible.plugin.AnsiblePlaybookInlineWorkflowNodeStep',
18-
'com.rundeck.plugins.ansible.logging.AnsibleSetStatsFilterPlugin'
18+
'com.rundeck.plugins.ansible.logging.AnsibleSetStatsFilterPlugin',
19+
'com.rundeck.plugins.ansible.plugin.AnsiblePluginGroup'
1920
].join(',')
2021

2122
apply plugin: 'java'

functional-test/src/test/groovy/functional/BasicIntegrationSpec.groovy

+4-67
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
package functional
22

3+
import functional.base.BaseTestConfiguration
34
import functional.util.TestUtil
4-
import org.rundeck.client.api.RundeckApi
5-
import org.rundeck.client.api.model.ExecLog
6-
import org.rundeck.client.api.model.ExecOutput
7-
import org.rundeck.client.api.model.ExecutionStateResponse
85
import org.rundeck.client.api.model.JobRun
9-
import org.rundeck.client.util.Client
10-
import spock.lang.Shared
11-
import spock.lang.Specification
126
import org.testcontainers.spock.Testcontainers
137

148

159
@Testcontainers
16-
class BasicIntegrationSpec extends Specification {
17-
18-
@Shared
19-
public static RundeckCompose rundeckEnvironment = new RundeckCompose(new File("src/test/resources/docker/docker-compose.yml").toURI())
20-
21-
@Shared
22-
Client<RundeckApi> client
10+
class BasicIntegrationSpec extends BaseTestConfiguration {
2311

2412
static String PROJ_NAME = 'ansible-test'
2513

2614
def setupSpec() {
27-
rundeckEnvironment.startCompose()
28-
client = rundeckEnvironment.configureRundeck(PROJ_NAME)
15+
startCompose()
16+
configureRundeck(PROJ_NAME)
2917
}
3018

3119
def "test simple inline playbook"(){
@@ -270,55 +258,4 @@ class BasicIntegrationSpec extends Specification {
270258
logs.findAll {it.log.contains("\"token\": 13231232312321321321321")}.size() == 1
271259
}
272260

273-
ExecutionStateResponse waitForJob(String executionId){
274-
def finalStatus = [
275-
'aborted',
276-
'failed',
277-
'succeeded',
278-
'timedout',
279-
'other'
280-
]
281-
282-
while(true) {
283-
ExecutionStateResponse result=client.apiCall { api-> api.getExecutionState(executionId)}
284-
if (finalStatus.contains(result?.getExecutionState()?.toLowerCase())) {
285-
return result
286-
} else {
287-
sleep (10000)
288-
}
289-
}
290-
291-
}
292-
293-
294-
List<ExecLog> getLogs(String executionId){
295-
def offset = 0
296-
def maxLines = 1000
297-
def lastmod = 0
298-
boolean isCompleted = false
299-
300-
List<ExecLog> logs = []
301-
302-
while (!isCompleted){
303-
ExecOutput result = client.apiCall { api -> api.getOutput(executionId, offset,lastmod, maxLines)}
304-
isCompleted = result.completed
305-
offset = result.offset
306-
lastmod = result.lastModified
307-
308-
logs.addAll(result.entries)
309-
310-
if(result.unmodified){
311-
sleep(5000)
312-
}else{
313-
sleep(2000)
314-
}
315-
}
316-
317-
return logs
318-
}
319-
320-
321-
322-
323-
324261
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package functional
2+
3+
import functional.base.BaseTestConfiguration
4+
import functional.util.TestUtil
5+
import org.rundeck.client.api.model.JobRun
6+
import org.testcontainers.spock.Testcontainers
7+
8+
9+
@Testcontainers
10+
class PluginGroupIntegrationSpec extends BaseTestConfiguration {
11+
12+
static String PROJ_NAME = 'ansible-plugin-group-test'
13+
14+
def setupSpec() {
15+
startCompose()
16+
configureRundeck(PROJ_NAME)
17+
}
18+
19+
def "test simple inline playbook"(){
20+
when:
21+
22+
def jobId = "fa0e401b-b5a8-436a-b13b-0e8092858021"
23+
24+
JobRun request = new JobRun()
25+
request.loglevel = 'DEBUG'
26+
27+
def result = client.apiCall {api-> api.runJob(jobId, request)}
28+
def executionId = result.id
29+
30+
def executionState = waitForJob(executionId)
31+
32+
def logs = getLogs(executionId)
33+
Map<String, Integer> ansibleNodeExecutionStatus = TestUtil.getAnsibleNodeResult(logs)
34+
35+
then:
36+
executionState!=null
37+
executionState.getExecutionState()=="SUCCEEDED"
38+
ansibleNodeExecutionStatus.get("ok")!=0
39+
ansibleNodeExecutionStatus.get("unreachable")==0
40+
ansibleNodeExecutionStatus.get("failed")==0
41+
ansibleNodeExecutionStatus.get("skipped")==0
42+
ansibleNodeExecutionStatus.get("ignored")==0
43+
44+
logs.findAll {it.log.contains("plugin group set getAnsibleConfigFilePath: /home/rundeck/ansible")}.size() == 1
45+
logs.findAll {it.log.contains("ANSIBLE_CONFIG: /home/rundeck/ansible")}.size() == 1
46+
47+
}
48+
49+
def "test simple inline playbook with env vars"(){
50+
when:
51+
52+
def jobId = "572367d2-e41a-4fdb-b6fc-effa32185b61"
53+
54+
JobRun request = new JobRun()
55+
request.loglevel = 'DEBUG'
56+
57+
def result = client.apiCall {api-> api.runJob(jobId, request)}
58+
def executionId = result.id
59+
60+
def executionState = waitForJob(executionId)
61+
62+
def logs = getLogs(executionId)
63+
Map<String, Integer> ansibleNodeExecutionStatus = TestUtil.getAnsibleNodeResult(logs)
64+
65+
then:
66+
executionState!=null
67+
executionState.getExecutionState()=="SUCCEEDED"
68+
ansibleNodeExecutionStatus.get("ok")!=0
69+
ansibleNodeExecutionStatus.get("unreachable")==0
70+
ansibleNodeExecutionStatus.get("failed")==0
71+
ansibleNodeExecutionStatus.get("skipped")==0
72+
ansibleNodeExecutionStatus.get("ignored")==0
73+
logs.findAll {it.log.contains("plugin group set getAnsibleConfigFilePath: /home/rundeck/ansible")}.size() == 1
74+
logs.findAll {it.log.contains("plugin group set getEncryptExtraVars: true")}.size() == 1
75+
logs.findAll {it.log.contains("ANSIBLE_CONFIG: /home/rundeck/ansible")}.size() == 1
76+
logs.findAll {it.log.contains("encryptVariable password")}.size() == 1
77+
logs.findAll {it.log.contains("encryptVariable username")}.size() == 1
78+
logs.findAll {it.log.contains("\"msg\": \"rundeck\"")}.size() == 1
79+
logs.findAll {it.log.contains("\"msg\": \"demo\"")}.size() == 1
80+
81+
}
82+
83+
}

functional-test/src/test/groovy/functional/RundeckCompose.groovy

-144
This file was deleted.

0 commit comments

Comments
 (0)