Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 12 | |
| 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 Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 21 | class Utils: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 22 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 23 | def __init__( self ): |
| 24 | self.default = '' |
| 25 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 26 | def mininetCleanIntro( self, includeCaseDesc=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 27 | """ |
| 28 | Description: |
| 29 | Introduction information of the mininet clean up |
| 30 | Required: |
| 31 | Returns: |
| 32 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 33 | main.log.report( "Stop Mininet" ) |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 34 | if includeCaseDesc: |
| 35 | main.case( "Stop Mininet" ) |
| 36 | main.caseExplanation = "Stopping the current mininet to start up fresh" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 37 | |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 38 | def mininetCleanup( self, Mininet, timeout=5, exitTimeout=1000 ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 39 | """ |
| 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 Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 49 | main.step( "Stopping Mininet" ) |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 50 | topoResult = Mininet.stopNet( timeout=timeout, exitTimeout=exitTimeout ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 51 | 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 Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 57 | def copyKarafLog( self, copyFileName="", before=False, includeCaseDesc=True, |
| 58 | useStern=False, startTime=None ): |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 59 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 60 | 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 Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 66 | """ |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 67 | import datetime |
| 68 | import math |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 69 | # TODO: Also grab the rotated karaf logs |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 70 | main.log.report( "Copy karaf logs" ) |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 71 | if includeCaseDesc: |
| 72 | main.case( "Copy karaf logs" ) |
| 73 | main.caseExplanation = "Copying the karaf logs to preserve them through" +\ |
| 74 | "reinstalling ONOS" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 75 | main.step( "Copying karaf logs" ) |
| 76 | stepResult = main.TRUE |
| 77 | scpResult = main.TRUE |
| 78 | copyResult = main.TRUE |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 79 | isKube = False |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 80 | for ctrl in main.Cluster.runningNodes: |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 81 | if ctrl.k8s: |
| 82 | isKube = True |
| 83 | continue |
| 84 | elif ctrl.inDocker: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 85 | 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 Wang | 327bad4 | 2021-03-24 14:19:58 -0700 | [diff] [blame] | 94 | scpResult = scpResult and main.ONOSbench.scp( ctrl.server, |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 95 | "/opt/onos/log/karaf.log", |
| 96 | "/tmp/karaf.log", |
| 97 | direction="from" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 98 | copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir, |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 99 | copyFileName=( copyFileName + "_karaf.log." + |
| 100 | ctrl.name + "_" ) if before else |
| 101 | ( "karaf.log." + ctrl.name + |
| 102 | "." + copyFileName ) ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 103 | if scpResult and copyResult: |
| 104 | stepResult = main.TRUE and stepResult |
| 105 | else: |
| 106 | stepResult = main.FALSE and stepResult |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 107 | if isKube: |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 108 | # 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 Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 112 | # 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 Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 121 | MINUTE = datetime.timedelta( minutes=1 ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 122 | for pod in pods: |
Jon Hall | 66ce22f | 2021-06-30 14:57:40 -0700 | [diff] [blame] | 123 | path = "%s/%s_%s.log" % ( main.logdir, copyFileName, pod ) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 124 | if useStern: |
Jon Hall | 66ce22f | 2021-06-30 14:57:40 -0700 | [diff] [blame] | 125 | 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 Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 133 | 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 Hall | 66ce22f | 2021-06-30 14:57:40 -0700 | [diff] [blame] | 144 | wait=wait ) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 145 | 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 Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 151 | utilities.assert_equals( expect=main.TRUE, |
| 152 | actual=stepResult, |
| 153 | onpass="Successfully copied remote ONOS logs", |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 154 | onfail="Failed to copy remote ONOS logs" ) |