Beispiel #1
0
    def do_terminate(self, ntry, params):
        """
        Terminate stage of testing

        @param ntry: number of try
        @type ntry: int

        @param params: list of testing parameters
        @type params: list
        """
        if 'keepalive' in params and params['keepalive'] is not None:
            self.logger.info(self.name +
                             ': will not terminate %s (keepalive requested)' %
                             params['iname'])
            return
        driver = cloud.get_driver(params['cloud'], self.logger,
                                  self.shareddata.maxwait)
        try:
            self.logger.debug(self.name + ': trying to terminata instance  ' +
                              params['iname'] + ', ntry ' + str(ntry))
            if self.shareddata.enabled:
                driver.terminate(params)
            self.logger.info(self.name + ': terminated ' + params['iname'])
        except cloud.PermanentCloudException, err:
            self.logger.error(
                self.name +
                ': got permanent error during instance termination, %s %s' %
                (type(err), err))
Beispiel #2
0
    def do_create(self, ntry, params):
        """
        Create stage of testing

        @param ntry: number of try
        @type ntry: int

        @param params: list of testing parameters
        @type params: list
        """
        self.logger.debug(self.name + ': trying to create instance  ' +
                          params['iname'] + ', ntry ' + str(ntry))
        driver = cloud.get_driver(params['cloud'], self.logger,
                                  self.shareddata.maxwait)
        if not self.shareddata.enabled:
            self.shareddata.mainq.put((0, 'setup', params.copy()))
            return
        try:
            params_new = driver.create(params)
            self.shareddata.mainq.put((0, 'setup', params_new.copy()))
        except cloud.base.TemporaryCloudException, exc:
            self.logger.debug('%s: Temporary Cloud Exception: %s', self.name,
                              exc)
            time.sleep(10)
            self.shareddata.mainq.put((ntry, 'create', params.copy()))
Beispiel #3
0
    def report_results(self, params):
        """
        Report results

        @param params: list of testing parameters
        @type params: list
        """
        console_output = ''
        if len(params['stages']) == 1:
            try:
                driver = cloud.get_driver(params['cloud'], self.logger, self.shareddata.maxwait)
                #getting console output after last stage
                if self.shareddata.enabled:
                    console_output = driver.get_console_output(params)
                self.logger.debug(self.name + ': got console output for %s: %s' % (params['iname'], console_output))
            except Exception, err:
                self.logger.error(self.name + ': report_results: Failed to get console output %s' % err)
Beispiel #4
0
    def do_terminate(self, ntry, params):
        """
        Terminate stage of testing

        @param ntry: number of try
        @type ntry: int

        @param params: list of testing parameters
        @type params: list
        """
        if 'keepalive' in params and params['keepalive'] is not None:
            self.logger.info(self.name + ': will not terminate %s (keepalive requested)' % params['iname'])
            return
        driver = cloud.get_driver(params['cloud'], self.logger, self.shareddata.maxwait)
        try:
            self.logger.debug(self.name + ': trying to terminata instance  ' + params['iname'] + ', ntry ' + str(ntry))
            if self.shareddata.enabled:
                driver.terminate(params)
            self.logger.info(self.name + ': terminated ' + params['iname'])
        except cloud.PermanentCloudException, err:
            self.logger.error(self.name + ': got permanent error during instance termination, %s %s' % (type(err), err))
Beispiel #5
0
    def do_create(self, ntry, params):
        """
        Create stage of testing

        @param ntry: number of try
        @type ntry: int

        @param params: list of testing parameters
        @type params: list
        """
        self.logger.debug(self.name + ': trying to create instance  ' + params['iname'] + ', ntry ' + str(ntry))
        driver = cloud.get_driver(params['cloud'], self.logger, self.shareddata.maxwait)
        if not self.shareddata.enabled:
            self.shareddata.mainq.put((0, 'setup', params.copy()))
            return
        try:
            params_new = driver.create(params)
            self.shareddata.mainq.put((0, 'setup', params_new.copy()))
        except cloud.base.TemporaryCloudException, exc:
            self.logger.debug('%s: Temporary Cloud Exception: %s', self.name, exc)
            time.sleep(10)
            self.shareddata.mainq.put((ntry, 'create', params.copy()))
Beispiel #6
0
    def report_results(self, params):
        """
        Report results

        @param params: list of testing parameters
        @type params: list
        """
        console_output = ''
        if len(params['stages']) == 1:
            try:
                driver = cloud.get_driver(params['cloud'], self.logger,
                                          self.shareddata.maxwait)
                #getting console output after last stage
                if self.shareddata.enabled:
                    console_output = driver.get_console_output(params)
                self.logger.debug(self.name +
                                  ': got console output for %s: %s' %
                                  (params['iname'], console_output))
            except Exception, err:
                self.logger.error(
                    self.name +
                    ': report_results: Failed to get console output %s' % err)
