admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 2 | """ |
| 3 | Created on 26-Oct-2012 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 4 | |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 5 | author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 6 | |
| 7 | TestON is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 10 | ( at your option ) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 11 | |
| 12 | TestON is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 18 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 19 | |
| 20 | |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 21 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 22 | import time |
| 23 | import pexpect |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 24 | import struct |
| 25 | import fcntl |
| 26 | import os |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 27 | import sys |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 28 | import signal |
| 29 | import sys |
| 30 | sys.path.append( "../" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 31 | from drivers.common.clidriver import CLI |
| 32 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 33 | |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 34 | class RemoteTestBedDriver( CLI ): |
| 35 | # The common functions for emulator included in RemoteTestBedDriver |
| 36 | |
| 37 | def __init__( self ): |
| 38 | super( CLI, self ).__init__() |
| 39 | |
| 40 | def connect( self, **connectargs ): |
| 41 | for key in connectargs: |
| 42 | vars( self )[ 'vm_' + key ] = connectargs[ key ] |
| 43 | |
| 44 | remote_user_name = main.componentDictionary[ |
| 45 | self.name ][ 'remote_user_name' ] |
| 46 | remote_ip_address = main.componentDictionary[ |
| 47 | self.name ][ 'remote_ip_address' ] |
| 48 | remote_port = main.componentDictionary[ self.name ][ 'remote_port' ] |
| 49 | remote_pwd = main.componentDictionary[ self.name ][ 'remote_pwd' ] |
| 50 | |
| 51 | self.handle = super( |
| 52 | RemoteTestBedDriver, |
| 53 | self ).connect( |
| 54 | user_name=remote_user_name, |
| 55 | ip_address=remote_ip_address, |
| 56 | port=remote_port, |
| 57 | pwd=remote_pwd ) |
| 58 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 59 | if self.handle: |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 60 | self.execute( cmd="\n", prompt="\$|>|#", timeout=10 ) |
| 61 | self.execute( cmd="SET CYGWIN=notty", prompt="\$|>|#", timeout=10 ) |
| 62 | self.execute( cmd="\n", prompt="\$|>|#", timeout=10 ) |
| 63 | main.log.info( |
| 64 | "ssh " + |
| 65 | self.vm_user_name + |
| 66 | '@' + |
| 67 | self.vm_ip_address ) |
| 68 | self.execute( |
| 69 | cmd="ssh " + |
| 70 | self.vm_user_name + |
| 71 | '@' + |
| 72 | self.vm_ip_address, |
| 73 | prompt="(.*)", |
| 74 | timeout=10 ) |
| 75 | self.execute( cmd="\n", prompt="assword:", timeout=10 ) |
| 76 | self.execute( cmd=self.vm_pwd, prompt="\$", timeout=10 ) |
| 77 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 78 | return self.handle |
kelvin-onlab | b87672e | 2015-01-16 10:58:34 -0800 | [diff] [blame] | 79 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 80 | return main.FALSE |