/**
 * Update packages on given nodes
 *
 * Expected parameters:
 *   SALT_MASTER_CREDENTIALS    Credentials to the Salt API.
 *   SALT_MASTER_URL            Full Salt API address [https://10.10.10.1:8000].
 *   TARGET_SERVERS             Salt compound target to match nodes to be updated [*, G@osfamily:debian].
 *
**/

def common = new com.mirantis.mk.Common()
def salt = new com.mirantis.mk.Salt()

def saltMaster
def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
def minions
def result
def command
def commandKwargs


node() {
    try {

        stage('Connect to Salt master') {
            saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
        }

        stage('List target servers') {
            minions = salt.getMinions(saltMaster, targetAll)

            if (minions.isEmpty()) {
                throw new Exception("No minion was targeted")
            }

            targetLiveAll = minions.join(' or ')
            common.infoMsg("Found nodes: ${targetLiveAll}")
            common.infoMsg("Selected nodes: ${targetLiveAll}")
        }

        stage("Setup network for compute") {
            common.infoMsg("Now all network configuration will be enforced, which caused reboot of nodes: ${targetLiveAll}")
            try {
                salt.cmdRun(saltMaster, targetLiveAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot')
            } catch(e) {
                common.infoMsg("no respond from nodes due reboot")
            }
            common.infoMsg("Now pipeline is waiting until node reconnect to salt master")
            timeout(800) {
                retry(666) {
                    try {
                        salt.runSaltCommand(saltMaster, 'local', targetLiveAll, 'test.ping', null, null, kwargs)
                    } catch(e) {
                        common.infoMsg("Still waiting for node to come up")
                        sleep(10)
                    }
                }
            }
        }

        stage("Deploy Compute") {
            common.infoMsg("Lets run rest of the states to finish deployment")
            salt.enforceState(saltMaster, targetLiveAll, 'linux,openssh,ntp,salt', true)
            retry(2) {
                salt.runSaltCommand(saltMaster, 'local', targetLiveAll, 'state.apply', null, null, kwargs)
            }
        }

    } catch (Throwable e) {
        // If there was an error or exception thrown, the build failed
        currentBuild.result = "FAILURE"
        throw e
    }
}
