Example #1
0
    def update_openrc(self, args):
        try:
            openrc_vars = args['openrc']
        except KeyError:
            return result_handler(consts.API_ERROR, 'openrc must be provided')
        else:
            if not isinstance(openrc_vars, collections.Mapping):
                return result_handler(consts.API_ERROR, 'args should be a dict')

        lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()]
        LOG.debug('Writing: %s', ''.join(lines))

        LOG.info('Writing openrc: Writing')
        utils.makedirs(consts.CONF_DIR)

        with open(consts.OPENRC, 'w') as f:
            f.writelines(lines)
        LOG.info('Writing openrc: Done')

        LOG.info('Source openrc: Sourcing')
        try:
            self._source_file(consts.OPENRC)
        except subprocess.CalledProcessError as e:
            LOG.exception('Failed to source openrc')
            return result_handler(consts.API_ERROR, str(e))
        LOG.info('Source openrc: Done')

        return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars})
Example #2
0
    def _parse_tasks(self, parser, task_files, args, task_args,
                     task_args_fnames):
        tasks = []

        # Parse task_files.
        for i, _ in enumerate(task_files):
            parser.path = task_files[i]
            tasks.append(
                parser.parse_task(self.task_id, task_args[i],
                                  task_args_fnames[i]))
            tasks[i]['case_name'] = os.path.splitext(
                os.path.basename(task_files[i]))[0]

        if args.render_only:
            utils.makedirs(args.render_only)
            for idx, task in enumerate(tasks):
                output_file_name = os.path.abspath(
                    os.path.join(
                        args.render_only,
                        '{0:03d}-{1}.yml'.format(idx, task['case_name'])))
                utils.write_file(output_file_name, task['rendered'])

            sys.exit(0)

        return tasks
Example #3
0
    def update_openrc(self, args):
        try:
            openrc_vars = args['openrc']
        except KeyError:
            return result_handler(consts.API_ERROR, 'openrc must be provided')
        else:
            if not isinstance(openrc_vars, collections.Mapping):
                return result_handler(consts.API_ERROR,
                                      'args should be a dict')

        lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()]
        LOG.debug('Writing: %s', ''.join(lines))

        LOG.info('Writing openrc: Writing')
        utils.makedirs(consts.CONF_DIR)

        with open(consts.OPENRC, 'w') as f:
            f.writelines(lines)
        LOG.info('Writing openrc: Done')

        LOG.info('Source openrc: Sourcing')
        try:
            self._source_file(consts.OPENRC)
        except subprocess.CalledProcessError as e:
            LOG.exception('Failed to source openrc')
            return result_handler(consts.API_ERROR, str(e))
        LOG.info('Source openrc: Done')

        return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars})
Example #4
0
    def _generate_ansible_conf_file(self, openrc_data):
        ansible_conf = {
            'clouds': {
                'opnfv': {
                    'auth': {
                    }
                }
            }
        }
        black_list = ['OS_IDENTITY_API_VERSION', 'OS_IMAGE_API_VERSION']

        for k, v in openrc_data.items():
            if k.startswith('OS') and k not in black_list:
                key = k[3:].lower()
                ansible_conf['clouds']['opnfv']['auth'][key] = v

        try:
            value = openrc_data['OS_IDENTITY_API_VERSION']
        except KeyError:
            pass
        else:
            ansible_conf['clouds']['opnfv']['identity_api_version'] = value

        makedirs(consts.OPENSTACK_CONF_DIR)
        with open(consts.CLOUDS_CONF, 'w') as f:
            yaml.dump(ansible_conf, f, default_flow_style=False)
Example #5
0
    def _set_log(self):
        log_format = '%(asctime)s %(name)s %(filename)s:%(lineno)d %(levelname)s %(message)s'
        log_formatter = logging.Formatter(log_format)

        utils.makedirs(constants.TASK_LOG_DIR)
        log_path = os.path.join(constants.TASK_LOG_DIR, '{}.log'.format(self.task_id))
        log_handler = logging.FileHandler(log_path)
        log_handler.setFormatter(log_formatter)
        log_handler.setLevel(logging.DEBUG)

        logging.root.addHandler(log_handler)
