splitting attworkflow jenkins files to build/test

Change-Id: Ied3d02116f1f94995848b3037c4fb4f809f83b9f
diff --git a/Jenkinsfile-attworkflow b/Jenkinsfile-attworkflow-build
similarity index 80%
rename from Jenkinsfile-attworkflow
rename to Jenkinsfile-attworkflow-build
index 21c9acf..6bdb2d6 100644
--- a/Jenkinsfile-attworkflow
+++ b/Jenkinsfile-attworkflow-build
@@ -234,68 +234,38 @@
                     }
                 }
             }
-            stage('Download cord-tester repo') {
-                timeout(2) {
-                    sh returnStdout: true, script: """
-                    git clone -b ${branch} ${cordRepoUrl}/cord-tester
-                    """
+            dir ("${configBaseDir}/${configToscaDir}/attworkflow-configs") {
+                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('Validate installed PODs') {
-                timeout(10) {
-                    sh """
-                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
-                    cd $WORKSPACE/cord-tester/src/test/robot/
-                    rm -rf Log/ || true
-                    pybot -d Log -T SanityK8POD.robot || true
-                    """
+                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('Configurations and Tests') {
-                timeout(10) {
-                    sh """
-                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
-                    cd $WORKSPACE/cord-tester/src/test/cord-api/Properties/
-                    sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'${deployment_config.nodes[0].ip}\'/\" RestApiProperties.py
-                    sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'30006\'/\" RestApiProperties.py
-                    sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
-                    sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
-                    cd $WORKSPACE/cord-tester/src/test/cord-api/Tests/
-                    rm -rf Log/ || true
-                    pybot -d Log -T FabricConfig.txt || true
-                    sleep 5
-                    pybot -d Log -T OSSVolt.txt || true
-                    pybot -d Log -T RealOLT_Test.txt || true
-                    """
+                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
+                        }
+                    }
                 }
             }
-            stage('Subscriber Validation and Ping Tests') {
-                timeout(30) {
-                    sh """
-                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
-                    cd $WORKSPACE/cord-tester/src/test/cord-api/Tests/
-                    pybot -d Log -T -v src_ip:${deployment_config.srcHost.ip} -v src_user:${deployment_config.srcHost.user} -v src_pass:${deployment_config.srcHost.pass} -v dst_user:${deployment_config.dstHost.user} -v dst_pass:${deployment_config.dstHost.pass} -v dst_ip:${deployment_config.dstHost.ip} -v dst_host_ip:${deployment_config.dstHost.hostIp} -v src_gateway:${deployment_config.srcHost.gateway} -v dst_gateway:${deployment_config.dstHost.gateway} -v init_state:awaiting-auth -v INITIAL_STATUS:FAIL -v ENABLE_STATUS:FAIL -v MACIP_STATUS:PASS Subscriber_StatusChecks.txt || true
-                    """
-                }
-            }
-            stage('Publish test results') {
-                sh returnStdout: true, script: """
-                if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs;
-                mkdir RobotLogs/TestDoc || true
-                cp -r $WORKSPACE/cord-tester/src/test/robot/Log/* $WORKSPACE/RobotLogs || true
-                cp -r $WORKSPACE/cord-tester/src/test/cord-api/Tests/Log/* $WORKSPACE/RobotLogs || true
-                """
-                step([$class: 'RobotPublisher',
-                    disableArchiveOutput: false,
-                    logFileName: 'RobotLogs/log*.html',
-                    otherFiles: '',
-                    outputFileName: 'RobotLogs/output*.xml',
-                    outputPath: '.',
-                    passThreshold: 100,
-                    reportFileName: 'RobotLogs/report*.html',
-                    unstableThreshold: 0
-                ])
-            }
             currentBuild.result = 'SUCCESS'
         } catch (err) {
             currentBuild.result = 'FAILURE'
diff --git a/Jenkinsfile-attworkflow-test b/Jenkinsfile-attworkflow-test
new file mode 100644
index 0000000..696f9a5
--- /dev/null
+++ b/Jenkinsfile-attworkflow-test
@@ -0,0 +1,78 @@
+// 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}.yml"
+            }
+            stage('Download Cord-Tester Repo') {
+                timeout(2) {
+                    sh returnStdout: true, script: """
+                    git clone -b ${branch} ${cordRepoUrl}/cord-tester
+                    """
+                }
+            }
+            stage('Test Configurations') {
+                timeout(10) {
+                    sh """
+                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                    cd $WORKSPACE/cord-tester/src/test/cord-api/Properties/
+                    sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'${deployment_config.nodes[0].ip}\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'30006\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
+                    cd $WORKSPACE/cord-tester/src/test/cord-api/Tests/
+                    rm -rf Log/ || true
+                    """
+                }
+            }
+            stage('Subscriber Validation and Ping Tests') {
+                timeout(30) {
+                    sh """
+                    export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                    cd $WORKSPACE/cord-tester/src/test/cord-api/Tests/
+                    pybot -d Log -T -v src_ip:${deployment_config.srcHost.ip} -v src_user:${deployment_config.srcHost.user} -v src_pass:${deployment_config.srcHost.pass} -v dst_user:${deployment_config.dstHost.user} -v dst_pass:${deployment_config.dstHost.pass} -v dst_ip:${deployment_config.dstHost.ip} -v dst_host_ip:${deployment_config.dstHost.hostIp} -v src_gateway:${deployment_config.srcHost.gateway} -v dst_gateway:${deployment_config.dstHost.gateway} -v src_iface:${deployment_config.srcHost.public_iface} WorkflowValidations/ATT_Test001.txt || true
+                    """
+                }
+            }
+            stage('Publish test results') {
+                sh returnStdout: true, script: """
+                if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs;
+                mkdir RobotLogs/TestDoc || true
+                cp -r $WORKSPACE/cord-tester/src/test/robot/Log/* $WORKSPACE/RobotLogs || true
+                cp -r $WORKSPACE/cord-tester/src/test/cord-api/Tests/Log/* $WORKSPACE/RobotLogs || true
+                """
+                step([$class: 'RobotPublisher',
+                    disableArchiveOutput: false,
+                    logFileName: 'RobotLogs/log*.html',
+                    otherFiles: '',
+                    outputFileName: 'RobotLogs/output*.xml',
+                    outputPath: '.',
+                    passThreshold: 100,
+                    reportFileName: 'RobotLogs/report*.html',
+                    unstableThreshold: 0
+                ])
+            }
+            currentBuild.result = 'SUCCESS'
+        } catch (err) {
+            currentBuild.result = 'FAILURE'
+            step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
+        }
+        echo "RESULT: ${currentBuild.result}"
+    }
+}
diff --git a/Jenkinsfile-rcordlite b/Jenkinsfile-rcordlite-control-plane
similarity index 80%
rename from Jenkinsfile-rcordlite
rename to Jenkinsfile-rcordlite-control-plane
index 2f96139..8eafcf5 100644
--- a/Jenkinsfile-rcordlite
+++ b/Jenkinsfile-rcordlite-control-plane
@@ -12,8 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-pod_config = null
-
 node ("${TestNodeName}") {
     timeout (time: 240) {
         stage ("Parse deployment configuration file") {
@@ -37,19 +35,35 @@
         }
         stage('Clean up') {
             timeout(10) {
-                try {
-                    sh """
-                    cd /home/cord/helm-charts
-                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
-                    helm ls | grep onos-voltha && helm delete --purge onos-voltha
-                    helm ls | grep onos-fabric && helm delete --purge onos-fabric
-                    helm ls | grep voltha && helm delete --purge voltha
-                    helm ls | grep rcord-lite && helm delete --purge rcord-lite
-                    helm ls | grep xos-core && helm delete --purge xos-core
-                    sleep 80
-                    """
-                } catch(error) { currentBuild.result = 'FAILURE' }
-            }    
+                sh returnStdout: true, script: """
+                rm -rf helm-charts cord-tester
+                git clone -b ${branch} ${cordRepoUrl}/helm-charts
+                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('Install xos-core and rcord-lite') {
             timeout(10) {