Example #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)
Example #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
Example #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
Example #4
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)
Example #5
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
Example #6
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))
Example #7
0
#!/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='******')