Example #6
0
def _change_output_to_influxdb():
    yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)

    parser = configparser.ConfigParser()
    parser.read(config.YARDSTICK_CONFIG_SAMPLE_FILE)

    parser.set('DEFAULT', 'dispatcher', 'influxdb')
    parser.set('dispatcher_influxdb', 'target',
               'http://%s:8086' % api_conf.GATEWAY_IP)

    with open(config.YARDSTICK_CONFIG_FILE, 'w') as f:
        parser.write(f)
Example #7
0
def _change_output_to_influxdb(ip):
    yardstick_utils.makedirs(consts.CONF_DIR)

    parser = configparser.ConfigParser()
    parser.read(consts.CONF_SAMPLE_FILE)

    parser.set('DEFAULT', 'dispatcher', 'influxdb')
    parser.set('dispatcher_influxdb', 'target',
               'http://{}:{}'.format(ip, consts.INFLUXDB_PORT))

    with open(consts.CONF_FILE, 'w') as f:
        parser.write(f)
Example #8
0
def _change_output_to_influxdb():
    common_utils.makedirs(consts.CONF_DIR)

    parser = configparser.ConfigParser()
    parser.read(consts.CONF_SAMPLE_FILE)

    parser.set('DEFAULT', 'dispatcher', 'influxdb')
    parser.set('dispatcher_influxdb', 'target',
               'http://%s:8086' % consts.INFLUXDB_IP)

    with open(consts.CONF_FILE, 'w') as f:
        parser.write(f)
Example #9
0
    def update_openrc(self, args):
        try:
            openrc_vars = args['openrc']
        except KeyError:
            return result_handler(consts.API_ERROR, 'openrc must be provided')

        try:
            environment_id = args['environment_id']
        except KeyError:
            return result_handler(consts.API_ERROR,
                                  'environment_id must be provided')

        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        LOG.info('writing openrc: %s', consts.OPENRC)
        makedirs(consts.CONF_DIR)

        lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()]
        LOG.debug('writing: %s', ''.join(lines))
        with open(consts.OPENRC, 'w') as f:
            f.writelines(lines)
        LOG.info('writing openrc: Done')

        LOG.info('source openrc: %s', consts.OPENRC)
        try:
            source_env(consts.OPENRC)
        except Exception:
            LOG.exception('source openrc failed')
            return result_handler(consts.API_ERROR, 'source openrc failed')
        LOG.info('source openrc: Done')

        openrc_id = str(uuid.uuid4())
        self._write_into_database(environment_id, openrc_id, openrc_vars)

        LOG.info('writing ansible cloud conf')
        try:
            self._generate_ansible_conf_file(openrc_vars)
        except Exception:
            LOG.exception('write cloud conf failed')
            return result_handler(consts.API_ERROR,
                                  'genarate ansible conf failed')
        LOG.info('finish writing ansible cloud conf')

        return result_handler(consts.API_SUCCESS, {
            'openrc': openrc_vars,
            'uuid': openrc_id
        })
Example #10
0
    def setup(self):
        # TODO: fixupt scenario_helper to hanlde ixia
        self.resource_file_name = str(
            self.scenario_helper.scenario_cfg['ixia_profile'])
        makedirs(self.RESULTS_MOUNT)
        cmd = MOUNT_CMD.format(self.vnfd_helper.mgmt_interface, self)
        LOG.debug(cmd)

        if not os.path.ismount(self.RESULTS_MOUNT):
            call(cmd, shell=True)

        shutil.rmtree(self.RESULTS_MOUNT, ignore_errors=True)
        makedirs(self.RESULTS_MOUNT)
        shutil.copy(self.resource_file_name, self.RESULTS_MOUNT)
Example #11
0
    def _change_output_to_influxdb(self, ip):
        utils.makedirs(consts.CONF_DIR)

        parser = configparser.ConfigParser()
        LOG.info('Reading output sample configuration')
        parser.read(consts.CONF_SAMPLE_FILE)

        LOG.info('Set dispatcher to influxdb')
        parser.set('DEFAULT', 'dispatcher', 'influxdb')
        parser.set('dispatcher_influxdb', 'target',
                   'http://{}:{}'.format(ip, consts.INFLUXDB_PORT))

        LOG.info('Writing to %s', consts.CONF_FILE)
        with open(consts.CONF_FILE, 'w') as f:
            parser.write(f)
