예제 #1
0
 def create_ssh_connection_to_instance(self, instance, retry=10):
     proxy_machine = self.get_proxy_machine(instance)
     ssh = None
     attempts = 0
     elapsed = 0
     next_retry_time = 10
     start = time.time()
     proxy_keypath = proxy_machine.machine.ssh.keypath or None
     while not ssh and attempts < retry:
         attempts += 1
         elapsed = int(time.time() - start)
         self.debug('Attempting to ssh to instances private ip:' +
                    str(instance.private_ip_address) +
                    'through the cc ip:' + str(proxy_machine.hostname) +
                    ', attempts:' + str(attempts) + "/" + str(retry) +
                    ", elapsed:" + str(elapsed))
         try:
             ssh = SshConnection(
                 host=instance.private_ip_address,
                 keypath=instance.keypath,
                 proxy=proxy_machine.hostname,
                 proxy_username=proxy_machine.machine.ssh.username,
                 proxy_password=proxy_machine.machine.ssh.password,
                 proxy_keypath=proxy_keypath)
         except Exception, ce:
             tb = self.tester.get_traceback()
             if attempts >= retry:
                 self.debug("\n" + tb, linebyline=False)
             self.debug('Failed to connect error:' + str(ce))
         if attempts < retry:
             time.sleep(next_retry_time)
예제 #2
0
 def connect(self):
     '''
     Attempts to connect to the SAN cli via ssh
     '''
     ssh = SshConnection(host=self.host,
                         username=self.username,
                         password=self.password)
     if not ssh:
         raise Exception('Could not connect to SAN at:' + str(self.host))
     self.sys = ssh.sys
     return ssh
예제 #3
0
    def __init__(self):
        self.setuptestcase()
        self.setup_parser(testname='Mpath_monkey',
                          vmtype=False,
                          zone=False,
                          keypair=False,
                          emi=False,
                          credpath=False,
                          description='Run multipath failover script')
        self.parser.add_argument(
            '--clear_rules',
            help=
            'If set will clear all eutester applied rules matching ipt_msg string',
            action='store_true',
            default=False)
        self.parser.add_argument(
            '--host',
            help='String representing host address or FQDN',
            default=None)
        self.parser.add_argument('--clear_on_exit',
                                 help='If set will clear rules on exit',
                                 action='store_true',
                                 default=False)
        self.parser.add_argument(
            '--username',
            help='String representing username for host login, default:root',
            default='root')
        self.parser.add_argument(
            '--keypath',
            help='String representing local path to host ssh key',
            default=None)
        self.parser.add_argument(
            '--interval',
            help='Integer representing seconds between path failover',
            default=30)
        self.parser.add_argument(
            '--restore_time',
            help='Integer representing seconds to allow path recovery',
            default=30)
        self.parser.add_argument('--sp_ip_list',
                                 help='String with SP addrs, comma delimited',
                                 default="10.109.25.186,192.168.25.182")

        self.get_args()

        self.ssh = SshConnection(self.args.host,
                                 keypath=self.args.keypath,
                                 password=self.args.password,
                                 username=self.args.username,
                                 debugmethod=self.debug,
                                 verbose=True)
        self.sys = self.ssh.sys
        self.cmd = self.ssh.cmd
        self.interval = int(self.args.interval)
        self.restore_time = int(self.args.restore_time)
        self.start = time.time()

        self.sp_ip_list = []
        print self.args.sp_ip_list
        if self.args.sp_ip_list:

            self.args.sp_ip_list = str(self.args.sp_ip_list).split(',')
            for ip in self.args.sp_ip_list:
                ip = str(ip).lstrip().rstrip()
                print 'adding ip to sp_ip_list:' + str(ip)
                self.sp_ip_list.append(ip)
        self.timer = None
예제 #4
0
from eutester.eulogger import Eulogger
import re
import subprocess
keypath = '/root/.ssh/id_rsa.pub'

