blob: 90519c063d67e490f6d5b2eb9f2ddf8a013c42ae [file] [log] [blame]
Joey Armstrong518f3572024-02-11 07:56:25 -05001// Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo37f168b2021-04-15 16:20:46 -07002//
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// NOTE we are importing the library even if it's global so that it's
16// easier to change the keywords during a replay
17library identifier: 'cord-jenkins-libraries@master',
18 retriever: modernSCM([
19 $class: 'GitSCMSource',
20 remote: 'https://gerrit.opencord.org/ci-management.git'
21])
22
23def localCharts = false
24
25pipeline {
26
27 /* no label, executor is determined by JJB */
28 agent {
29 label "${params.buildNode}"
30 }
31 options {
32 timeout(time: 90, unit: 'MINUTES')
33 }
34 environment {
35 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
36 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
37 ROBOT_MISC_ARGS="-d $WORKSPACE/RobotLogs"
38 }
39
40 stages {
41
42 stage('Download Code') {
43 steps {
44 getVolthaCode([
45 branch: "${branch}",
46 gerritProject: "${gerritProject}",
47 gerritRefspec: "${gerritRefspec}",
48 volthaSystemTestsChange: "${volthaSystemTestsChange}",
49 volthaHelmChartsChange: "${volthaHelmChartsChange}",
50 ])
51 }
52 }
53 stage('Build Redfish Importer Image') {
54 steps {
55 sh """
56 make -C $WORKSPACE/device-management/\$1 DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build-importer
57 """
58 }
59 }
60 stage('Build demo_test Image') {
61 steps {
62 sh """
63 make -C $WORKSPACE/device-management/\$1/demo_test DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build
64 """
65 }
66 }
67 stage('Build mock-redfish-server Image') {
68 steps {
69 sh """
70 make -C $WORKSPACE/device-management/\$1/mock-redfish-server DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build
71 """
72 }
73 }
74 stage('Create K8s Cluster') {
75 steps {
76 createKubernetesCluster([nodes: 3])
77 }
78 }
79 stage('Load image in kind nodes') {
80 steps {
81 loadToKind()
82 }
83 }
84 stage('Deploy Voltha') {
85 steps {
86 script {
87 if (branch != "master" || volthaHelmChartsChange != "") {
88 // if we're using a release or testing changes in the charts, then use the local clone
89 localCharts = true
90 }
91 }
92 volthaDeploy([
93 workflow: "att",
94 extraHelmFlags: extraHelmFlags,
95 dockerRegistry: "mirror.registry.opennetworking.org",
96 localCharts: localCharts,
97 ])
98 // start logging
99 sh """
100 mkdir -p $WORKSPACE/att
101 _TAG=kail-att kail -n infra -n voltha -n default > $WORKSPACE/att/onos-voltha-combined.log &
102 """
103 // forward ONOS and VOLTHA ports
104 sh """
105 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
106 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
Matteo Scandolo37f168b2021-04-15 16:20:46 -0700107 """
108 }
109 }
110
111 stage('Run E2E Tests') {
112 steps {
113 sh '''
114 mkdir -p $WORKSPACE/RobotLogs
115
116 # tell the kubernetes script to use images tagged citest and pullPolicy:Never
117 sed -i 's/master/citest/g' $WORKSPACE/device-management/kubernetes/deploy*.yaml
118 sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' $WORKSPACE/device-management/kubernetes/deploy*.yaml
119 make -C $WORKSPACE/device-management functional-mock-test || true
120 '''
121 }
122 }
123 }
124
125 post {
126 always {
127 sh '''
128 set +e
129 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq
130 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq
131 kubectl get nodes -o wide
132 kubectl get pods -o wide --all-namespaces
133
134 sync
135 pkill kail || true
136
137 ## Pull out errors from log files
138 extract_errors_go() {
139 echo
140 echo "Error summary for $1:"
141 grep $1 $WORKSPACE/att/onos-voltha-combined.log | grep '"level":"error"' | cut -d ' ' -f 2- | jq -r '.msg'
142 echo
143 }
144
145 extract_errors_python() {
146 echo
147 echo "Error summary for $1:"
148 grep $1 $WORKSPACE/att/onos-voltha-combined.log | grep 'ERROR' | cut -d ' ' -f 2-
149 echo
150 }
151
152 extract_errors_go voltha-rw-core > $WORKSPACE/error-report.log
153 extract_errors_go adapter-open-olt >> $WORKSPACE/error-report.log
154 extract_errors_python adapter-open-onu >> $WORKSPACE/error-report.log
155 extract_errors_python voltha-ofagent >> $WORKSPACE/error-report.log
156
157 gzip $WORKSPACE/att/onos-voltha-combined.log
158 '''
159 step([$class: 'RobotPublisher',
160 disableArchiveOutput: false,
161 logFileName: 'RobotLogs/log*.html',
162 otherFiles: '',
163 outputFileName: 'RobotLogs/output*.xml',
164 outputPath: '.',
165 passThreshold: 80,
166 reportFileName: 'RobotLogs/report*.html',
167 unstableThreshold: 0]);
168 archiveArtifacts artifacts: '**/*.log,**/*.gz'
169 }
170 }
171}