Beispiel #7
0
    def add_data(self, data, emails=None, subject=None):
        """
        Add testing data
        @param data: list of data fields
        @type params: list

        @param emails: comma-separated list of emails interested in result
        @type emails: str

        @param subject: email subject
        @type subject: str

        @return: transaction id or None
        @rtype: str or None
        """
        transaction_id = ''.join(random.choice(string.ascii_lowercase) for x in range(10))
        # pylint: disable=maybe-no-member
        self.logger.progress('Adding validation transaction ' + transaction_id)
        transaction_dict = {}
        count = 0
        for params in data:
            cloud_name = params.get('cloud', 'ec2')
            params['cloud'] = cloud_name

            driver = cloud.get_driver(cloud_name, self.logger, self.maxwait)

            if not cloud_name in self.cloud_access:
                self.logger.error('No cloud access data for %s in config', cloud_name)
                continue
            mandatory_fields = ['product', 'arch', 'version', 'ami'] + driver.mandatory_fields
            data_is_valid = True
            for field in mandatory_fields:
                if not field in params:
                    self.logger.error('Missing %s in params', field)
                    data_is_valid = False
            if not data_is_valid:
                continue

            if not 'region' in params:
                params['region'] = 'default'

            if params['ami'] in transaction_dict.keys():
                self.logger.error('Ami %s was already added for transaction %s!', params['ami'], transaction_id)
                continue
            self.logger.debug('Got valid data line ' + str(params))
            hwp_found = False
            for hwpdir in ['hwp', '/usr/share/valid/hwp']:
                try:
                    hwpfd = open(hwpdir + '/' + params['arch'] + '.yaml', 'r')
                    hwp = yaml.load(hwpfd)
                    hwpfd.close()
                    for item in hwp:
                        # old-style hwps
                        if 'ec2name' in item:
                            item['cloudhwname'] = item['ec2name']
                    # filter hwps based on args
                    hwp = [x for x in hwp if re.match(self.hwp_filter, str(x['cloudhwname']))]
                    if not len(hwp):
                        # precautions
                        self.logger.info('no hwp match for %s; nothing to do', self.hwp_filter)
                        continue

                    self.logger.info('using hwps: %s', reduce(lambda x, y: x + ', %s' % str(y['cloudhwname']), hwp[1:], str(hwp[0]['cloudhwname'])))
                    ninstances = 0
                    for hwp_item in hwp:
                        params_copy = {par: params[par] for par in params}
                        # we want to avoid version being float or int
                        params_copy['version'] = str(params['version'])

                        # update params with hwp details
                        params_copy.update(hwp_item)

                        if not 'enable_stages' in params_copy:
                            params_copy['enable_stages'] = self.enable_stages
                        if not 'disable_stages' in params_copy:
                            params_copy['disable_stages'] = self.disable_stages
                        if not 'enable_tags' in params_copy:
                            params_copy['enable_tags'] = self.enable_tags
                        if not 'disable_tags' in params_copy:
                            params_copy['disable_tags'] = self.disable_tags
                        if not 'enable_tests' in params_copy:
                            params_copy['enable_tests'] = self.enable_tests
                        if not 'disable_tests' in params_copy:
                            params_copy['disable_tests'] = self.disable_tests

                        if not 'repeat' in params_copy:
                            params_copy['repeat'] = self.repeat

                        if not 'name' in params_copy:
                            params_copy['name'] = params_copy['ami'] + ' validation'

                        driver.set_default_params(params_copy, self.cloud_access)

                        params_copy['transaction_id'] = transaction_id
                        params_copy['iname'] = 'Instance' + str(count) + '_' + transaction_id
                        params_copy['stages'] = self.get_test_stages(params_copy)
                        ninstances += len(params_copy['stages'])
                        if params_copy['stages'] != []:
                            self.logger.info('Adding ' + params_copy['iname'] + ': ' + \
                                                hwp_item['cloudhwname'] + ' instance for ' + \
                                                params_copy['ami'] + ' testing in ' + params_copy['region'])
                            self.mainq.put((0, 'create', params_copy))
                            count += 1
                        else:
                            self.logger.info('No tests for ' + params_copy['iname'] + ': ' + \
                                                hwp_item['cloudhwname'] + ' instance for ' + \
                                                params_copy['ami'] + ' testing in ' + params_copy['region'])
                    if ninstances > 0:
                        transaction_dict[params['ami']] = {'ninstances': ninstances, 'instances': []}
                        if emails:
                            transaction_dict[params['ami']]['emails'] = emails
                            if subject:
                                transaction_dict[params['ami']]['subject'] = subject
                    hwp_found = True
                    break
                # pylint: disable=bare-except
                except:
                    self.logger.debug(':' + traceback.format_exc())
            if not hwp_found:
                self.logger.error('HWP for ' + params['arch'] + ' is not found, skipping dataline for ' + params['ami'])
        if count > 0:
            self.resultdic[transaction_id] = transaction_dict
            # pylint: disable=maybe-no-member
            self.logger.progress('Validation transaction ' + transaction_id + ' added')
            return transaction_id
        else:
            self.logger.error('No data added')
            return None
