Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 2 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3 | Copyright 2016 Open Networking Foundation (ONF) |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 8 | |
| 9 | TestON is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 12 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 13 | |
| 14 | TestON is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 21 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 22 | |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 23 | import json |
| 24 | import os |
| 25 | import re |
| 26 | import subprocess |
| 27 | from docker import Client |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 28 | from docker import errors |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 29 | from drivers.common.apidriver import API |
| 30 | |
| 31 | class DockerApiDriver( API ): |
| 32 | |
| 33 | def __init__( self ): |
| 34 | """ |
| 35 | Initialize client |
| 36 | """ |
| 37 | self.name = None |
| 38 | self.home = None |
| 39 | self.handle = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 40 | super( DockerApiDriver, self ).__init__() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 41 | |
| 42 | def connect( self, **connectargs ): |
| 43 | """ |
| 44 | Create Client handle to connnect to Docker server |
| 45 | """ |
| 46 | try: |
| 47 | for key in connectargs: |
| 48 | vars( self )[ key ] = connectargs[ key ] |
| 49 | self.name = self.options[ 'name' ] |
| 50 | for key in self.options: |
| 51 | if key == "home": |
| 52 | self.home = self.options[ 'home' ] |
| 53 | break |
| 54 | if self.home is None or self.home == "": |
| 55 | self.home = "/var/tmp" |
| 56 | |
| 57 | self.handle = super( DockerApiDriver, self ).connect() |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 58 | self.dockerClient = Client( base_url='unix://var/run/docker.sock' ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 59 | return self.handle |
| 60 | except Exception as e: |
| 61 | main.log.exception( e ) |
| 62 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 63 | def getListOfImages( self, repo="onosproject/onos" ): |
| 64 | """ |
| 65 | Get the list of image tags |
| 66 | """ |
| 67 | try: |
| 68 | imageList = list( self.dockerClient.images( name=repo ) ) |
| 69 | imageListToSend = [] |
Pratik Parab | 50d53d4 | 2017-03-24 14:28:22 -0700 | [diff] [blame] | 70 | duplicateTagDetected = 0 |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 71 | for imageDict in imageList: |
| 72 | if imageDict[ 'RepoTags' ] is not None: |
Pratik Parab | 50d53d4 | 2017-03-24 14:28:22 -0700 | [diff] [blame] | 73 | if len( imageDict[ 'RepoTags' ] ) > 1: |
| 74 | duplicateTagDetected = 1 |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 75 | imageListToSend.append( imageDict[ 'RepoTags' ][ 0 ].encode( 'UTF8' ).split( ':' )[ 1 ] ) |
Pratik Parab | 50d53d4 | 2017-03-24 14:28:22 -0700 | [diff] [blame] | 76 | return imageListToSend, duplicateTagDetected |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 77 | except Exception as e: |
| 78 | main.log.exception( e ) |
| 79 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 80 | def dockerPull( self, onosRepo ="onosproject/onos", onosTag="latest" ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 81 | """ |
| 82 | Pulls Docker image from repository |
| 83 | """ |
| 84 | try: |
| 85 | main.log.info( self.name + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 86 | ": Pulling Docker image " + onosRepo + ":" + onosTag ) |
| 87 | for line in self.dockerClient.pull( repository = onosRepo, |
| 88 | tag = onosTag, stream = True ): |
| 89 | print "#", |
| 90 | main.log.info( json.dumps( json.loads( line ), indent =4 )) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 91 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 92 | # response = json.dumps( json.load( pullResult ), indent=4 ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 93 | if re.search( "for onosproject/onos:" + onosTag, line ): |
| 94 | main.log.info( "onos docker image pulled is: " + line ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 95 | return main.TRUE |
| 96 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 97 | main.log.error( "Failed to download image from: " + onosRepo + ":" + onosTag ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 98 | main.log.error( "Error respone: " ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 99 | main.log.error( line ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 100 | return main.FALSE |
| 101 | except Exception: |
| 102 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 103 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 104 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 105 | def dockerCreateCT( self, onosImage="onosproject/onos:latest", onosNode="onos1" ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 106 | """ |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 107 | Create a Docker container with a specific image |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 108 | """ |
| 109 | try: |
| 110 | main.log.info( self.name + |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 111 | ": Creating Docker container for node: " + onosNode ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 112 | response = self.dockerClient.create_container( image=onosImage, |
| 113 | tty=True, name=onosNode, detach=True ) |
| 114 | # print response |
| 115 | # print response.get("Id") |
| 116 | # print response.get("Warnings") |
| 117 | if( str( response.get( "Warnings" ) ) == 'None' ): |
| 118 | main.log.info( "Created container for node: " + onosNode + "; container id is: " + response.get( "Id" ) ) |
| 119 | return( main.TRUE, response.get( "Id" ) ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 120 | else: |
| 121 | main.log.info( "Noticed warnings during create" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 122 | return( main.FALSE, null ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 123 | except Exception: |
| 124 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 125 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 126 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 127 | def dockerStartCT( self, ctID ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 128 | """ |
| 129 | Start Docker container |
| 130 | """ |
| 131 | try: |
| 132 | main.log.info( self.name + |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 133 | ": Starting Docker conatiner Id " + ctID ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 134 | response = self.dockerClient.start( container = ctID ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 135 | if response is None: |
| 136 | main.log.info( "Started container for Id: " + ctID ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 137 | return main.TRUE |
| 138 | else: |
| 139 | main.log.info( "Noticed warnings during start" ) |
| 140 | return main.FALSE |
| 141 | except Exception: |
| 142 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 143 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 144 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 145 | def dockerStopCT( self, ctName ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 146 | """ |
| 147 | Stop docker container |
| 148 | """ |
| 149 | try: |
| 150 | main.log.info( self.name + |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 151 | ": Stopping Docker conatiner for node " + ctName ) |
| 152 | response = self.dockerClient.stop( ctName ) |
| 153 | if response is None: |
| 154 | main.log.info( "Stopped container for node: " + ctName ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 155 | return main.TRUE |
| 156 | else: |
| 157 | main.log.info( "Noticed warnings during stop" ) |
| 158 | return main.FALSE |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 159 | except errors.NotFound: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 160 | main.log.info( ctName + " not found! Continue on tests..." ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 161 | return main.TRUE |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 162 | except Exception: |
| 163 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 164 | # main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 165 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 166 | def dockerRestartCT( self, ctName ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 167 | """ |
| 168 | Restart Docker container |
| 169 | """ |
| 170 | try: |
| 171 | main.log.info( self.name + |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 172 | ": Restarting Docker conatiner for node " + ctName ) |
| 173 | response = self.dockerClient.restart( ctName ) |
| 174 | if response is None: |
| 175 | main.log.info( "Restarted container for node: " + ctName ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 176 | return main.TRUE |
| 177 | else: |
| 178 | main.log.info( "Noticed warnings during Restart" ) |
| 179 | return main.FALSE |
| 180 | except Exception: |
| 181 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 182 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 183 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 184 | def dockerCheckCTName( self, ctName ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 185 | """ |
| 186 | Check Docker conatiner status |
| 187 | """ |
| 188 | try: |
| 189 | main.log.info( self.name + |
Jon Hall | 3dbc7dc | 2015-12-01 12:11:42 -0800 | [diff] [blame] | 190 | ": Checking Docker Status for CT with 'Names' " + ctName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 191 | namelist = [ response[ "Names" ] for response in self.dockerClient.containers( all=True ) if not [] ] |
| 192 | main.log.info( "Name list is: " + str( namelist ) ) |
| 193 | if( [ ctName ] in namelist ): |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 194 | main.log.info( "Container " + ctName + " exists" ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 195 | return main.TRUE |
| 196 | else: |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 197 | main.log.info( "Container " + ctName + " does not exist" ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 198 | return main.FALSE |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 199 | except errors.NotFound: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 200 | main.log.warn( ctName + "not found! Continue with the tests..." ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 201 | return main.FALSE |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 202 | except Exception: |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 203 | main.log.exception( self.name + ": Uncaught exception! Continue tests..." ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 204 | # main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 205 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 206 | def dockerRemoveCT( self, ctName ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 207 | """ |
| 208 | Remove Docker conatiner |
| 209 | """ |
| 210 | try: |
| 211 | main.log.info( self.name + |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 212 | ": Removing Docker container for node " + ctName ) |
| 213 | response = self.dockerClient.remove_container( ctName, force=True ) |
| 214 | if response is None: |
| 215 | main.log.info( "Removed container for node: " + ctName ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 216 | return main.TRUE |
| 217 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 218 | main.log.info( "Noticed warnings during Remove " + ctName ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 219 | return main.FALSE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 220 | main.log.exception( self.name + ": not found, continuing..." ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 221 | except errors.NotFound: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 222 | main.log.warn( ctName + "not found! Continue with the tests..." ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 223 | return main.TRUE |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 224 | except Exception: |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 225 | main.log.exception( self.name + ": Uncaught exception! Continuing..." ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 226 | # main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 227 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 228 | def dockerRemoveImage( self, imageRepoTag=None ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 229 | """ |
| 230 | Remove Docker image |
| 231 | """ |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 232 | rmResult = main.TRUE |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 233 | if self.dockerClient.images() is []: |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 234 | main.log.info( "No docker image found" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 235 | return rmResult |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 236 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 237 | imageList = [ image[ "Id" ] for image in self.dockerClient.images() |
| 238 | if image[ "RepoTags" ] is None |
| 239 | or imageRepoTag in image[ "RepoTags" ] ] |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 240 | for id in imageList: |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 241 | try: |
| 242 | main.log.info( self.name + ": Removing Docker image " + id ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 243 | response = self.dockerClient.remove_image( id, force = True ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 244 | if response is None: |
| 245 | main.log.info( "Removed Docker image: " + id ) |
| 246 | rmResult = rmResult and main.TRUE |
| 247 | else: |
| 248 | main.log.info( "Noticed warnings during Remove " + id ) |
| 249 | rmResult = rmResult and main.FALSE |
| 250 | except errors.NotFound: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 251 | main.log.warn( image + "not found! Continue with the tests..." ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 252 | rmResult = rmResult and main.TRUE |
| 253 | except Exception: |
| 254 | main.log.exception( self.name + ": Uncaught exception! Continuing..." ) |
| 255 | rmResult = rmResult and main.FALSE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 256 | # main.cleanAndExit() |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 257 | return rmResult |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 258 | |
| 259 | def fetchLatestClusterFile( self, branch="master" ): |
| 260 | """ |
| 261 | Fetch onos-form-cluster file from a particular branch |
| 262 | """ |
| 263 | try: |
| 264 | command = "wget -N https://raw.githubusercontent.com/opennetworkinglab/\ |
| 265 | onos/" + branch + "/tools/package/bin/onos-form-cluster" |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 266 | subprocess.call( command ) # output checks are missing for now |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 267 | command = "chmod u+x " + "onos-form-cluster" |
| 268 | subprocess.call( command ) |
| 269 | return main.TRUE |
| 270 | except Exception: |
| 271 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 272 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 273 | |
Jon Hall | 321a457 | 2016-05-04 15:28:25 -0700 | [diff] [blame] | 274 | def onosFormCluster( self, onosIPs, cmdPath, user="karaf", passwd="karaf" ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 275 | """ |
| 276 | From ONOS cluster for IP addresses in onosIPs list |
| 277 | """ |
| 278 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 279 | onosIPs = " ".join( onosIPs ) |
Jon Hall | 321a457 | 2016-05-04 15:28:25 -0700 | [diff] [blame] | 280 | command = "{}/onos-form-cluster -u {} -p {} {}".format( cmdPath, |
| 281 | user, |
| 282 | passwd, |
suibin zhang | 1ab833b | 2016-05-12 12:10:11 -0700 | [diff] [blame] | 283 | onosIPs ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 284 | result = subprocess.call( command, shell=True ) |
| 285 | if result == 0: |
| 286 | return main.TRUE |
| 287 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 288 | main.log.info( "Something is not right in forming cluster>" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 289 | return main.FALSE |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 290 | except Exception: |
| 291 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 292 | main.cleanAndExit() |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 293 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 294 | def dockerIP( self, ctName ): |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 295 | """ |
| 296 | Fetch IP address assigned to specified node/container |
| 297 | """ |
| 298 | try: |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 299 | output = self.dockerClient.inspect_container( ctName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 300 | nodeIP = output[ 'NetworkSettings' ][ 'IPAddress' ] |
| 301 | main.log.info( " Docker IP " + str( nodeIP ) ) |
| 302 | return str( nodeIP ) |
Hari Krishna | 6031b7c | 2015-09-28 17:46:29 -0700 | [diff] [blame] | 303 | |
| 304 | except Exception: |
| 305 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 306 | main.cleanAndExit() |