
/**
 *  Test salt models pipeline
 *  DEFAULT_GIT_REF
 *  DEFAULT_GIT_URL
 *  CREDENTIALS_ID
 *  EXTRA_FORMULAS
 *  CLUSTER_NAME
 *  NODE_TARGET
 *  SYSTEM_GIT_URL
 *  SYSTEM_GIT_REF
 *  FORMULAS_SOURCE
 *  RECLASS_VERSION
 *  MAX_CPU_PER_JOB
 *  LEGACY_TEST_MODE
 *  RECLASS_IGNORE_CLASS_NOTFOUND
 *  APT_REPOSITORY
 *  APT_REPOSITORY_GPG
 */

def common = new com.mirantis.mk.Common()
def gerrit = new com.mirantis.mk.Gerrit()
def git = new com.mirantis.mk.Git()
def ssh = new com.mirantis.mk.Ssh()
def saltModelTesting = new com.mirantis.mk.SaltModelTesting()

def defaultGitRef = DEFAULT_GIT_REF
def defaultGitUrl = DEFAULT_GIT_URL

def checkouted = false

def reclassVersion = 'v1.5.4'
if (common.validInputParam('RECLASS_VERSION')) {
  reclassVersion = RECLASS_VERSION
}

throttle(['test-model']) {
  timeout(time: 1, unit: 'HOURS') {
    node("python&&docker") {
      try{
        stage("checkout") {
          if(defaultGitRef != "" && defaultGitUrl != "") {
              checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
          } else {
            throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
          }
          if(checkouted) {
            if (fileExists('classes/system')) {
              if (SYSTEM_GIT_URL == "") {
                ssh.prepareSshAgentKey(CREDENTIALS_ID)
                dir('classes/system') {
                  remoteUrl = git.getGitRemote()
                  ssh.ensureKnownHosts(remoteUrl)
                }
                ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
              } else {
                dir('classes/system') {
                  if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
                    common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
                  }
                }
              }
            }
          }
        }

        stage("test node") {
          if (checkouted) {
            def workspace = common.getWorkspace()
            def testResult = false
            common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
            try {
              def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
              testResult = saltModelTesting.setupAndTestNode(
                  NODE_TARGET,
                  CLUSTER_NAME,
                  EXTRA_FORMULAS,
                  workspace,
                  FORMULAS_SOURCE,
                  FORMULAS_REVISION,
                  reclassVersion,
                  MAX_CPU_PER_JOB.toInteger(),
                  RECLASS_IGNORE_CLASS_NOTFOUND,
                  LEGACY_TEST_MODE,
                  APT_REPOSITORY,
                  APT_REPOSITORY_GPG,
                  DockerCName)
            } catch (Exception e) {
              if (e.getMessage() == "script returned exit code 124") {
                common.errorMsg("Impossible to test node due to timeout of salt-master, ABORTING BUILD")
                currentBuild.result = "ABORTED"
              } else {
                throw e
              }
            }
            if (testResult) {
              common.infoMsg("Test finished: SUCCESS")
            } else {
              error('Test node finished: FAILURE')
              throw new RuntimeException('Test node stage finished: FAILURE')
            }
          }
        }
      } catch (Throwable e) {
        // If there was an error or exception thrown, the build failed
        currentBuild.result = "FAILURE"
        currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
        throw e
      }
    }
  }
}
