Esempio n. 1
0
class Eutester(object):
    def __init__(
        self,
        config_file=None,
        password=None,
        keypath=None,
        credpath=None,
        aws_access_key_id=None,
        aws_secret_access_key=None,
        account="eucalyptus",
        user="******",
        region=None,
        boto_debug=0,
    ):
        """  
        This is the constructor for a eutester object, it takes care of setting up the connections that will be required for a test to run. 
        
        """

        ### Default values for configuration
        self.config_file = config_file
        self.eucapath = "/opt/eucalyptus"
        self.current_ssh = "clc"
        self.boto_debug = boto_debug
        self.ssh = None
        self.sftp = None
        self.clc = None
        self.password = password
        self.keypath = keypath
        self.credpath = credpath
        self.timeout = 30
        self.delay = 0
        self.exit_on_fail = 0
        self.fail_count = 0
        self.start_time = time.time()
        self.key_dir = "./"
        self.account_id = 0000000000001
        self.hypervisor = None
        self.region = RegionInfo()

        ##### Euca Logs
        self.cloud_log_buffer = ""
        self.cc_log_buffer = ""
        self.nc_log_buffer = ""
        self.sc_log_buffer = ""
        self.walrus_log_buffer = ""
        self.logging_thread = False

        ### Eutester logs
        self.logger = eulogger.Eulogger(identifier="EUTESTER")

        self.debug = self.logger.log.debug
        self.critical = self.logger.log.critical
        self.info = self.logger.log.info
        self.logging_thread_pool = []
        ### LOGS to keep for printing later
        self.fail_log = []
        self.running_log = self.logger.log

        ### SSH Channels for tailing log files
        self.cloud_log_channel = None
        self.cc_log_channel = None
        self.nc_log_channel = None

        self.clc_index = 0

        ### If I have a config file
        ### PRIVATE CLOUD
        if self.config_file != None:
            ## read in the config file
            self.debug("Reading config file: " + config_file)
            self.config = self.read_config(config_file)

            ### Set the eucapath
            try:
                if "REPO" in self.config["machines"][0].source:
                    self.eucapath = "/"
            except:
                raise Exception("Could not get REPO info from input file")
            # self.hypervisor = self.get_hypervisor()
            ### No credpath but does have password and an ssh connection to the CLC
            ### Private cloud with root access
            ### Need to get credentials for the user if there arent any passed in
            ### Need to create service manager for user if we have an ssh connection and password
            if self.password != None:
                clc_array = self.get_component_machines("clc")
                self.clc = clc_array[0]
                walrus_array = self.get_component_machines("ws")
                self.walrus = walrus_array[0]

                if self.credpath is None:
                    ### TRY TO GET CREDS ON FIRST CLC if it fails try on second listed clc, if that fails weve hit a terminal condition
                    try:
                        self.debug("Attempting to get credentials and setup sftp")
                        self.sftp = self.clc.ssh.connection.open_sftp()
                        self.credpath = self.get_credentials(account, user)
                        self.debug("Successfully downloaded and synced credentials")
                    except Exception, e:
                        self.debug("Caught an exception when getting credentials from first CLC: " + str(e))
                        ### If i only have one clc this is a critical failure, else try on the other clc
                        if len(clc_array) < 2:
                            raise Exception("Could not get credentials from first CLC and no other to try")
                        self.swap_clc()
                        self.sftp = self.clc.ssh.connection.open_sftp()
                        try:
                            self.credpath = self.get_credentials(account, user)
                        except Exception, e:
                            raise Exception("Could not get credentials from second CLC and no other to try")

                self.service_manager = EuserviceManager(self)
                self.clc = self.service_manager.get_enabled_clc().machine
                self.walrus = self.service_manager.get_enabled_walrus().machine