Beispiel #8
0
    def add_data(self, data, emails=None, subject=None):
        """
        Add testing data
        @param data: list of data fields
        @type params: list

        @param emails: comma-separated list of emails interested in result
        @type emails: str

        @param subject: email subject
        @type subject: str

        @return: transaction id or None
        @rtype: str or None
        """
        transaction_id = ''.join(
            random.choice(string.ascii_lowercase) for x in range(10))
        # pylint: disable=maybe-no-member
        self.logger.progress('Adding validation transaction ' + transaction_id)
        transaction_dict = {}
        count = 0
        for params in data:
            cloud_name = params.get('cloud', 'ec2')
            params['cloud'] = cloud_name

            driver = cloud.get_driver(cloud_name, self.logger, self.maxwait)

            if not cloud_name in self.cloud_access:
                self.logger.error('No cloud access data for %s in config',
                                  cloud_name)
                continue
            mandatory_fields = ['product', 'arch', 'version', 'ami'
                                ] + driver.mandatory_fields
            data_is_valid = True
            for field in mandatory_fields:
                if not field in params:
                    self.logger.error('Missing %s in params', field)
                    data_is_valid = False
            if not data_is_valid:
                continue

            if not 'region' in params:
                params['region'] = 'default'

            if params['ami'] in transaction_dict.keys():
                self.logger.error(
                    'Ami %s was already added for transaction %s!',
                    params['ami'], transaction_id)
                continue
            self.logger.debug('Got valid data line ' + str(params))
            hwp_found = False
            for hwpdir in ['hwp', '/usr/share/valid/hwp']:
                try:
                    hwpfd = open(hwpdir + '/' + params['arch'] + '.yaml', 'r')
                    hwp = yaml.load(hwpfd)
                    hwpfd.close()
                    for item in hwp:
                        # old-style hwps
                        if 'ec2name' in item:
                            item['cloudhwname'] = item['ec2name']
                    # filter hwps based on args
                    hwp = [
                        x for x in hwp
                        if re.match(self.hwp_filter, str(x['cloudhwname']))
                    ]
                    if not len(hwp):
                        # precautions
                        self.logger.info('no hwp match for %s; nothing to do',
                                         self.hwp_filter)
                        continue

                    self.logger.info(
                        'using hwps: %s',
                        reduce(lambda x, y: x + ', %s' % str(y['cloudhwname']),
                               hwp[1:], str(hwp[0]['cloudhwname'])))
                    ninstances = 0
                    for hwp_item in hwp:
                        params_copy = {par: params[par] for par in params}
                        # we want to avoid version being float or int
                        params_copy['version'] = str(params['version'])

                        # update params with hwp details
                        params_copy.update(hwp_item)

                        if not 'enable_stages' in params_copy:
                            params_copy['enable_stages'] = self.enable_stages
                        if not 'disable_stages' in params_copy:
                            params_copy['disable_stages'] = self.disable_stages
                        if not 'enable_tags' in params_copy:
                            params_copy['enable_tags'] = self.enable_tags
                        if not 'disable_tags' in params_copy:
                            params_copy['disable_tags'] = self.disable_tags
                        if not 'enable_tests' in params_copy:
                            params_copy['enable_tests'] = self.enable_tests
                        if not 'disable_tests' in params_copy:
                            params_copy['disable_tests'] = self.disable_tests

                        if not 'repeat' in params_copy:
                            params_copy['repeat'] = self.repeat

                        if not 'name' in params_copy:
                            params_copy[
                                'name'] = params_copy['ami'] + ' validation'

                        driver.set_default_params(params_copy,
                                                  self.cloud_access)

                        params_copy['transaction_id'] = transaction_id
                        params_copy['iname'] = 'Instance' + str(
                            count) + '_' + transaction_id
                        params_copy['stages'] = self.get_test_stages(
                            params_copy)
                        ninstances += len(params_copy['stages'])
                        if params_copy['stages'] != []:
                            self.logger.info('Adding ' + params_copy['iname'] + ': ' + \
                                                hwp_item['cloudhwname'] + ' instance for ' + \
                                                params_copy['ami'] + ' testing in ' + params_copy['region'])
                            self.mainq.put((0, 'create', params_copy))
                            count += 1
                        else:
                            self.logger.info('No tests for ' + params_copy['iname'] + ': ' + \
                                                hwp_item['cloudhwname'] + ' instance for ' + \
                                                params_copy['ami'] + ' testing in ' + params_copy['region'])
                    if ninstances > 0:
                        transaction_dict[params['ami']] = {
                            'ninstances': ninstances,
                            'instances': []
                        }
                        if emails:
                            transaction_dict[params['ami']]['emails'] = emails
                            if subject:
                                transaction_dict[
                                    params['ami']]['subject'] = subject
                    hwp_found = True
                    break
                # pylint: disable=bare-except
                except:
                    self.logger.debug(':' + traceback.format_exc())
            if not hwp_found:
                self.logger.error('HWP for ' + params['arch'] +
                                  ' is not found, skipping dataline for ' +
                                  params['ami'])
        if count > 0:
            self.resultdic[transaction_id] = transaction_dict
            # pylint: disable=maybe-no-member
            self.logger.progress('Validation transaction ' + transaction_id +
                                 ' added')
            return transaction_id
        else:
            self.logger.error('No data added')
            return None