Example #12
0
    def _change_output_to_influxdb(self, ip):
        utils.makedirs(consts.CONF_DIR)

        parser = configparser.ConfigParser()
        LOG.info('Reading output sample configuration')
        parser.read(consts.CONF_SAMPLE_FILE)

        LOG.info('Set dispatcher to influxdb')
        parser.set('DEFAULT', 'dispatcher', 'influxdb')
        parser.set('dispatcher_influxdb', 'target',
                   'http://{}:{}'.format(ip, consts.INFLUXDB_PORT))

        LOG.info('Writing to %s', consts.CONF_FILE)
        with open(consts.CONF_FILE, 'w') as f:
            parser.write(f)
Example #13
0
def _change_output_to_influxdb():
    common_utils.makedirs(consts.CONF_DIR)

    parser = configparser.ConfigParser()
    LOG.info('Reading output sample configuration')
    parser.read(consts.CONF_SAMPLE_FILE)

    LOG.info('Set dispatcher to influxdb')
    parser.set('DEFAULT', 'dispatcher', 'influxdb')
    parser.set('dispatcher_influxdb', 'target',
               'http://%s:8086' % consts.INFLUXDB_IP)

    LOG.info('Writing to %s', consts.CONF_FILE)
    with open(consts.CONF_FILE, 'w') as f:
        parser.write(f)
Example #14
0
    def setup(self):
        # NOTE: fixup scenario_helper to hanlde ixia
        self.resource_file_name = \
            utils.find_relative_file(
                self.scenario_helper.scenario_cfg['ixia_profile'],
                self.scenario_helper.scenario_cfg["task_path"])
        utils.makedirs(self.RESULTS_MOUNT)
        cmd = MOUNT_CMD.format(self.vnfd_helper.mgmt_interface, self)
        LOG.debug(cmd)

        if not os.path.ismount(self.RESULTS_MOUNT):
            call(cmd, shell=True)

        shutil.rmtree(self.RESULTS_MOUNT, ignore_errors=True)
        utils.makedirs(self.RESULTS_MOUNT)
        shutil.copy(self.resource_file_name, self.RESULTS_MOUNT)
Example #15
0
    def upload_openrc(self, args):
        try:
            upload_file = args['file']
        except KeyError:
            return result_handler(consts.API_ERROR, 'file must be provided')

        try:
            environment_id = args['environment_id']
        except KeyError:
            return result_handler(consts.API_ERROR,
                                  'environment_id must be provided')

        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        LOG.info('writing openrc: %s', consts.OPENRC)
        makedirs(consts.CONF_DIR)
        upload_file.save(consts.OPENRC)
        source_env(consts.OPENRC)

        LOG.info('parsing openrc')
        try:
            openrc_data = self._get_openrc_dict()
        except Exception:
            LOG.exception('parse openrc failed')
            return result_handler(consts.API_ERROR, 'parse openrc failed')

        openrc_id = str(uuid.uuid4())
        self._write_into_database(environment_id, openrc_id, openrc_data)

        LOG.info('writing ansible cloud conf')
        try:
            self._generate_ansible_conf_file(openrc_data)
        except Exception:
            LOG.exception('write cloud conf failed')
            return result_handler(consts.API_ERROR,
                                  'genarate ansible conf failed')
        LOG.info('finish writing ansible cloud conf')

        return result_handler(consts.API_SUCCESS, {
            'openrc': openrc_data,
            'uuid': openrc_id
        })
Example #16
0
    def update_openrc(self, args):
        try:
            openrc_vars = args['openrc']
        except KeyError:
            return result_handler(consts.API_ERROR, 'openrc must be provided')

        try:
            environment_id = args['environment_id']
        except KeyError:
            return result_handler(consts.API_ERROR, 'environment_id must be provided')

        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        LOG.info('writing openrc: %s', consts.OPENRC)
        makedirs(consts.CONF_DIR)

        lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()]
        LOG.debug('writing: %s', ''.join(lines))
        with open(consts.OPENRC, 'w') as f:
            f.writelines(lines)
        LOG.info('writing openrc: Done')

        LOG.info('source openrc: %s', consts.OPENRC)
        try:
            source_env(consts.OPENRC)
        except Exception:
            LOG.exception('source openrc failed')
            return result_handler(consts.API_ERROR, 'source openrc failed')
        LOG.info('source openrc: Done')

        openrc_id = str(uuid.uuid4())
        self._write_into_database(environment_id, openrc_id, openrc_vars)

        LOG.info('writing ansible cloud conf')
        try:
            self._generate_ansible_conf_file(openrc_vars)
        except Exception:
            LOG.exception('write cloud conf failed')
            return result_handler(consts.API_ERROR, 'genarate ansible conf failed')
        LOG.info('finish writing ansible cloud conf')

        return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars, 'uuid': openrc_id})
