Skip to content

Commit

Permalink
Merge pull request #355 from rundeck-plugins/add-plugin-group
Browse files Browse the repository at this point in the history
add plugin group
  • Loading branch information
ltamaster authored Apr 1, 2024
2 parents 366b40f + c86b7ad commit fadc2aa
Show file tree
Hide file tree
Showing 20 changed files with 700 additions and 226 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ ext.pluginClassNames = [
'com.rundeck.plugins.ansible.plugin.AnsibleModuleWorkflowStep',
'com.rundeck.plugins.ansible.plugin.AnsiblePlaybookWorflowNodeStep',
'com.rundeck.plugins.ansible.plugin.AnsiblePlaybookInlineWorkflowNodeStep',
'com.rundeck.plugins.ansible.logging.AnsibleSetStatsFilterPlugin'
'com.rundeck.plugins.ansible.logging.AnsibleSetStatsFilterPlugin',
'com.rundeck.plugins.ansible.plugin.AnsiblePluginGroup'
].join(',')

apply plugin: 'java'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
package functional

import functional.base.BaseTestConfiguration
import functional.util.TestUtil
import org.rundeck.client.api.RundeckApi
import org.rundeck.client.api.model.ExecLog
import org.rundeck.client.api.model.ExecOutput
import org.rundeck.client.api.model.ExecutionStateResponse
import org.rundeck.client.api.model.JobRun
import org.rundeck.client.util.Client
import spock.lang.Shared
import spock.lang.Specification
import org.testcontainers.spock.Testcontainers


@Testcontainers
class BasicIntegrationSpec extends Specification {

@Shared
public static RundeckCompose rundeckEnvironment = new RundeckCompose(new File("src/test/resources/docker/docker-compose.yml").toURI())

@Shared
Client<RundeckApi> client
class BasicIntegrationSpec extends BaseTestConfiguration {

static String PROJ_NAME = 'ansible-test'

def setupSpec() {
rundeckEnvironment.startCompose()
client = rundeckEnvironment.configureRundeck(PROJ_NAME)
startCompose()
configureRundeck(PROJ_NAME)
}

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

ExecutionStateResponse waitForJob(String executionId){
def finalStatus = [
'aborted',
'failed',
'succeeded',
'timedout',
'other'
]

while(true) {
ExecutionStateResponse result=client.apiCall { api-> api.getExecutionState(executionId)}
if (finalStatus.contains(result?.getExecutionState()?.toLowerCase())) {
return result
} else {
sleep (10000)
}
}

}


List<ExecLog> getLogs(String executionId){
def offset = 0
def maxLines = 1000
def lastmod = 0
boolean isCompleted = false

List<ExecLog> logs = []

while (!isCompleted){
ExecOutput result = client.apiCall { api -> api.getOutput(executionId, offset,lastmod, maxLines)}
isCompleted = result.completed
offset = result.offset
lastmod = result.lastModified

logs.addAll(result.entries)

if(result.unmodified){
sleep(5000)
}else{
sleep(2000)
}
}

return logs
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package functional

import functional.base.BaseTestConfiguration
import functional.util.TestUtil
import org.rundeck.client.api.model.JobRun
import org.testcontainers.spock.Testcontainers


@Testcontainers
class PluginGroupIntegrationSpec extends BaseTestConfiguration {

static String PROJ_NAME = 'ansible-plugin-group-test'

def setupSpec() {
startCompose()
configureRundeck(PROJ_NAME)
}

def "test simple inline playbook"(){
when:

def jobId = "fa0e401b-b5a8-436a-b13b-0e8092858021"

JobRun request = new JobRun()
request.loglevel = 'DEBUG'

def result = client.apiCall {api-> api.runJob(jobId, request)}
def executionId = result.id

def executionState = waitForJob(executionId)

def logs = getLogs(executionId)
Map<String, Integer> ansibleNodeExecutionStatus = TestUtil.getAnsibleNodeResult(logs)

then:
executionState!=null
executionState.getExecutionState()=="SUCCEEDED"
ansibleNodeExecutionStatus.get("ok")!=0
ansibleNodeExecutionStatus.get("unreachable")==0
ansibleNodeExecutionStatus.get("failed")==0
ansibleNodeExecutionStatus.get("skipped")==0
ansibleNodeExecutionStatus.get("ignored")==0

logs.findAll {it.log.contains("plugin group set getAnsibleConfigFilePath: /home/rundeck/ansible")}.size() == 1
logs.findAll {it.log.contains("ANSIBLE_CONFIG: /home/rundeck/ansible")}.size() == 1

}

def "test simple inline playbook with env vars"(){
when:

def jobId = "572367d2-e41a-4fdb-b6fc-effa32185b61"

JobRun request = new JobRun()
request.loglevel = 'DEBUG'

def result = client.apiCall {api-> api.runJob(jobId, request)}
def executionId = result.id

def executionState = waitForJob(executionId)

def logs = getLogs(executionId)
Map<String, Integer> ansibleNodeExecutionStatus = TestUtil.getAnsibleNodeResult(logs)

then:
executionState!=null
executionState.getExecutionState()=="SUCCEEDED"
ansibleNodeExecutionStatus.get("ok")!=0
ansibleNodeExecutionStatus.get("unreachable")==0
ansibleNodeExecutionStatus.get("failed")==0
ansibleNodeExecutionStatus.get("skipped")==0
ansibleNodeExecutionStatus.get("ignored")==0
logs.findAll {it.log.contains("plugin group set getAnsibleConfigFilePath: /home/rundeck/ansible")}.size() == 1
logs.findAll {it.log.contains("plugin group set getEncryptExtraVars: true")}.size() == 1
logs.findAll {it.log.contains("ANSIBLE_CONFIG: /home/rundeck/ansible")}.size() == 1
logs.findAll {it.log.contains("encryptVariable password")}.size() == 1
logs.findAll {it.log.contains("encryptVariable username")}.size() == 1
logs.findAll {it.log.contains("\"msg\": \"rundeck\"")}.size() == 1
logs.findAll {it.log.contains("\"msg\": \"demo\"")}.size() == 1

}

}
144 changes: 0 additions & 144 deletions functional-test/src/test/groovy/functional/RundeckCompose.groovy

This file was deleted.

Loading

0 comments on commit fadc2aa

Please sign in to comment.