blob: b4e8f696299d91d4e81d7dd936c5f3486f747c51 [file] [log] [blame]
Devin Lim142b5342017-07-20 15:22:39 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Devin Lim142b5342017-07-20 15:22:39 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Devin Lim142b5342017-07-20 15:22:39 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
Devin Lim58046fa2017-07-05 16:55:00 -070021class Utils:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070022
Devin Lim58046fa2017-07-05 16:55:00 -070023 def __init__( self ):
24 self.default = ''
25
Devin Lim0c972b72018-02-08 14:53:59 -080026 def mininetCleanIntro( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070027 """
28 Description:
29 Introduction information of the mininet clean up
30 Required:
31 Returns:
32 """
Devin Lim58046fa2017-07-05 16:55:00 -070033 main.log.report( "Stop Mininet" )
Devin Lim0c972b72018-02-08 14:53:59 -080034 if includeCaseDesc:
35 main.case( "Stop Mininet" )
36 main.caseExplanation = "Stopping the current mininet to start up fresh"
Devin Lim58046fa2017-07-05 16:55:00 -070037
Devin Lima7cfdbd2017-09-29 15:02:22 -070038 def mininetCleanup( self, Mininet, timeout=5, exitTimeout=1000 ):
Devin Lim142b5342017-07-20 15:22:39 -070039 """
40 Description:
41 Clean up the mininet using stopNet and verify it.
42 Required:
43 * Mininet - mininet driver to use
44 * timeout - time out of mininet.stopNet.
45 Returns:
46 Returns main.TRUE if successfully stopping minient.
47 else returns main.FALSE
48 """
Devin Lim58046fa2017-07-05 16:55:00 -070049 main.step( "Stopping Mininet" )
Devin Lima7cfdbd2017-09-29 15:02:22 -070050 topoResult = Mininet.stopNet( timeout=timeout, exitTimeout=exitTimeout )
Devin Lim58046fa2017-07-05 16:55:00 -070051 utilities.assert_equals( expect=main.TRUE,
52 actual=topoResult,
53 onpass="Successfully stopped mininet",
54 onfail="Failed to stopped mininet" )
55 return topoResult
56
Jon Halla7b27e62021-06-29 12:13:51 -070057 def copyKarafLog( self, copyFileName="", before=False, includeCaseDesc=True,
58 useStern=False, startTime=None ):
Devin Lim58046fa2017-07-05 16:55:00 -070059 """
Devin Lim142b5342017-07-20 15:22:39 -070060 Description:
61 copy the karaf log and verify it.
62 Required:
63 * copyFileName - name of the end portion of the
64 copyFileName.
65 Returns:
Devin Lim58046fa2017-07-05 16:55:00 -070066 """
Jon Halla7b27e62021-06-29 12:13:51 -070067 import datetime
68 import math
Jon Hallca319892017-06-15 15:25:22 -070069 # TODO: Also grab the rotated karaf logs
Devin Lim58046fa2017-07-05 16:55:00 -070070 main.log.report( "Copy karaf logs" )
Devin Lim0c972b72018-02-08 14:53:59 -080071 if includeCaseDesc:
72 main.case( "Copy karaf logs" )
73 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
74 "reinstalling ONOS"
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.step( "Copying karaf logs" )
76 stepResult = main.TRUE
77 scpResult = main.TRUE
78 copyResult = main.TRUE
Jon Hall06fd0df2021-01-25 15:50:06 -080079 isKube = False
Devin Lim142b5342017-07-20 15:22:39 -070080 for ctrl in main.Cluster.runningNodes:
Jon Hall06fd0df2021-01-25 15:50:06 -080081 if ctrl.k8s:
82 isKube = True
83 continue
84 elif ctrl.inDocker:
Jon Hall3c0114c2020-08-11 15:07:42 -070085 scpResult = scpResult and ctrl.server.dockerCp( ctrl.name,
86 "/opt/onos/log/karaf.log",
87 "/tmp/karaf.log",
88 direction="from" )
89 scpResult = scpResult and main.ONOSbench.scp( ctrl.server,
90 "/tmp/karaf.log",
91 "/tmp/karaf.log",
92 direction="from" )
93 else:
You Wang327bad42021-03-24 14:19:58 -070094 scpResult = scpResult and main.ONOSbench.scp( ctrl.server,
Jon Hall3c0114c2020-08-11 15:07:42 -070095 "/opt/onos/log/karaf.log",
96 "/tmp/karaf.log",
97 direction="from" )
Devin Lim58046fa2017-07-05 16:55:00 -070098 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
Devin Lim0c972b72018-02-08 14:53:59 -080099 copyFileName=( copyFileName + "_karaf.log." +
100 ctrl.name + "_" ) if before else
101 ( "karaf.log." + ctrl.name +
102 "." + copyFileName ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700103 if scpResult and copyResult:
104 stepResult = main.TRUE and stepResult
105 else:
106 stepResult = main.FALSE and stepResult
Jon Hall06fd0df2021-01-25 15:50:06 -0800107 if isKube:
Jon Hall06fd0df2021-01-25 15:50:06 -0800108 # We also need to save the pod name to switch name mapping
109 main.ONOSbench.kubectlPodNodes( dstPath=main.logdir + "/podMapping.txt",
110 kubeconfig=ctrl.k8s.kubeConfig,
111 namespace=main.params[ 'kubernetes' ][ 'namespace' ] )
Jon Hall06fd0df2021-01-25 15:50:06 -0800112 # Save image for pods, based on "describe pods"
113 main.ONOSbench.kubectlDescribe( "pods",
114 main.logdir + "/describePods.txt",
115 kubeconfig=ctrl.k8s.kubeConfig,
116 namespace=main.params[ 'kubernetes' ][ 'namespace' ] )
117 # Get the pod logs
118 pods = main.ONOSbench.kubectlGetPodNames( kubeconfig=ctrl.k8s.kubeConfig,
119 namespace=main.params[ 'kubernetes' ][ 'namespace' ] )
120
Jon Halla7b27e62021-06-29 12:13:51 -0700121 MINUTE = datetime.timedelta( minutes=1 )
Jon Hall06fd0df2021-01-25 15:50:06 -0800122 for pod in pods:
Jon Hall66ce22f2021-06-30 14:57:40 -0700123 path = "%s/%s_%s.log" % ( main.logdir, copyFileName, pod )
Jon Halla7b27e62021-06-29 12:13:51 -0700124 if useStern:
Jon Hall66ce22f2021-06-30 14:57:40 -0700125 wait=10
126 if "onos-classic" in pod:
127 wait=30
128 elif "stratum" in pod:
129 wait=30
130 else:
131 main.log.debug( "Skipping fetch logs for %s" % pod )
132 continue
Jon Halla7b27e62021-06-29 12:13:51 -0700133 if startTime:
134 now = datetime.datetime.utcnow()
135 duration = ( now - startTime ) + MINUTE
136 since = "%ss" % int( math.ceil( duration.total_seconds() ) )
137 else:
138 since = "1h"
139 podResults = main.ONOSbench.sternLogs( pod,
140 path,
141 kubeconfig=ctrl.k8s.kubeConfig,
142 namespace=main.params[ 'kubernetes' ][ 'namespace' ],
143 since=since,
Jon Hall66ce22f2021-06-30 14:57:40 -0700144 wait=wait )
Jon Halla7b27e62021-06-29 12:13:51 -0700145 else:
146 podResults = main.ONOSbench.kubectlLogs( pod,
147 path,
148 kubeconfig=ctrl.k8s.kubeConfig,
149 namespace=main.params[ 'kubernetes' ][ 'namespace' ] )
150 stepResult = stepResult and podResults
Devin Lim58046fa2017-07-05 16:55:00 -0700151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="Successfully copied remote ONOS logs",
Jon Hallca319892017-06-15 15:25:22 -0700154 onfail="Failed to copy remote ONOS logs" )