Example #17
0
    def _generate_ansible_conf_file(self, openrc_data):
        ansible_conf = {'clouds': {'opnfv': {'auth': {}}}}
        black_list = ['OS_IDENTITY_API_VERSION', 'OS_IMAGE_API_VERSION']

        for k, v in openrc_data.items():
            if k.startswith('OS') and k not in black_list:
                key = k[3:].lower()
                ansible_conf['clouds']['opnfv']['auth'][key] = v

        try:
            value = openrc_data['OS_IDENTITY_API_VERSION']
        except KeyError:
            pass
        else:
            ansible_conf['clouds']['opnfv']['identity_api_version'] = value

        makedirs(consts.OPENSTACK_CONF_DIR)
        with open(consts.CLOUDS_CONF, 'w') as f:
            yaml.dump(ansible_conf, f, default_flow_style=False)
Example #18
0
    def upload_openrc(self, args):
        try:
            upload_file = args['file']
        except KeyError:
            return result_handler(consts.API_ERROR, 'file must be provided')

        try:
            environment_id = args['environment_id']
        except KeyError:
            return result_handler(consts.API_ERROR, 'environment_id must be provided')

        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        LOG.info('writing openrc: %s', consts.OPENRC)
        makedirs(consts.CONF_DIR)
        upload_file.save(consts.OPENRC)
        source_env(consts.OPENRC)

        LOG.info('parsing openrc')
        try:
            openrc_data = self._get_openrc_dict()
        except Exception:
            LOG.exception('parse openrc failed')
            return result_handler(consts.API_ERROR, 'parse openrc failed')

        openrc_id = str(uuid.uuid4())
        self._write_into_database(environment_id, openrc_id, openrc_data)

        LOG.info('writing ansible cloud conf')
        try:
            self._generate_ansible_conf_file(openrc_data)
        except Exception:
            LOG.exception('write cloud conf failed')
            return result_handler(consts.API_ERROR, 'genarate ansible conf failed')
        LOG.info('finish writing ansible cloud conf')

        return result_handler(consts.API_SUCCESS, {'openrc': openrc_data, 'uuid': openrc_id})
Example #19
0
def _create_directories():
    yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)
# Copyright (c) 2015 Ericsson AB and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from __future__ import absolute_import
import logging
import os

from yardstick.common import constants
from yardstick.common import utils as yardstick_utils

yardstick_utils.makedirs(constants.LOG_DIR)
LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log')
LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s'

_LOG_FORMATTER = logging.Formatter(LOG_FORMATTER)
_LOG_STREAM_HDLR = logging.StreamHandler()
_LOG_FILE_HDLR = logging.FileHandler(LOG_FILE)

LOG = logging.getLogger(__name__)


def _init_logging():

    LOG.setLevel(logging.DEBUG)

    _LOG_STREAM_HDLR.setFormatter(_LOG_FORMATTER)
Example #21
0
 def test_makedirs_busy(self, mock_os_makedirs):
     mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
     with self.assertRaises(OSError):
         utils.makedirs('a/b/c/d')
Example #22
0
 def _create_directories(self):
     utils.makedirs(consts.CONF_DIR)
Example #23
0
def _create_directories():
    common_utils.makedirs(consts.CONF_DIR)
Example #24
0
 def test_makedirs(self, *_):
     self.assertIsNone(utils.makedirs('a/b/c/d'))
Example #25
0
 def test_makedirs_exists(self, mock_os_makedirs):
     mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
     self.assertIsNone(utils.makedirs('a/b/c/d'))
Example #26
0
 def _create_directories(self):
     utils.makedirs(consts.CONF_DIR)
Example #27
0
def _create_directories():
    yardstick_utils.makedirs(consts.CONF_DIR)