Esempio n. 2
0
class Eutester(object):
    def __init__(self, config_file=None, password=None, keypath=None, credpath=None, aws_access_key_id=None, aws_secret_access_key = None, account="eucalyptus",  user="******", boto_debug=0):
        """  
        EUCADIR => $eucadir, 
        VERIFY_LEVEL => $verify_level, 
        TOOLKIT => $toolkit, 
        DELAY => $delay, 
        FAIL_COUNT => $fail_count, 
        INPUT_FILE => $input_file, 
        PASSWORD => $password }
        , credpath=None, timeout=30, exit_on_fail=0
        EucaTester takes 2 arguments to their constructor
        1. Configuration file to use
        2. Eucalyptus component to connect to [CLC NC00 SC WS CC00] or a hostname
        3. Password to connect to the host
        4. 
        """
        
        ### Default values for configuration
        self.config_file = config_file 
        self.eucapath = "/opt/eucalyptus"
        self.current_ssh = "clc"
        self.boto_debug = boto_debug
        self.ssh = None
        self.sftp = None
        self.password = password
        self.keypath = keypath
        self.credpath = credpath
        self.timeout = 30
        self.delay = 0
        self.exit_on_fail = 0
        self.fail_count = 0
        self.start_time = time.time()
        self.key_dir = "./"
        self.account_id = 0000000000001
        self.hypervisor = None
        
        ##### Euca Logs 
        self.cloud_log_buffer = ''
        self.cc_log_buffer  = ''
        self.nc_log_buffer = ''
        self.sc_log_buffer = ''
        self.walrus_log_buffer = ''
        self.logging_thread = False
        
        ### Eutester logs
        self.logger = eulogger.Eulogger(identifier="localhost")
        self.debug = self.logger.log.debug
        self.critical = self.logger.log.critical
        self.info = self.logger.log.info
        self.logging_thread_pool = []
        ### LOGS to keep for printing later
        self.fail_log = []
        self.running_log = self.logger.log
        
        ### SSH Channels for tailing log files
        self.cloud_log_channel = None
        self.cc_log_channel= None
        self.nc_log_channel= None
        
        self.clc_index = 0

        ### If I have a config file
        ### PRIVATE CLOUD
        if self.config_file != None:
            ## read in the config file
            self.debug("Reading config file: " + config_file)
            self.config = self.read_config(config_file)
            ### Set the eucapath
            if "REPO" in self.config["machines"][0].source:
                self.eucapath="/"
            #self.hypervisor = self.get_hypervisor()
            ### No credpath but does have password and an ssh connection to the CLC
            ### Private cloud with root access 
            ### Need to get credentials for the user if there arent any passed in
            ### Need to create service manager for user if we have an ssh connection and password
            if (self.password != None):
                self.clc = self.get_component_machines("clc")[self.clc_index]
                if self.credpath is None:
                    ### TRY TO GET CREDS ON FIRST CLC if it fails try on second listed clc, if that fails weve hit a terminal condition
                    try:
                        self.sftp = self.clc.ssh.connection.open_sftp()
                        self.credpath = self.get_credentials(account,user)
                    except Exception, e:
                        self.swap_clc()
                        self.sftp = self.clc.ssh.connection.open_sftp()
                        self.credpath = self.get_credentials(account,user)
                self.service_manager = EuserviceManager(self)
                self.clc = self.service_manager.get_enabled_clc().machine

        ### Pull the access and secret keys from the eucarc
        if (self.credpath != None):         
            aws_access_key_id = self.get_access_key()
            aws_secret_access_key = self.get_secret_key()
                    
        ### If you have credentials for the boto connections, create them
        if (aws_access_key_id != None) and (aws_secret_access_key != None):
           self.ec2 = boto.connect_ec2(aws_access_key_id=aws_access_key_id,
                                        aws_secret_access_key=aws_secret_access_key,
                                        is_secure=False,
                                        api_version = '2009-11-30',
                                        region=RegionInfo(name="eucalyptus", endpoint=self.get_clc_ip()),
                                        port=8773,
                                        path="/services/Eucalyptus",
                                        debug=self.boto_debug)
           self.walrus = boto.connect_s3(aws_access_key_id=aws_access_key_id,
                                          aws_secret_access_key=aws_secret_access_key,
                                          is_secure=False,
                                          host=self.get_walrus_ip(),
                                          port=8773,
                                          path="/services/Walrus",
                                          calling_format=OrdinaryCallingFormat(),
                                          debug=self.boto_debug)
           self.euare = boto.connect_iam(aws_access_key_id=aws_access_key_id,
                                          aws_secret_access_key=aws_secret_access_key,
                                          is_secure=False,
                                          host=self.get_clc_ip(),
                                          port=8773,
                                          path="/services/Euare",
                                          debug=self.boto_debug)