[SDFAB-391] Create a new fabric-tna job and pipeline to run linerate tests

Change-Id: I7be6f3151a945385df9c77ba905eb22e0ffdfe79
diff --git a/jjb/pipeline/fabric-tna-hardware.groovy b/jjb/pipeline/fabric-tna-hardware.groovy
new file mode 100644
index 0000000..059687c
--- /dev/null
+++ b/jjb/pipeline/fabric-tna-hardware.groovy
@@ -0,0 +1,57 @@
+pipeline {
+    agent {
+        label "${params.BUILD_NODE}"
+    }
+    options {
+        timeout(time: 60, unit: 'MINUTES')
+    }
+    environment {
+        SWITCH_USER = "jenkins"
+        STRATUM_PORT = "${params.STRATUM_PORT}"
+        SWITCH_ADDR = "${params.SWITCH_IP}:${STRATUM_PORT}"
+        SWITCH_SSH = "${SWITCH_USER}@${params.SWITCH_IP}"
+        CHASSIS_CONFIG = "/home/jenkins/chassis_config.pb.txt"
+        TREX_DIR = "/srv/trex-core-2.85-scapy-2.4.5/scripts"
+    }
+
+    stages {
+        stage('Start Stratum') {
+            steps {
+                step([$class: 'WsCleanup'])
+                git branch: "${params.GIT_BRANCH}", credentialsId: 'github-onf-bot-ssh-key', url: "${params.GIT_URL}"
+                sshagent(credentials: ['menlo-pdp-32qs-jenkins']) {
+                    sh returnStdout: false, label: "Start Stratum on ${params.SWITCH_IP}", script: '''
+                        . ./.env
+                        ssh ${SWITCH_SSH} "docker stop stratum_bfrt && sudo pkill stratum" || true
+                        scp ./ptf/tests/linerate/chassis_config.pb.txt ${SWITCH_SSH}:/home/jenkins/
+                        ssh ${SWITCH_SSH} "DOCKER_IMAGE_TAGGED=$STRATUM_DOCKER_IMG SDE_VERSION=$SDE_VERSION CHASSIS_CONFIG=${CHASSIS_CONFIG} \
+                            ./start-stratum-container.sh -external_stratum_urls=0.0.0.0:${STRATUM_PORT}"
+                    '''
+                    sh "until nc -z ${params.SWITCH_IP} ${STRATUM_PORT}; do sleep 1; done"
+                }
+            }
+        }
+        stage('Run fabric-tna tests') {
+            options { retry(3) }
+            steps {
+                script {
+                    withDockerRegistry([url: "https://registry.opennetworking.org", credentialsId: "onf-registry-credentials"]) {
+                        sh returnStdout: false, label: "Build fabric-tna and run linerate tests", script: """
+                            PROFILE=${params.PROFILE} SWITCH_ADDR=${SWITCH_ADDR} bash .jenkins/linerate.sh
+                        """
+                    }
+                }
+            }
+        }
+    }
+    post {
+        always {
+            sshagent(credentials: ['menlo-pdp-32qs-jenkins']) {
+                sh returnStdout: false, label: "Stop Stratum", script: """
+                    ssh ${SWITCH_SSH} "docker stop stratum_bfrt && sudo pkill stratum" || true
+                """
+            }
+            archiveArtifacts(artifacts: 'logs/**/**', allowEmptyArchive: true, excludes: 'logs/**/int-traffic-trace-*.pcap')
+        }
+    }
+}
diff --git a/jjb/repos/fabric-tna.yaml b/jjb/repos/fabric-tna.yaml
index 5e6f3c3..2c6e870 100644
--- a/jjb/repos/fabric-tna.yaml
+++ b/jjb/repos/fabric-tna.yaml
@@ -20,3 +20,4 @@
     jobs:
       - 'fabric-tna-pr-verify'
       - 'fabric-tna-postmerge'
+      - 'fabric-tna-linerate-tests'
diff --git a/jjb/templates/fabric-tna-jobs.yaml b/jjb/templates/fabric-tna-jobs.yaml
index efabd3b..8e8db60 100644
--- a/jjb/templates/fabric-tna-jobs.yaml
+++ b/jjb/templates/fabric-tna-jobs.yaml
@@ -159,3 +159,60 @@
           # branch and the new pull request.
           artifacts: '**/*.log,**/*.json'
           excludes: 'tmp/**/*'
+
+- job-template:
+    id: 'fabric-tna-linerate-tests'
+    name: 'fabric-tna-linerate-tests'
+
+    description: |
+      Created by {id} job-template from ci-management/jjb/fabric-tna-jobs.yaml, script ../pipeline/fabric-tna.groovy<br/>
+
+    # Cron syntax; trigger daily at 23:00 PST
+    triggers:
+      - timed: |
+            TZ=US/Pacific
+            H 23 * * *
+
+    properties:
+      - onf-infra-onfstaff-private:
+      - onf-infra-properties:
+          build-days-to-keep: '15'
+          artifact-num-to-keep: '15'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '60'
+          jenkins-ssh-credential: '{github-onf-bot-ssh-credential}'
+
+    parameters:
+      - string:
+          name: BUILD_NODE
+          default: 'menlo-pdp-lotta-nics'
+          description: 'Name of the Jenkins build executor to run the job on'
+      - string:
+          name: GIT_URL
+          default: 'git@github.com:stratum/fabric-tna.git'
+          description: 'Location of fabric-tna repository that tests will check'
+      - string:
+          name: GIT_BRANCH
+          default: 'main'
+          description: 'Name of Git branch to pull from fabric-tna repository'
+      - string:
+          name: PROFILE
+          default: 'fabric-spgw-int'
+          description: 'Name of the flavor of linerate tests to run'
+      - string:
+          name: SWITCH_IP
+          default: '10.128.13.29'
+          description: 'Address of the Stratum service (P4Runtime, gNMI, etc.) running on the remote switch'
+      - string:
+          name: STRATUM_PORT
+          default: '28000'
+          description: 'Port of the Stratum service (P4Runtime, gNMI, etc.) running on the remote switch'
+
+    project-type: pipeline
+    concurrent: true
+    extraEnvironmentVars: ""
+    sandbox: true
+
+    dsl: !include-raw-escape: ../pipeline/fabric-tna-hardware.groovy