// Copyright 2017-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

node ("${TestNodeName}") {
    def withKind = false
    if (params.withKind != null){
        withKind = params.withKind
    }
    def tech_prof_directory = "XGS_PON"
    if (params.oltDebVersion.contains("asgvolt64")){
        tech_prof_directory = "GPON"
    }
    timeout (100) {
        try {
            stage ("Parse deployment configuration file") {
                sh returnStdout: true, script: "rm -rf ${configBaseDir} voltha-system-tests kind-voltha"
                sh returnStdout: true, script: "git clone -b master ${cordRepoUrl}/${configBaseDir}"
                sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/voltha-system-tests"
                sh returnStdout: true, script: "git clone -b master ${cordRepoUrl}/kind-voltha"
                if ( params.workFlow == "DT" ) {
                    deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
                }
                else
                {
                    deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
                }
            }
            stage('Clean up') {
                timeout(10) {
                    sh returnStdout: true, script: """
                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
                    for hchart in \$(helm list -q | grep -E -v 'docker-registry|mavenrepo|ponnet');
                    do
                        echo "Purging chart: \${hchart}"
                        helm delete --purge "\${hchart}"
                    done
                    """
                    timeout(5) {
                        waitUntil {
                            helm_deleted = sh returnStdout: true, script: """
                            export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
                            helm ls -q | grep -E -v 'docker-registry|mavenrepo|ponnet' | wc -l
                            """
                            return helm_deleted.toInteger() == 0
                        }
                    }
                    timeout(5) {
                        waitUntil {
                            kubectl_deleted = sh returnStdout: true, script: """
                            export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
                            kubectl get pods --all-namespaces --no-headers | grep -E -v 'kube-system|docker-registry|mavenrepo|ponnet' | wc -l
                            """
                            return kubectl_deleted.toInteger() == 0
                        }
                    }
                    timeout(1) {
                        sh returnStdout: false, script: """
                        #Remove all while true; do kubectl port-forward ...done; rules
                        for port_fwd_id in `ps -ax | grep "port-forward" | grep -E "onos|voltha" | grep "while true"| awk '{print \$1}'`;
                        do
                            cat /proc/\$port_fwd_id/cmdline
                            kill -9 \$port_fwd_id
                        done

                        #Remove all kubectl port-forward rules
                        for port_fwd_id in `ps -ax | grep "port-forward" | grep -E "onos|voltha" | awk '{print \$1}'`;
                        do
                            cat /proc/\$port_fwd_id/cmdline
                            kill -9 \$port_fwd_id
                        done
                        """
                    }
                }
            }
            stage('Install Voltha')  {
                timeout(10) {
                    sh returnStdout: true, script: """
                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
                    cd kind-voltha/
                    if [ "${branch}" != "master" ]; then
                        cd $WORKSPACE/kind-voltha
                        source releases/${branch}
                    else
                        export EXTRA_HELM_FLAGS='-f $WORKSPACE/${configBaseDir}/${configKubernetesDir}/voltha/${configFileName}.yml'
                    fi

                    # VOL-2194 ONOS SSH and REST ports hardcoded to 30115/30120 in tests
                    # JENKINS_NODE_COOKIE=dontKillMe ask Jenkins doesn't kill the proces after this job. we want the `while true; do kubectl port-forward` keep alive
                    if [[ "${workFlow}" == "DT" ]]; then
                       JENKINS_NODE_COOKIE=dontKillMe ONOS_SSH_PORT=30115 ONOS_API_PORT=30120 VOLTHA_LOG_LEVEL=DEBUG WITH_SIM_ADAPTERS=n WITH_TP=yes DEPLOY_K8S=no INSTALL_KUBECTL=no INSTALL_HELM=no WITH_EAPOL=no WITH_DHCP=no WITH_IGMP=no WITH_RADIUS=no FANCY=0 ./voltha up
                    else
                       JENKINS_NODE_COOKIE=dontKillMe ONOS_SSH_PORT=30115 ONOS_API_PORT=30120 VOLTHA_LOG_LEVEL=DEBUG WITH_SIM_ADAPTERS=n WITH_RADIUS=y WITH_TP=yes DEPLOY_K8S=no INSTALL_KUBECTL=no INSTALL_HELM=no FANCY=0 ./voltha up
                    fi

                    kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\t'}{.imageID}{'\\n'}" | sort | uniq -c
                    kubectl get nodes -o wide
                    kubectl get pods -n voltha -o wide
                    """
                    }
            }
            if ( withKind && deployment_config.fabric_switches.size() > 0 ) {
                stage('OpenFlow port forward for aggregation switch') {
                    timeout(1) {
                        sh returnStdout: true, script: """
                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
                        #This uses the default route out, porperly configured is the management
                        mgmt_address=`ip route get 1 | awk '{print \$NF;exit}'`
                        JENKINS_NODE_COOKIE=dontkill kubectl port-forward -n default service/onos-openflow --address=\$mgmt_address 6653:6653 >> /dev/null 2>&1 &
                        """
                    }
                }
            }
            if ( params.configurePod && params.profile != "Default" ) {
                stage('Push Tech-Profile') {
                    timeout(1) {
                        out_push_tp = sh returnStatus: true, script: """
                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
                        etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
                        kubectl cp $WORKSPACE/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
                        put_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'cat /tmp/flexpod.json | ETCDCTL_API=3 etcdctl put service/voltha/technology_profiles/${tech_prof_directory}/64')
                        """
                        return out_push_tp == 0
                    }
                    timeout(1) {
                        out_get_tp = sh returnStatus: true, script: """
                        etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
                        get_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/technology_profiles/${tech_prof_directory}/64')
                        """
                        return out_get_tp == 0
                    }
                }
            }
            stage('Push Sadis-config') {
                timeout(1) {
                    sadis_out = sh returnStatus: true, script: """
                    if [[ "${workFlow}" == "DT" ]]; then
                        curl -sSL --user karaf:karaf -X POST -H Content-Type:application/json http://${deployment_config.nodes[0].ip}:30120/onos/v1/network/configuration --data @$WORKSPACE/voltha-system-tests/tests/data/${configFileName}-sadis-DT.json
                    else
                        curl -sSL --user karaf:karaf -X POST -H Content-Type:application/json http://${deployment_config.nodes[0].ip}:30120/onos/v1/network/configuration --data @$WORKSPACE/voltha-system-tests/tests/data/${configFileName}-sadis.json
                    fi
                    """
                    return sadis_out == 0
                }
            }
            if ( params.reinstallOlt ) {
                stage('Reinstall OLT software') {
                    for(int i=0; i < deployment_config.olts.size(); i++) {
                        sh returnStdout: true, script: """
                        sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} "dpkg --install ${oltDebVersion}"
                        sleep 10
                        """
                        timeout(5) {
                            waitUntil {
                                olt_sw_present = sh returnStdout: true, script: """
                                if [[ "${oltDebVersion}" == *"asfvolt16"* ]]; then
                                    sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'dpkg --list | grep asfvolt16 | wc -l'
                                else
                                    sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'dpkg --list | grep asgvolt64 | wc -l'
                                fi
                                if ( ${deployment_config.olts[i].fortygig} ); then
                                    sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'echo "port ce128 sp=40000" >> /broadcom/qax.soc'
                                fi
                                """
                                return olt_sw_present.toInteger() > 0
                            }
                        }
                    }
                }
               stage('Restart OLT processes') {
                    for(int i=0; i < deployment_config.olts.size(); i++) {
                        timeout(5) {
                            sh returnStdout: true, script: """
                            ssh-keyscan -H ${deployment_config.olts[i].ip} >> ~/.ssh/known_hosts
                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'reboot' || true
                            sleep 120
                            """
                        }
                        timeout(15) {
                            waitUntil {
                                devprocess = sh returnStdout: true, script: "sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'ps -ef | grep dev_mgmt_daemon | wc -l'"
                                return devprocess.toInteger() > 0
                            }
                        }
                        timeout(15) {
                            waitUntil {
                                openoltprocess = sh returnStdout: true, script: "sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'ps -ef | grep openolt | wc -l'"
                                return openoltprocess.toInteger() > 0
                            }
                        }
                    }
                }
            }
            if ( deployment_config.fabric_switches.size() > 0 ) {
                stage('Switch Configurations in ONOS') {
                    timeout(1) {
                        netcfg_out = sh returnStatus: true, script: """
                        curl -sSL --user karaf:karaf -X POST -H Content-Type:application/json http://${deployment_config.nodes[0].ip}:30120/onos/v1/network/configuration --data @$WORKSPACE/${configBaseDir}/${configToscaDir}/voltha/${configFileName}-onos-netcfg-switch.json
                        curl -sSL --user karaf:karaf -X POST http://${deployment_config.nodes[0].ip}:30120/onos/v1/applications/org.onosproject.segmentrouting/active

                        """
                        return netcfg_out == 0
                    }
                    timeout(1) {
                        waitUntil {
                            sr_active_out = sh returnStatus: true, script: """
                            ssh-keygen -R [${deployment_config.nodes[0].ip}]:30115
                            ssh-keyscan -p 30115 -H ${deployment_config.nodes[0].ip} >> ~/.ssh/known_hosts
                            sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.dhcpl2relay"
                            sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.aaa"
                            sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "log:set TRACE org.opencord.olt"
                            curl -sSL --user karaf:karaf -X GET http://${deployment_config.nodes[0].ip}:30120/onos/v1/applications/org.onosproject.segmentrouting | jq '.state' | grep ACTIVE
                            sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "cfg set org.onosproject.net.flow.impl.FlowRuleManager purgeOnDisconnection false"
                            sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "cfg set org.onosproject.net.meter.impl.MeterManager purgeOnDisconnection false"
                            """
                            return sr_active_out == 0
                        }
                    }
                    timeout(1) {
                        // FIXME support multiple OLTs
                        for(int i=0; i < deployment_config.hosts.src.size(); i++) {
                            xconnect_out = sh returnStatus: true, script: """
                            version=\$(sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "summary" | grep version)
                            sleep 10
                            if [[ \$version == *"version=2.2"* ]]; then
                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "endpoints": [${deployment_config.fabric_switches[0].bngPort},${deployment_config.fabric_switches[0].oltPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
                            else
                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "ports": [${deployment_config.fabric_switches[0].bngPort},${deployment_config.fabric_switches[0].oltPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
                            fi
                            """
                        }
                    }
                }
            }
            currentBuild.result = 'SUCCESS'
        } catch (err) {
            currentBuild.result = 'FAILURE'
            step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
            throw err
        }
        echo "RESULT: ${currentBuild.result}"
    }
}
