blob: 8362a0841b35a0aa77e628389c9c910587c7a3eb [file] [log] [blame]
Joey Armstrong980e37f2023-02-28 18:57:41 -05001// Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
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// 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&
107 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
108 """
109 }
110 }
111
112 stage('Run E2E Tests') {
113 steps {
114 sh '''
115 mkdir -p $WORKSPACE/RobotLogs
116
117 # tell the kubernetes script to use images tagged citest and pullPolicy:Never
118 sed -i 's/master/citest/g' $WORKSPACE/device-management/kubernetes/deploy*.yaml
119 sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' $WORKSPACE/device-management/kubernetes/deploy*.yaml
120 make -C $WORKSPACE/device-management functional-mock-test || true
121 '''
122 }
123 }
124 }
125
126 post {
127 always {
128 sh '''
129 set +e
130 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq
131 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq
132 kubectl get nodes -o wide
133 kubectl get pods -o wide --all-namespaces
134
135 sync
136 pkill kail || true
137
138 ## Pull out errors from log files
139 extract_errors_go() {
140 echo
141 echo "Error summary for $1:"
142 grep $1 $WORKSPACE/att/onos-voltha-combined.log | grep '"level":"error"' | cut -d ' ' -f 2- | jq -r '.msg'
143 echo
144 }
145
146 extract_errors_python() {
147 echo
148 echo "Error summary for $1:"
149 grep $1 $WORKSPACE/att/onos-voltha-combined.log | grep 'ERROR' | cut -d ' ' -f 2-
150 echo
151 }
152
153 extract_errors_go voltha-rw-core > $WORKSPACE/error-report.log
154 extract_errors_go adapter-open-olt >> $WORKSPACE/error-report.log
155 extract_errors_python adapter-open-onu >> $WORKSPACE/error-report.log
156 extract_errors_python voltha-ofagent >> $WORKSPACE/error-report.log
157
158 gzip $WORKSPACE/att/onos-voltha-combined.log
159 '''
160 step([$class: 'RobotPublisher',
161 disableArchiveOutput: false,
162 logFileName: 'RobotLogs/log*.html',
163 otherFiles: '',
164 outputFileName: 'RobotLogs/output*.xml',
165 outputPath: '.',
166 passThreshold: 80,
167 reportFileName: 'RobotLogs/report*.html',
168 unstableThreshold: 0]);
169 archiveArtifacts artifacts: '**/*.log,**/*.gz'
170 }
171 }
172}