p = subprocess.Popen('cat {0}'.format(keypath), shell=True,
                     stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
pub_key = p.stdout.read()
result = p.wait()
if result:
    raise RuntimeError('Error reading in key at: "{0}", errcode:{1}'.format(keypath, result))

with open('config_data') as config_data:
    lines = config_data.readlines()

ipset = set([])
ip_regex = re.compile("(^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})")

for line in lines:
    match = ip_regex.match(line)
    if match:
        ipset.add(match.groups()[0])

logger = Eulogger()

for ip in ipset:
    logger = Eulogger(identifier=ip)
    ssh = SshConnection(host=ip, password='******', debugmethod=logger.log.debug)
    ssh.sys("echo " + pub_key + " >> ~/.ssh/authorized_keys", code=0, verbose=True)

예제 #5
0
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
pub_key = p.stdout.read()
result = p.wait()
if result:
    raise RuntimeError('Error reading in key at: "{0}", errcode:{1}'.format(
        keypath, result))

with open('config_data') as config_data:
    lines = config_data.readlines()

ipset = set([])
ip_regex = re.compile("(^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})")

for line in lines:
    match = ip_regex.match(line)
    if match:
        ipset.add(match.groups()[0])

logger = Eulogger()

for ip in ipset:
    logger = Eulogger(identifier=ip)
    ssh = SshConnection(host=ip,
                        password='******',
                        debugmethod=logger.log.debug)
    ssh.sys("echo " + pub_key + " >> ~/.ssh/authorized_keys",
            code=0,
            verbose=True)
예제 #6
0
 def __init__(self, 
               proxy_hostname,  #192.168.23.9
               proxy_username = '******',
               proxy_password = None, 
               proxy_keypath = None,
               timeout = 120,
               retry = 2, 
               debugmethod = None,
               verbose = True,
               win_instance = None,
               win_keypath = None,
               win_password = None ):
     '''
     Description: Help class to execute remote powershell cmdlets over an ssh connection in order to 
                 test Windows Instance functionality within the cloud.
                 
     :type proxy_host: string
     :param proxy_host: The ip address or FQDN hostname of the windows server to connect via ssh, and exectute the powershell commands on.
     
     :type proxy_username: string
     :param proxy_username: The username used for created the remote ssh session, and executing the powershell cmdlets
     
     :type proxy_password: string
     :param proxy_passwrd: The password used fro creating the remote ssh session. 
     
     :type proxy_keypath: string
     :param proxy_keypath: The path to the ssh keyfile used for establishing the ssh session to the remote powershell server. 
     
     :type timeout: integer
     :param timeout: Timeout to be used as a default for method timeouts. ie  timeout used for establising an ssh session to powershell server. 
     
     :type retry:
     :param retry: Used to define the amount of times to retry a failed method before giving up. 
     
     :type debugmethod: method
     :param debugmethod: A method which can be pass and used for self.debug
     
     :type verbose: boolean
     :param verbose: A boolean to flag on or off debug messages. 
     
     :type win_instance: instance object
     :param win_instance: instance object used as the default target for running tests against
     
     :type win_keypath: string
     :param win_keypath: A string representing the path to the keyfile used when launching the win_instance instance. 
                         This is used for building the password to win_instance if necessarry. 
                         See ec2ops for get_windows_instance_password method
     
     :type win_password: string
     :param win_password: The cloud generated password associated with win_instance. See ec2ops for get_windows_instance_password method
      
     '''
     
     self.proxy_hostname = proxy_hostname
     self.proxy_username = proxy_username or 'Administrator'
     self.proxy_password = proxy_password
     self.proxy_keypath = proxy_keypath
     self.timeout = timeout
     self.retry = retry
     self.verbose = verbose
     self.win_instance = win_instance
     self.win_keypath = win_keypath
     self.win_password = win_password
     self.debugmethod = debugmethod
     if self.debugmethod is None:
         logger = Eulogger(identifier= 'winproxy'+ str(proxy_hostname) + ":")
         self.debugmethod = logger.log.debug
         
     #setup ssh connection to power shell proxy server
     self.ssh = SshConnection( proxy_hostname, keypath=proxy_keypath, password=proxy_password, username=proxy_username, 
                                             timeout=timeout, retry=retry,debugmethod=self.debugmethod, verbose=True)
     self.sys = self.ssh.sys
     self.cmd = self.ssh.cmd
예제 #7
0
class WindowsProxyTests():
     
    def __init__(self, 
                  proxy_hostname,  #192.168.23.9
                  proxy_username = '******',
                  proxy_password = None, 
                  proxy_keypath = None,
                  timeout = 120,
                  retry = 2, 
                  debugmethod = None,
                  verbose = True,
                  win_instance = None,
                  win_keypath = None,
                  win_password = None ):
        '''
        Description: Help class to execute remote powershell cmdlets over an ssh connection in order to 
                    test Windows Instance functionality within the cloud.
                    
        :type proxy_host: string
        :param proxy_host: The ip address or FQDN hostname of the windows server to connect via ssh, and exectute the powershell commands on.
        
        :type proxy_username: string
        :param proxy_username: The username used for created the remote ssh session, and executing the powershell cmdlets
        
        :type proxy_password: string
        :param proxy_passwrd: The password used fro creating the remote ssh session. 
        
        :type proxy_keypath: string
        :param proxy_keypath: The path to the ssh keyfile used for establishing the ssh session to the remote powershell server. 
        
        :type timeout: integer
        :param timeout: Timeout to be used as a default for method timeouts. ie  timeout used for establising an ssh session to powershell server. 
        
        :type retry:
        :param retry: Used to define the amount of times to retry a failed method before giving up. 
        
        :type debugmethod: method
        :param debugmethod: A method which can be pass and used for self.debug
        
        :type verbose: boolean
        :param verbose: A boolean to flag on or off debug messages. 
        
        :type win_instance: instance object
        :param win_instance: instance object used as the default target for running tests against
        
        :type win_keypath: string
        :param win_keypath: A string representing the path to the keyfile used when launching the win_instance instance. 
                            This is used for building the password to win_instance if necessarry. 
                            See ec2ops for get_windows_instance_password method
        
        :type win_password: string
        :param win_password: The cloud generated password associated with win_instance. See ec2ops for get_windows_instance_password method
         
        '''
        
        self.proxy_hostname = proxy_hostname
        self.proxy_username = proxy_username or 'Administrator'
        self.proxy_password = proxy_password
        self.proxy_keypath = proxy_keypath
        self.timeout = timeout
        self.retry = retry
        self.verbose = verbose
        self.win_instance = win_instance
        self.win_keypath = win_keypath
        self.win_password = win_password
        self.debugmethod = debugmethod
        if self.debugmethod is None:
            logger = Eulogger(identifier= 'winproxy'+ str(proxy_hostname) + ":")
            self.debugmethod = logger.log.debug
            
        #setup ssh connection to power shell proxy server
        self.ssh = SshConnection( proxy_hostname, keypath=proxy_keypath, password=proxy_password, username=proxy_username, 
                                                timeout=timeout, retry=retry,debugmethod=self.debugmethod, verbose=True)
        self.sys = self.ssh.sys
        self.cmd = self.ssh.cmd


    def debug(self,msg):
        '''
        Used to print debug, defaults to print() but over ridden by self.debugmethod if not None
        msg - mandatory -string, message to be printed
        '''
        if ( self.verbose is True ):
            if self.debugmethod:
                self.debugmethod(msg)
            else:
                print(msg)
    def reset_ssh(self):
        self.ssh.close()
        self.ssh.refresh_connection()

    
    def ps_cmd(self, 
               hostname, 
               password,
               ps1source = '. C:\eutester_profile.ps1;', 
               command=None,
               cmdprefix=None, 
               listformat=False, 
               retries=1, 
               retryinterval=10, 
               cmdtimeout=30, 
               pscb = None,
               exitcode=0,
               timeout=360):
        '''
        Description: Issues a powershell command on a remote windows server over ssh. (ie the windows server is running cygwin, etc).
                    Send command over ssh connection to power shell proxy server. Proxy server then excutes Power shell command
                    against 'hostname' using 'password'. Checks for ssh errors, and command exit status code.  
                    the command. 
                    Returns the command output in either a single string buffer or list of lines depending on 'listformat' setting. 
                    
        :type hostname: string
        :param hostname: mandatory - string, hostname or ip addr of instance
        
        :type password: string
        :param password: mandatory - string, windows Administrator password derived from instance
        
        :type ps1source: string
        :param ps1source: optional - string, in ". <filename;" form. A prefix to source a given powershell script for cmdlets default: '. C:\eutester_profile.ps1;'
        
        :type command: string
        :param command: optional - string, command/cmdlet to run after the login sequence. 
        
        :type cmdprefix: string
        :param cmdprefix: optional - string, command prefix to run other than default login sequence 
        
        :type listformat: boolean
        :param listformat: optional - boolean, indicate whether or not returned string buffer is split per lines in a list or single buffer  
        
        :type retries: integer
        :param retries: optional - integer, number of times to retry this command after failure  
        
        :type retryinterval: integer
        :param retryinterval: optional - integer, number of seconds to sleep between retries after failure 
        
        :type cmdtimeout: integer
        :param cmdtimeout: optional - integer,  number of seconds to wait before giving up on each command retry
        
        :type exitcode: integer
        :param exitcode: optional - integer, exit code to check remote command return value against, default = 0. 
        
        :type pscb: method
        :param pscb: optional - callback to handle per line output of command, default is: self.check_pshell_output used to fail fast on remote powershell errors
        
        :type timeout: integer
        :param timeout: optional - integer, number of seconds to wait before giving up on this method (sum of all retries)
        
        :rtype: string
        :returns: The string buffer containing stdout/err of the remote powershell session. 
        '''
        start = time.time()
        elapsed = 0
        #if pscb is None:
        #    pscb = self.check_pshell_output
        #if no command is provided assume only the prefix is run, usually to test login. 
        if command is None:
            loginoutput=';'
            command = ""
        else:
            loginoutput=' | out-null;'
        
        if cmdprefix is None:
                #Build the power shell command to run on remote proxy...
                cmdprefix = 'echo "\n" | powershell -command "&{'+str(ps1source)+' Eutester-New-Euca-QA -hostname ' + hostname + ' ; Eutester-Test-Euca-Login -hostname ' + hostname + ' -password ' + password + loginoutput
        cmd = cmdprefix + str(command) + '}"'
        
        #Attempt to run the command until number of retries is exceeded...
        for attempt in xrange(0,retries):
            self.debug('ps_cmd: cmd:"'+str(cmd)+'", attempt:'+str(attempt)+'/'+str(retries)+', elapsed:'+str(elapsed))
            try:
                try:
                    self.ps_status_msg('    ( Attempt:'+str(attempt)+' )')
                    #
                    output = self.ssh.cmd(cmd,
                                          listformat = listformat,
                                          timeout = cmdtimeout,
                                          cb = pscb )
                    self.debug('Command returned!!!!')
                    self.debug("\nstatus:"+str(output['status']))
                except Exception, e:
                    raise Exception('Error while attempting to execute remote ssh command to proxy,\nError:'+str(e))
                if output['status'] != exitcode:
                    raise Exception('Proxied ssh cmd:"'+str(command)+'", proxy returned error code:'+str(output['status']))
                self.ps_status_msg('Command was successful')
                return output['output']
            except Exception, ae:
                self.ps_status_msg('ps_cmd, attempt:'+str(attempt)+', failed:'+str(ae))
                time.sleep(retryinterval)
            finally:
예제 #8
0
 def __init__(self, 
               proxy_hostname,  #192.168.23.9
               proxy_username = '******',
               proxy_password = None, 
               proxy_keypath = None,
               timeout = 120,
               retry = 2, 
               debugmethod = None,
               verbose = True,
               win_instance = None,
               win_keypath = None,
               win_password = None ):
     '''
     Description: Help class to execute remote powershell cmdlets over an ssh connection in order to 
                 test Windows Instance functionality within the cloud.
                 
     :type proxy_host: string
     :param proxy_host: The ip address or FQDN hostname of the windows server to connect via ssh, and exectute the powershell commands on.
     
     :type proxy_username: string
     :param proxy_username: The username used for created the remote ssh session, and executing the powershell cmdlets
     
     :type proxy_password: string
     :param proxy_passwrd: The password used fro creating the remote ssh session. 
     
     :type proxy_keypath: string
     :param proxy_keypath: The path to the ssh keyfile used for establishing the ssh session to the remote powershell server. 
     
     :type timeout: integer
     :param timeout: Timeout to be used as a default for method timeouts. ie  timeout used for establising an ssh session to powershell server. 
     
     :type retry:
     :param retry: Used to define the amount of times to retry a failed method before giving up. 
     
     :type debugmethod: method
     :param debugmethod: A method which can be pass and used for self.debug
     
     :type verbose: boolean
     :param verbose: A boolean to flag on or off debug messages. 
     
     :type win_instance: instance object
     :param win_instance: instance object used as the default target for running tests against
     
     :type win_keypath: string
     :param win_keypath: A string representing the path to the keyfile used when launching the win_instance instance. 
                         This is used for building the password to win_instance if necessarry. 
                         See ec2ops for get_windows_instance_password method
     
     :type win_password: string
     :param win_password: The cloud generated password associated with win_instance. See ec2ops for get_windows_instance_password method
      
     '''
     
     self.proxy_hostname = proxy_hostname
     self.proxy_username = proxy_username or 'Administrator'
     self.proxy_password = proxy_password
     self.proxy_keypath = proxy_keypath
     self.timeout = timeout
     self.retry = retry
     self.verbose = verbose
     self.win_instance = win_instance
     self.win_keypath = win_keypath
     self.win_password = win_password
     self.debugmethod = debugmethod
     if self.debugmethod is None:
         logger = Eulogger(identifier= 'winproxy'+ str(proxy_hostname) + ":")
         self.debugmethod = logger.log.debug
         
     #setup ssh connection to power shell proxy server
     self.ssh = SshConnection( proxy_hostname, keypath=proxy_keypath, password=proxy_password, username=proxy_username, 
                                             timeout=timeout, retry=retry,debugmethod=self.debugmethod, verbose=True)
     self.sys = self.ssh.sys
     self.cmd = self.ssh.cmd
예제 #9
0
class WindowsProxyTests():
     
    def __init__(self, 
                  proxy_hostname,  #192.168.23.9
                  proxy_username = '******',
                  proxy_password = None, 
                  proxy_keypath = None,
                  timeout = 120,
                  retry = 2, 
                  debugmethod = None,
                  verbose = True,
                  win_instance = None,
                  win_keypath = None,
                  win_password = None ):
        '''
        Description: Help class to execute remote powershell cmdlets over an ssh connection in order to 
                    test Windows Instance functionality within the cloud.
                    
        :type proxy_host: string
        :param proxy_host: The ip address or FQDN hostname of the windows server to connect via ssh, and exectute the powershell commands on.
        
        :type proxy_username: string
        :param proxy_username: The username used for created the remote ssh session, and executing the powershell cmdlets
        
        :type proxy_password: string
        :param proxy_passwrd: The password used fro creating the remote ssh session. 
        
        :type proxy_keypath: string
        :param proxy_keypath: The path to the ssh keyfile used for establishing the ssh session to the remote powershell server. 
        
        :type timeout: integer
        :param timeout: Timeout to be used as a default for method timeouts. ie  timeout used for establising an ssh session to powershell server. 
        
        :type retry:
        :param retry: Used to define the amount of times to retry a failed method before giving up. 
        
        :type debugmethod: method
        :param debugmethod: A method which can be pass and used for self.debug
        
        :type verbose: boolean
        :param verbose: A boolean to flag on or off debug messages. 
        
        :type win_instance: instance object
        :param win_instance: instance object used as the default target for running tests against
        
        :type win_keypath: string
        :param win_keypath: A string representing the path to the keyfile used when launching the win_instance instance. 
                            This is used for building the password to win_instance if necessarry. 
                            See ec2ops for get_windows_instance_password method
        
        :type win_password: string
        :param win_password: The cloud generated password associated with win_instance. See ec2ops for get_windows_instance_password method
         
        '''
        
        self.proxy_hostname = proxy_hostname
        self.proxy_username = proxy_username or 'Administrator'
        self.proxy_password = proxy_password
        self.proxy_keypath = proxy_keypath
        self.timeout = timeout
        self.retry = retry
        self.verbose = verbose
        self.win_instance = win_instance
        self.win_keypath = win_keypath
        self.win_password = win_password
        self.debugmethod = debugmethod
        if self.debugmethod is None:
            logger = Eulogger(identifier= 'winproxy'+ str(proxy_hostname) + ":")
            self.debugmethod = logger.log.debug
            
        #setup ssh connection to power shell proxy server
        self.ssh = SshConnection( proxy_hostname, keypath=proxy_keypath, password=proxy_password, username=proxy_username, 
                                                timeout=timeout, retry=retry,debugmethod=self.debugmethod, verbose=True)
        self.sys = self.ssh.sys
        self.cmd = self.ssh.cmd


    def debug(self,msg):
        '''
        Used to print debug, defaults to print() but over ridden by self.debugmethod if not None
        msg - mandatory -string, message to be printed
        '''
        if ( self.verbose is True ):
            if self.debugmethod:
                self.debugmethod(msg)
            else:
                print(msg)
    def reset_ssh(self):
        self.ssh.refresh_connection()

    
    def ps_cmd(self, 
               hostname, 
               password,
               ps1source = '. C:\eutester_profile.ps1;', 
               command=None,
               cmdprefix=None, 
               listformat=False, 
               retries=1, 
               retryinterval=10, 
               cmdtimeout=30, 
               pscb = None,
               exitcode=0,
               timeout=360):
        '''
        Description: Issues a powershell command on a remote windows server over ssh. (ie the windows server is running cygwin, etc).
                    Send command over ssh connection to power shell proxy server. Proxy server then excutes Power shell command
                    against 'hostname' using 'password'. Checks for ssh errors, and command exit status code.  
                    the command. 
                    Returns the command output in either a single string buffer or list of lines depending on 'listformat' setting. 
                    
        :type hostname: string
        :param hostname: mandatory - string, hostname or ip addr of instance
        
        :type password: string
        :param password: mandatory - string, windows Administrator password derived from instance
        
        :type ps1source: string
        :param ps1source: optional - string, in ". <filename;" form. A prefix to source a given powershell script for cmdlets default: '. C:\eutester_profile.ps1;'
        
        :type command: string
        :param command: optional - string, command/cmdlet to run after the login sequence. 
        
        :type cmdprefix: string
        :param cmdprefix: optional - string, command prefix to run other than default login sequence 
        
        :type listformat: boolean
        :param listformat: optional - boolean, indicate whether or not returned string buffer is split per lines in a list or single buffer  
        
        :type retries: integer
        :param retries: optional - integer, number of times to retry this command after failure  
        
        :type retryinterval: integer
        :param retryinterval: optional - integer, number of seconds to sleep between retries after failure 
        
        :type cmdtimeout: integer
        :param cmdtimeout: optional - integer,  number of seconds to wait before giving up on each command retry
        
        :type exitcode: integer
        :param exitcode: optional - integer, exit code to check remote command return value against, default = 0. 
        
        :type pscb: method
        :param pscb: optional - callback to handle per line output of command, default is: self.check_pshell_output used to fail fast on remote powershell errors
        
        :type timeout: integer
        :param timeout: optional - integer, number of seconds to wait before giving up on this method (sum of all retries)
        
        :rtype: string
        :returns: The string buffer containing stdout/err of the remote powershell session. 
        '''
        start = time.time()
        elapsed = 0
        #if pscb is None:
        #    pscb = self.check_pshell_output
        #if no command is provided assume only the prefix is run, usually to test login. 
        if command is None:
            loginoutput=';'
            command = ""
        else:
            loginoutput=' | out-null;'
        
        if cmdprefix is None:
                #Build the power shell command to run on remote proxy...
                cmdprefix = 'echo "\n" | powershell -command "&{'+str(ps1source)+' Eutester-New-Euca-QA -hostname ' + hostname + ' ; Eutester-Test-Euca-Login -hostname ' + hostname + ' -password ' + password + loginoutput
        cmd = cmdprefix + str(command) + '}"'
        
        #Attempt to run the command until number of retries is exceeded...
        attempt=0
        for attempt in xrange(0,retries):
            self.debug('ps_cmd: cmd:"'+str(repr(cmd))+'", attempt:'+str(attempt)+'/'+str(retries)+', elapsed:'+str(elapsed))
            try:
                try:
                    self.ps_status_msg('    ( Attempt:'+str(attempt)+' )')
                    #
                    output = self.ssh.cmd(cmd,
                                          listformat = listformat,
                                          timeout = cmdtimeout,
                                          cb = pscb )
                    self.debug('Command returned!!!!')
                    self.debug("\nstatus:"+str(output['status']))
                except Exception, e:
                    raise Exception('Error while attempting to execute remote ssh command to proxy,\nError:'+str(e))
                if output['status'] != exitcode:
                    raise Exception('Proxied ssh cmd:"'+str(command)+'", proxy returned error code:'+str(output['status']))
                self.ps_status_msg('Command was successful')
                return output['output']
            except Exception, ae:
                self.ps_status_msg('ps_cmd, attempt:'+str(attempt)+', failed:'+str(ae))
                if (attempt+1 < retries):
                    time.sleep(retryinterval)
            finally:
예제 #10
0
    def __init__(self,
                 node=None,
                 queue=None,
                 interval=None,
                 restore_time=None,
                 sp_ip_list=None,
                 path_iterations=None):
        self.queue = queue or my_queue
        self.setuptestcase()
        if not (node or queue or sp_ip_list):
            self.setup_parser(testname='Path_Controller', vmtype=False,zone=False, keypair=False,emi=False,credpath=False,
                              description='Run multipath failover script')
            self.parser.add_argument('--clear_rules', help='If set will clear all eutester applied rules matching ipt_msg string',action='store_true', default=False)
            self.parser.add_argument('--hostname', help='String representing host address or FQDN',default=None)
            self.parser.add_argument('--clear_on_exit', help='If set will clear rules on exit',action='store_true', default=False)
            self.parser.add_argument('--username', help='String representing username for host login, default:root',default='root')
            self.parser.add_argument('--keypath', help='String representing local path to host ssh key',default=None)
            self.parser.add_argument('--interval', help='Integer representing seconds between path failover',default=30)
            self.parser.add_argument('--restore_time', help='Integer representing seconds to allow path recovery',default=15)
            self.parser.add_argument('--sp_ip_list', help='String with SP addrs, comma delimited',default=None)
            self.parser.add_argument('--path_iterations', help='Number of times to iterate through sp_ip_list when \
                                     blocking paths. "0" loops forever', default=2)
            self.get_args()

        # Allow __init__ to get args from __init__'s kwargs or through command line parser...
        """
        for kw in kwargs:
            print 'Setting kwarg:' + str(kw) + " to " + str(kwargs[kw])
            self.set_arg(kw ,kwargs[kw])
        """

        if self.has_arg('path_iterations'):
            self.path_iterations =  self.args.path_iterations
        else:
            self.path_iterations =  path_iterations or 2
        self.total_path_iterations = 0
        self.node = node
        if self.node:
            self.host = node.hostname
            self.ssh = self.node.machine.ssh
        else:
            self.host = self.args.hostname
            self.ssh = SshConnection(self.args.host,
                                     keypath=self.args.keypath,
                                     password=self.args.password,
                                     username=self.args.username,
                                     debugmethod=self.debug,
                                     verbose=True)
        self.sys = self.ssh.sys
        self.cmd = self.ssh.cmd

        if self.has_arg('interval'):
            self.interval = int(self.args.interval)
        else:
            self.interval = interval or 30

        if self.has_arg('restore_time'):
            self.restore_time = int(self.args.restore_time)
        else:
            self.restore_time = restore_time or 15
        self.start = time.time()
        self.lastblocked = None
        self.blocked = []
        self.get_sp_ip_list(sp_ip_list=sp_ip_list)
        self.timer = None
        self.last_clear_attempt_time = 0
        self.last_cleared_time = 0
        self.last_block_time = 0
        self.debug('Path_Controller init:' \
                    + "\nhost:" + str(self.host) \
                    + "\nsp_ipt_list:" + str(self.sp_ip_list) \
                    + "\ninterval:" + str(self.interval) \
                    + "\nrestore_time:" + str(self.restore_time))
예제 #11
0
파일: junk.py 프로젝트: diderson/se34euca
#!/usr/bin/python
from se34euca.lib.EucaUITestLib_Base import *
from selenium import webdriver
from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from eucaops import Eucaops

import unittest, time, re

from eutester.sshconnection import SshConnection

ssh = SshConnection(host='10.111.5.62', password='******', verbose=True)
print ssh.sys('ls /etc')

#tester = Eucaops(config_file='62.conf', password='******')
예제 #12
0
파일: junk.py 프로젝트: aliceh/se34euca
#!/usr/bin/python
from se34euca.lib.EucaUITestLib_Base import *
from selenium import webdriver
from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from eucaops import Eucaops

import unittest, time, re

from eutester.sshconnection import SshConnection

ssh = SshConnection(host='10.111.5.62', password='******', verbose=True)
print ssh.sys('ls /etc')


#tester = Eucaops(config_file='62.conf', password='******')