Hardik Windlass | 36d5bdb | 2022-02-09 10:13:13 +0000 | [diff] [blame^] | 1 | // Copyright 2022-present Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // used to deploy VOLTHA and configure ONOS physical PODs |
| 16 | |
| 17 | // NOTE we are importing the library even if it's global so that it's |
| 18 | // easier to change the keywords during a replay |
| 19 | library identifier: 'cord-jenkins-libraries@master', |
| 20 | retriever: modernSCM([ |
| 21 | $class: 'GitSCMSource', |
| 22 | remote: 'https://gerrit.opencord.org/ci-management.git' |
| 23 | ]) |
| 24 | |
| 25 | def infraNamespace = "infra" |
| 26 | def volthaNamespace = "voltha" |
| 27 | |
| 28 | def deploy_custom_chart(namespace, name, chart, extraHelmFlags) { |
| 29 | sh """ |
| 30 | helm install --create-namespace --set defaults.image_pullPolicy=Always --namespace ${namespace} ${extraHelmFlags} ${name} ${chart} |
| 31 | """ |
| 32 | } |
| 33 | |
| 34 | pipeline { |
| 35 | |
| 36 | /* no label, executor is determined by JJB */ |
| 37 | agent { |
| 38 | label "${params.buildNode}" |
| 39 | } |
| 40 | options { |
| 41 | timeout(time: 45, unit: 'MINUTES') |
| 42 | } |
| 43 | environment { |
| 44 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 45 | KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf" |
| 46 | VOLTCONFIG="$HOME/.volt/config-minimal" |
| 47 | LOG_FOLDER="$WORKSPACE/dmi/" |
| 48 | APPS_TO_LOG="${OltDevMgr}" |
| 49 | } |
| 50 | |
| 51 | stages{ |
| 52 | stage('Download Code') { |
| 53 | steps { |
| 54 | getVolthaCode([ |
| 55 | branch: "${branch}", |
| 56 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 57 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 58 | ]) |
| 59 | } |
| 60 | } |
| 61 | stage ("Parse deployment configuration file") { |
| 62 | steps { |
| 63 | sh returnStdout: true, script: "rm -rf ${configBaseDir}" |
| 64 | sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}" |
| 65 | script { |
| 66 | if ( params.workFlow == "DT" ) { |
| 67 | deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml" |
| 68 | } |
| 69 | else if ( params.workFlow == "TT" ) |
| 70 | { |
| 71 | deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-TT.yaml" |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml" |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | stage('Clean up') { |
| 81 | steps { |
| 82 | timeout(15) { |
| 83 | script { |
| 84 | helmTeardown(["default", infraNamespace, volthaNamespace]) |
| 85 | } |
| 86 | timeout(1) { |
| 87 | sh returnStdout: false, script: ''' |
| 88 | # remove orphaned port-forward from different namespaces |
| 89 | ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true |
| 90 | ''' |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | stage('Install Voltha') { |
| 96 | steps { |
| 97 | timeout(20) { |
| 98 | installVoltctl("${branch}") |
| 99 | script { |
| 100 | // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts |
| 101 | def localCharts = false |
| 102 | if (volthaHelmChartsChange != "") { |
| 103 | localCharts = true |
| 104 | } |
| 105 | |
| 106 | // should the config file be suffixed with the workflow? see "deployment_config" |
| 107 | def localHelmFlags = "-f $WORKSPACE/${configBaseDir}/${configKubernetesDir}/voltha/${configFileName}.yml --set global.log_level=${logLevel} " |
| 108 | |
| 109 | if (workFlow.toLowerCase() == "dt") { |
| 110 | localHelmFlags += " --set radius.enabled=false " |
| 111 | } |
| 112 | if (workFlow.toLowerCase() == "tt") { |
| 113 | localHelmFlags += " --set radius.enabled=false --set global.incremental_evto_update=true " |
| 114 | if (enableMultiUni.toBoolean()) { |
| 115 | localHelmFlags += " --set voltha-adapter-openonu.adapter_open_onu.uni_port_mask=${uniPortMask} " |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // NOTE temporary workaround expose ONOS node ports (pod-config needs to be updated to contain these values) |
| 120 | // and to connect the ofagent to all instances of ONOS |
| 121 | localHelmFlags = localHelmFlags + " --set onos-classic.onosSshPort=30115 " + |
| 122 | "--set onos-classic.onosApiPort=30120 " + |
| 123 | "--set onos-classic.onosOfPort=31653 " + |
| 124 | "--set onos-classic.individualOpenFlowNodePorts=true " + |
| 125 | "--set voltha.onos_classic.replicas=${params.NumOfOnos}" |
| 126 | |
| 127 | if (bbsimReplicas.toInteger() != 0) { |
| 128 | localHelmFlags = localHelmFlags + " --set onu=${onuNumber},pon=${ponNumber} " |
| 129 | } |
| 130 | |
| 131 | // adding user specified helm flags at the end so they'll have priority over everything else |
| 132 | localHelmFlags = localHelmFlags + " ${extraHelmFlags}" |
| 133 | |
| 134 | def numberOfAdaptersToWait = 2 |
| 135 | |
| 136 | if(openoltAdapterChart != "onf/voltha-adapter-openolt") { |
| 137 | localHelmFlags = localHelmFlags + " --set voltha-adapter-openolt.enabled=false" |
| 138 | // We skip waiting for adapters in the volthaDeploy step because it's already waiting for |
| 139 | // both of them after the deployment of the custom olt adapter. See line 156. |
| 140 | numberOfAdaptersToWait = 0 |
| 141 | } |
| 142 | |
| 143 | volthaDeploy([ |
| 144 | workflow: workFlow.toLowerCase(), |
| 145 | extraHelmFlags: localHelmFlags, |
| 146 | localCharts: localCharts, |
| 147 | kubeconfig: "$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf", |
| 148 | onosReplica: params.NumOfOnos, |
| 149 | atomixReplica: params.NumOfAtomix, |
| 150 | kafkaReplica: params.NumOfKafka, |
| 151 | etcdReplica: params.NumOfEtcd, |
| 152 | bbsimReplica: bbsimReplicas.toInteger(), |
| 153 | adaptersToWait: numberOfAdaptersToWait, |
| 154 | ]) |
| 155 | |
| 156 | if(openoltAdapterChart != "onf/voltha-adapter-openolt"){ |
| 157 | extraHelmFlags = extraHelmFlags + " --set global.log_level=${logLevel}" |
| 158 | deploy_custom_chart(volthaNamespace, oltAdapterReleaseName, openoltAdapterChart, extraHelmFlags) |
| 159 | waitForAdapters([ |
| 160 | adaptersToWait: 2 |
| 161 | ]) |
| 162 | } |
| 163 | } |
| 164 | sh """ |
| 165 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"& |
| 166 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="etcd" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd ${params.VolthaEtcdPort}:2379; done"& |
| 167 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="kafka" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"& |
| 168 | ps aux | grep port-forward |
| 169 | """ |
| 170 | getPodsInfo("$WORKSPACE") |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | stage('Deploy Device Manager Interface Chart') { |
| 175 | steps { |
| 176 | script { |
| 177 | deploy_custom_chart('default', 'olt-device-manager', dmiChart, extraHelmFlags) |
| 178 | } |
| 179 | println "Wait for olt-device-manager to start" |
| 180 | sh """ |
| 181 | set +x |
| 182 | devmgr=\$(kubectl get pods -l app.kubernetes.io/name=${params.OltDevMgr} --no-headers | grep "0/" | wc -l) |
| 183 | while [[ \$devmgr != 0 ]]; do |
| 184 | sleep 5 |
| 185 | devmgr=\$(kubectl get pods -l app.kubernetes.io/name=${params.OltDevMgr} --no-headers | grep "0/" | wc -l) |
| 186 | done |
| 187 | """ |
| 188 | sh """ |
| 189 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="${params.OltDevMgr}" bash -c "while true; do kubectl port-forward --address 0.0.0.0 svc/${params.OltDevMgr} 50051:10000; done"& |
| 190 | ps aux | grep port-forward |
| 191 | """ |
| 192 | } |
| 193 | } |
| 194 | stage('Start logging') { |
| 195 | steps { |
| 196 | sh returnStdout: false, script: ''' |
| 197 | # start logging with kail |
| 198 | cd $WORKSPACE |
| 199 | mkdir -p $LOG_FOLDER |
| 200 | list=($APPS_TO_LOG) |
| 201 | for app in "${list[@]}" |
| 202 | do |
| 203 | echo "Starting logs for: ${app}" |
| 204 | _TAG=kail-$app kail -l app.kubernetes.io/name=$app --since 1h > $LOG_FOLDER/$app.log& |
| 205 | done |
| 206 | ''' |
| 207 | } |
| 208 | } |
| 209 | stage('Reinstall OLT software') { |
| 210 | steps { |
| 211 | script { |
| 212 | if ( params.reinstallOlt ) { |
| 213 | for(int i=0; i < deployment_config.olts.size(); i++) { |
| 214 | sh returnStdout: true, script: """ |
| 215 | ssh-keyscan -H ${deployment_config.olts[i].sship} >> ~/.ssh/known_hosts |
| 216 | if [ "${params.inBandManagement}" == "true" ]; then |
| 217 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'kill -9 `pgrep -f "[b]ash /opt/openolt/openolt_dev_mgmt_daemon_process_watchdog"` || true' |
| 218 | fi |
| 219 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} "dpkg --install ${deployment_config.olts[i].oltDebVersion}" |
| 220 | sleep 10 |
| 221 | """ |
| 222 | timeout(5) { |
| 223 | waitUntil { |
| 224 | olt_sw_present = sh returnStdout: true, script: """ |
| 225 | if [[ "${deployment_config.olts[i].oltDebVersion}" == *"asfvolt16"* ]]; then |
| 226 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'dpkg --list | grep asfvolt16 | wc -l' |
| 227 | elif [[ "${deployment_config.olts[i].oltDebVersion}" == *"asgvolt64"* ]]; then |
| 228 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'dpkg --list | grep asgvolt64 | wc -l' |
| 229 | elif [[ "${deployment_config.olts[i].oltDebVersion}" == *"rlt-1600x-w"* ]]; then |
| 230 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'dpkg --list | grep rlt-1600x-w | wc -l' |
| 231 | elif [[ "${deployment_config.olts[i].oltDebVersion}" == *"rlt-1600g-w"* ]]; then |
| 232 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'dpkg --list | grep rlt-1600g-w | wc -l' |
| 233 | elif [[ "${deployment_config.olts[i].oltDebVersion}" == *"rlt-3200g-w"* ]]; then |
| 234 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'dpkg --list | grep rlt-3200g-w | wc -l' |
| 235 | else |
| 236 | echo Unknown Debian package for openolt |
| 237 | fi |
| 238 | if (${deployment_config.olts[i].fortygig}); then |
| 239 | if [[ "${params.inBandManagement}" == "true" ]]; then |
| 240 | ssh-keyscan -H ${deployment_config.olts[i].sship} >> ~/.ssh/known_hosts |
| 241 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'mkdir -p /opt/openolt/' |
| 242 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'cp /root/watchdog-script/* /opt/openolt/' |
| 243 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'cp /root/bal_cli_appl/example_user_appl /broadcom' |
| 244 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'cp in-band-startup-script/* /etc/init.d/' |
| 245 | fi |
| 246 | fi |
| 247 | """ |
| 248 | return olt_sw_present.toInteger() > 0 |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | stage('Restart OLT processes') { |
| 257 | steps { |
| 258 | script { |
| 259 | if ( params.restartOlt ) { |
| 260 | //rebooting OLTs |
| 261 | for(int i=0; i < deployment_config.olts.size(); i++) { |
| 262 | timeout(15) { |
| 263 | sh returnStdout: true, script: """ |
| 264 | ssh-keyscan -H ${deployment_config.olts[i].sship} >> ~/.ssh/known_hosts |
| 265 | sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'rm -f /var/log/openolt.log; rm -f /var/log/dev_mgmt_daemon.log; rm -f /var/log/openolt_process_watchdog.log; reboot > /dev/null &' || true |
| 266 | """ |
| 267 | } |
| 268 | } |
| 269 | sh returnStdout: true, script: """ |
| 270 | sleep ${params.waitTimerForOltUp} |
| 271 | """ |
| 272 | //Checking dev_management_deamon and openoltprocesses |
| 273 | for(int i=0; i < deployment_config.olts.size(); i++) { |
| 274 | if ( params.oltAdapterReleaseName != "open-olt" ) { |
| 275 | timeout(15) { |
| 276 | waitUntil { |
| 277 | devprocess = sh returnStdout: true, script: "sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'ps -ef | grep dev_mgmt_daemon | wc -l'" |
| 278 | return devprocess.toInteger() > 0 |
| 279 | } |
| 280 | } |
| 281 | timeout(15) { |
| 282 | waitUntil { |
| 283 | openoltprocess = sh returnStdout: true, script: "sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].sship} 'ps -ef | grep openolt | wc -l'" |
| 284 | return openoltprocess.toInteger() > 0 |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | stage('Run Device Management Interface Tests') { |
| 294 | environment { |
| 295 | ROBOT_FILE="dmi-hw-management.robot" |
| 296 | ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs" |
| 297 | ROBOT_CONFIG_FILE="$WORKSPACE/voltha-system-tests/tests/data/dmi-components-adtran.yaml" |
| 298 | } |
| 299 | steps { |
| 300 | sh """ |
| 301 | mkdir -p $ROBOT_LOGS_DIR |
| 302 | export ROBOT_MISC_ARGS="--removekeywords wuks -e notreadyDMI -i functionalDMI -d $ROBOT_LOGS_DIR" |
| 303 | make -C $WORKSPACE/voltha-system-tests voltha-dmi-test || true |
| 304 | """ |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | post { |
| 310 | always { |
| 311 | sh ''' |
| 312 | # stop the kail processes |
| 313 | list=($APPS_TO_LOG) |
| 314 | for app in "${list[@]}" |
| 315 | do |
| 316 | echo "Stopping logs for: ${app}" |
| 317 | _TAG="kail-$app" |
| 318 | P_IDS="$(ps e -ww -A | grep "_TAG=$_TAG" | grep -v grep | awk '{print $1}')" |
| 319 | if [ -n "$P_IDS" ]; then |
| 320 | echo $P_IDS |
| 321 | for P_ID in $P_IDS; do |
| 322 | kill -9 $P_ID |
| 323 | done |
| 324 | fi |
| 325 | done |
| 326 | ''' |
| 327 | step([$class: 'RobotPublisher', |
| 328 | disableArchiveOutput: false, |
| 329 | logFileName: 'RobotLogs/log*.html', |
| 330 | otherFiles: '', |
| 331 | outputFileName: 'RobotLogs/output*.xml', |
| 332 | outputPath: '.', |
| 333 | passThreshold: 100, |
| 334 | reportFileName: 'RobotLogs/report*.html', |
| 335 | unstableThreshold: 0, |
| 336 | onlyCritical: true]); |
| 337 | archiveArtifacts artifacts: '**/*.txt,**/*.gz,*.gz,**/*.log' |
| 338 | } |
| 339 | } |
| 340 | } |