New Jenkins file for CORD/Seba release

Change-Id: I3dc49cdd00f23c9b8ffd0aea742e4656f507ef49
diff --git a/Jenkinsfile-attworkflow-build-released-ver b/Jenkinsfile-attworkflow-build-released-ver
new file mode 100644
index 0000000..205a90f
--- /dev/null
+++ b/Jenkinsfile-attworkflow-build-released-ver
@@ -0,0 +1,264 @@
+// 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}") {
+    timeout (100) {
+        try {
+            stage ("Parse deployment configuration file") {
+                sh returnStdout: true, script: "rm -rf ${configBaseDir}"
+                sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
+                deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
+            }
+            stage('Clean up') {
+                timeout(10) {
+                    sh returnStdout: true, script: """
+                    rm -rf cord-tester
+                    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
+                        }
+                    }
+                }
+            }
+            stage('Add CORD repository') {
+                sh returnStdout: true, script: """
+                export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                helm repo add cord https://charts.opencord.org
+                helm repo update
+                """
+                timeout(1) {
+                    waitUntil {
+                        cord_repo_present = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        helm repo list | grep cord | wc -l
+                        """
+                        return cord_repo_present.toInteger() == 1
+                    }
+                }
+            }
+            stage('Install CORD Platform') {
+                sh returnStdout: true, script: """
+                export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                helm install -f ../${configBaseDir}/${configKubernetesDir}/${configFileName}.yml -n cord-platform --version 1.0.0 cord/cord-platform
+                """
+                timeout(1) {
+                    waitUntil {
+                        cord_helm_installed = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        helm ls | grep -i cord-platform | wc -l
+                        """
+                        return cord_helm_installed.toInteger() == 1
+                    }
+                }
+            }
+            stage('Install SEBA Profile') {
+                sh returnStdout: true, script: """
+                export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                helm install -f ../${configBaseDir}/${configKubernetesDir}/${configFileName}.yml -n seba --version 1.0.0 cord/seba
+                """
+                timeout(1) {
+                    waitUntil {
+                        seba_helm_installed = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        helm ls | grep -i seba | wc -l
+                        """
+                        return seba_helm_installed.toInteger() == 1
+                    }
+                }
+            }
+            stage('Install ATT workflow') {
+                sh returnStdout: true, script: """
+                export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                helm install -f ../${configBaseDir}/${configKubernetesDir}/${configFileName}.yml -n att-workflow --version 1.0.0 cord/att-workflow
+                """
+                timeout(1) {
+                    waitUntil {
+                        attworkflow_helm_installed = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        helm ls | grep -i att-workflow | wc -l
+                        """
+                        return attworkflow_helm_installed.toInteger() == 1
+                    }
+                }
+            }
+            stage('Check containers are running') {
+                timeout(20) {
+                    waitUntil {
+                        pods_running = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        kubectl get pods | grep -i running | wc -l
+                        """
+                        return pods_running.toInteger() == 42
+                    }
+                    waitUntil {
+                        pods_completed = sh returnStdout: true, script: """
+                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                        kubectl get pods | grep -i completed | wc -l
+                        """
+                        return pods_completed.toInteger() == 3
+                    }
+                }
+            }
+            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 --remove asfvolt16 && dpkg --purge asfvolt16'
+                        """
+                        timeout(5) {
+                            waitUntil {
+                                olt_sw_present = sh returnStdout: true, script: """
+                                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'
+                                """
+                                return olt_sw_present.toInteger() == 0
+                            }
+                        }
+                        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}"
+                        """
+                        timeout(5) {
+                            waitUntil {
+                                olt_sw_present = sh returnStdout: true, script: """
+                                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'
+                                """
+                                return olt_sw_present.toInteger() == 1
+                            }
+                        }
+                        // If the OLT is connected to a 40G switch interface, set the NNI port to be downgraded
+                        if ("${deployment_config.olts[i].fortygig}" != null && "${deployment_config.olts[i].fortygig}" == 'true') {
+                            sh returnStdout: true, script: """
+                            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'
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} '/opt/bcm68620/svk_init.sh'
+                            """
+                        }
+                    }
+                }
+                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} 'service bal_core_dist stop' || true
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'service openolt stop' || true
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} '> /var/log/bal_core_dist.log'
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} '> /var/log/openolt.log'
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'service bal_core_dist start &'
+                            sleep 5
+                            sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'service openolt start &'
+                            """
+                        }
+                        timeout(15) {
+                            waitUntil {
+                                onu_discovered = sh returnStdout: true, script: "sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'cat /var/log/openolt.log | grep \"oper_state: up\" | wc -l'"
+                                return onu_discovered.toInteger() > 0
+                            }
+                        }
+                    }
+                }
+            }
+            if ( params.configurePod ) {
+                dir ("${configBaseDir}/${configToscaDir}/att-workflow") {
+                    stage('Configure R-CORD - Fabric and whitelist') {
+                        timeout(1) {
+                            waitUntil {
+                                out_fabric = sh returnStdout: true, script: """
+                                curl -s -H "xos-username:admin@opencord.org" -H "xos-password:letmein" -X POST --data-binary @${configFileName}-fabric.yaml http://${deployment_config.nodes[0].ip}:30007/run | grep -i "created models" | wc -l
+                                """
+                                return out_fabric.toInteger() == 1
+                            }
+                        }
+                    }
+                    stage('Configure R-CORD - Subscriber') {
+                        timeout(1) {
+                            waitUntil {
+                                out_subscriber = sh returnStdout: true, script: """
+                                curl -s -H 'xos-username:admin@opencord.org' -H 'xos-password:letmein' -X POST --data-binary @${configFileName}-subscriber.yaml http://${deployment_config.nodes[0].ip}:30007/run | grep -i "created models" | wc -l
+                                """
+                                return out_subscriber.toInteger() == 1
+                            }
+                        }
+                    }
+                    stage('Configure R-CORD - OLT') {
+                        timeout(1) {
+                            waitUntil {
+                                out_olt = sh returnStdout: true, script: """
+                                curl -H 'xos-username:admin@opencord.org' -H 'xos-password:letmein' -X POST --data-binary @${configFileName}-olt.yaml http://${deployment_config.nodes[0].ip}:30007/run | grep -i "created models" | wc -l
+                                """
+                                return out_olt.toInteger() == 1
+                            }
+                        }
+                    }
+                }
+            }
+            if ( params.installBBSim ) {
+                dir ("helm-charts") {
+                    stage('Install BBSim') {
+                        timeout(10) {
+                            sh returnStdout: true, script: """
+                            export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                            helm install -f ../${configBaseDir}/${configKubernetesDir}/${configFileName}.yml -n bbsim bbsim --set onus_per_pon_port=${onuNumber}
+                            """
+                        }
+                        timeout(10) {
+                            waitUntil {
+                                base_kubernetes_tosca_running = sh returnStdout: true, script: """
+                                export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf &&
+                                kubectl get pods -n voltha | grep -i bbsim | wc -l
+                                """
+                                return base_kubernetes_tosca_running.toInteger() == 1
+                            }
+                        }
+                    }
+                }
+                dir ("${configBaseDir}/${configToscaDir}/bbsim") {
+                    stage('Configure BBSim - OLT') {
+                        timeout(1) {
+                            waitUntil {
+                                out_olt = sh returnStdout: true, script: """
+                                curl -H 'xos-username:admin@opencord.org' -H 'xos-password:letmein' -X POST --data-binary @bbsim-16.yaml http://${deployment_config.nodes[0].ip}:30007/run | grep -i "created models" | wc -l
+                                """
+                                return out_olt.toInteger() == 1
+                            }
+                        }
+                    }
+                }
+            }
+            currentBuild.result = 'SUCCESS'
+        } catch (err) {
+            currentBuild.result = 'FAILURE'
+            step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
+        }
+        echo "RESULT: ${currentBuild.result}"
+    }
+}