creating re-deploy node job for mcord-build to listen to

Change-Id: I52fd70b2377d58ca66c245467817527ea831a3cf
diff --git a/jjb/cord-test/mcord-build.yaml b/jjb/cord-test/mcord-build.yaml
index 7500fde..f90f2ed 100644
--- a/jjb/cord-test/mcord-build.yaml
+++ b/jjb/cord-test/mcord-build.yaml
@@ -1,34 +1,46 @@
 ---
-# POD Nightly Build Pipeline M-CORD Jobs
+# MCORD 6.0 Build+Test job on Single-Node
 
 - project:
-    name: mcord-nightly-build-pipeline
+    name: mcord-build
 
     project-name: '{name}'
 
-    build-timeout: '300'
-
     jobs:
-      # qct pod 4 build jobs (mcord)
-      - 'build_pod_manual':
-         pod: 'qct-pod4'
-         pod_config: 'qct-pod4-mcord.yml'
-         profile: 'mcord'
-         branch: 'cord-4.1'
-         Jenkinsfile: 'Jenkinsfile.newBuildSystem'
+      - 'mcord_build_test'
 
-      # onf pod build job (mcord)
-      - 'build_pod_manual':
-         pod: 'onf-mcord-dev'
-         pod_config: 'onlab-mcord-cavium-pod1.yml'
-         profile: 'mcord'
-         branch: 'cord-5.0'
-         Jenkinsfile: 'Jenkinsfile.MCORDBuildSystem'
+- job-template:
+    id: mcord_build_test
+    name: 'mcord_build_test'
+    description: |
+      Created by {id} job-template from ci-management/jjb/mcord-build.yaml
 
-      # qct pod 4 test jobs
-      - 'build_pod_manual_test':
-         pod: 'qct-pod4'
-         pod_config: 'qct-pod4-mcord.yml'
-         profile: 'mcord'
-         branch: 'cord-4.1'
-         Jenkinsfile: 'Jenkinsfile-mcord'
+    properties:
+      - cord-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+          artifact-num-to-keep: '{artifact-num-to-keep}'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    parameters:
+      - string:
+          name: executorNode
+          default: 'flex-ocp-mcord'
+          description: 'Name of the Jenkins node to run the job on'
+
+      - string:
+         name: notificationEmail
+         default: 'kailash@opennetworking.org, you@opennetworking.org, suchitra@opennetworking.org'
+         description: 'List of email recipients'
+
+    project-type: pipeline
+    concurrent: false
+
+    dsl: !include-raw-escape: ../pipeline/mcord-deployment.groovy
+
+    triggers:
+        - reverse:
+            jobs: 'deploy-node-maas'
diff --git a/jjb/mcord-build.yaml b/jjb/mcord-build.yaml
deleted file mode 100644
index d46ea6b..0000000
--- a/jjb/mcord-build.yaml
+++ /dev/null
@@ -1,42 +0,0 @@
----
-# MCORD 6.0 Build+Test job on Single-Node
-
-- project:
-    name: mcord-build
-
-    project-name: '{name}'
-
-    jobs:
-      - 'mcord_build_test'
-
-- job-template:
-    id: mcord_build_test
-    name: 'mcord_build_test'
-    description: |
-      Created by {id} job-template from ci-management/jjb/mcord-build.yaml
-
-    properties:
-      - cord-infra-properties:
-          build-days-to-keep: '{build-days-to-keep}'
-          artifact-num-to-keep: '{artifact-num-to-keep}'
-
-    wrappers:
-      - lf-infra-wrappers:
-          build-timeout: '{build-timeout}'
-          jenkins-ssh-credential: '{jenkins-ssh-credential}'
-
-    parameters:
-      - string:
-          name: executorNode
-          default: 'flex-ocp-mcord'
-          description: 'Name of the Jenkins node to run the job on'
-
-      - string:
-         name: notificationEmail
-         default: 'kailash@opennetworking.org, you@opennetworking.org, suchitra@opennetworking.org'
-         description: 'List of email recipients'
-
-    project-type: pipeline
-    concurrent: false
-
-    dsl: !include-raw-escape: pipeline/mcord-deployment.groovy
diff --git a/jjb/pipeline/redeploy-node-maas.groovy b/jjb/pipeline/redeploy-node-maas.groovy
new file mode 100644
index 0000000..fe93747
--- /dev/null
+++ b/jjb/pipeline/redeploy-node-maas.groovy
@@ -0,0 +1,54 @@
+/*re-deploy node via maas cli commands. to be used prior to mcord 6.0 build job*/
+
+pipeline {
+
+  /* no label, executor is determined by JJB */
+  agent {
+    label "${params.executorNode}"
+  }
+
+  stages {
+
+    stage ('Re-Deploy Node') {
+      steps {
+          sh "maas login maas http://${maas_ip}/MAAS/api/2.0 ${maas_api_key}"
+          sh "maas maas machine release ${node_id}"
+
+          timeout(time:15) {
+            waitUntil {
+              script {
+                  try {
+                    sh "maas maas machine read ${node_id} | grep Ready"
+                    return true
+                    } catch (exception) {
+                        return false
+                    }
+                 }
+              }
+            }
+
+            sh "maas maas machines allocate"
+            sh "maas maas machine deploy ${node_id}"
+
+         timeout(time:15) {
+            waitUntil {
+              script {
+                  try {
+                    sh "maas maas machine read ${node_id} | grep Deployed"
+                    return true
+                    } catch (exception) {
+                        return false
+                    }
+                 }
+              }
+            }
+          }
+      }
+   }
+
+  post {
+        always {
+          step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
+     }
+    }
+}
diff --git a/jjb/redeploy-node-maas.yaml b/jjb/redeploy-node-maas.yaml
new file mode 100644
index 0000000..a0c7e00
--- /dev/null
+++ b/jjb/redeploy-node-maas.yaml
@@ -0,0 +1,58 @@
+---
+# Job to re-deploy a particular node on a given maas server
+# Job requires maas server api-key and node id
+
+- project:
+    name: deploy-node
+
+    project-name: '{name}'
+
+    jobs:
+      - 'deploy-node-maas'
+
+- job-template:
+    id: deploy-node-maas
+    name: 'deploy-node-maas'
+    description: |
+      Created by {id} job-template from ci-management/jjb/redeploy-node-maas.yaml
+
+    properties:
+      - cord-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+          artifact-num-to-keep: '{artifact-num-to-keep}'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    parameters:
+      - string:
+          name: executorNode
+          default: 'qa-testvm-pod'
+          description: 'Name of the Jenkins node to run the job on. This node must have access to the maas server'
+
+      - string:
+          name: maas_ip
+          default: ''
+          description: 'IP of MAAS Server'
+
+      - string:
+          name: maas_api_key
+          default: ''
+          description: 'MAAS API Key'
+
+      - string:
+          name: node_id
+          default: 'rrwkmn'
+          description: 'Node Id of node to release acquire and deploy'
+
+      - string:
+         name: notificationEmail
+         default: 'kailash@opennetworking.org, you@opennetworking.org, suchitra@opennetworking.org'
+         description: 'List of email recipients'
+
+    project-type: pipeline
+    concurrent: false
+
+    dsl: !include-raw-escape: pipeline/redeploy-node-maas.groovy