Ejemplo n.º 1
0
 def update_rally_logs(res_dir, rally_conf='/etc/rally/rally.conf'):
     """Print rally logs in res dir"""
     if not os.path.exists(res_dir):
         os.makedirs(res_dir)
     rconfig = configparser.RawConfigParser()
     rconfig.read(rally_conf)
     rconfig.set('DEFAULT', 'debug', True)
     rconfig.set('DEFAULT', 'use_stderr', False)
     rconfig.set('DEFAULT', 'log-file', 'rally.log')
     rconfig.set('DEFAULT', 'log_dir', res_dir)
     with open(rally_conf, 'w') as config_file:
         rconfig.write(config_file)
Ejemplo n.º 2
0
    def __init__(self):
        self._logger = logging.getLogger()

        config_path = os.path.join(os.path.expanduser('~'), '.shipane_sdk',
                                   'config', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = configparser.RawConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"), )

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger,
                              **dict(self._config.items('ShiPanE')))
Ejemplo n.º 3
0
    def get_rm_conf_old(self):
        """
        Get excluded files config from remove_file.
        """
        # Convert config object into dict
        self.using_new_format = False
        parsedconfig = ConfigParser.RawConfigParser()
        if not self.remove_file:
            # no filename defined, return nothing
            logger.debug('remove_file is undefined')
            return None
        if not os.path.isfile(self.remove_file):
            logger.debug('%s not found. No data files, commands,'
                         ' or patterns will be ignored, and no keyword obfuscation will occur.', self.remove_file)
            return None
        try:
            verify_permissions(self.remove_file)
        except RuntimeError as e:
            if self.config.validate:
                # exit if permissions invalid and using --validate
                raise RuntimeError('ERROR: %s' % e)
            logger.warning('WARNING: %s', e)
        try:
            parsedconfig.read(self.remove_file)
            sections = parsedconfig.sections()

            if not sections:
                # file has no sections, skip it
                logger.debug('Remove.conf exists but no parameters have been defined.')
                return None

            if sections != ['remove']:
                raise RuntimeError('ERROR: invalid section(s) in remove.conf. Only "remove" is valid.')

            expected_keys = ('commands', 'files', 'patterns', 'keywords')
            rm_conf = {}
            for item, value in parsedconfig.items('remove'):
                if item not in expected_keys:
                    raise RuntimeError('ERROR: Unknown key in remove.conf: ' + item +
                                       '\nValid keys are ' + ', '.join(expected_keys) + '.')
                if six.PY3:
                    rm_conf[item] = value.strip().encode('utf-8').decode('unicode-escape').split(',')
                else:
                    rm_conf[item] = value.strip().decode('string-escape').split(',')
            self.rm_conf = rm_conf
        except ConfigParser.Error as e:
            # can't parse config file at all
            logger.debug(e)
            logger.debug('To configure using YAML, please use file-redaction.yaml and file-content-redaction.yaml.')
            raise RuntimeError('ERROR: Cannot parse the remove.conf file.\n'
                               'See %s for more information.' % self.config.logging_file)
        logger.warning('WARNING: remove.conf is deprecated. Please use file-redaction.yaml and file-content-redaction.yaml. See https://access.redhat.com/articles/4511681 for details.')
        return self.rm_conf
Ejemplo n.º 4
0
    def __init__(self, path):
        self.path = path
        self.config = configparser.RawConfigParser()
        self._sync = False

        for section, params in self.DEFAULT_CONFIG.items():
            for key, value in params.items():
                self.set(section, key, value)

        self.save()

        self._sync = True
Ejemplo n.º 5
0
 def update_default_role(self, rally_conf='/etc/rally/rally.conf'):
     """Detect and update the default role if required"""
     role = self.get_default_role(self.cloud)
     if not role:
         return
     rconfig = configparser.RawConfigParser()
     rconfig.read(rally_conf)
     if not rconfig.has_section('openstack'):
         rconfig.add_section('openstack')
     rconfig.set('openstack', 'swift_operator_role', role.name)
     with open(rally_conf, 'w') as config_file:
         rconfig.write(config_file)
Ejemplo n.º 6
0
def init_config():
    conf_path = get_config_path()[0]
    if os.path.exists(conf_path):
        die("%s already exists!" % conf_path)

    parser = configparser.RawConfigParser()
    conf_dir = os.path.dirname(conf_path)
    if not os.path.isdir(conf_dir):
        os.makedirs(conf_dir)
    parser.add_section(SECTION)
    parser.set(SECTION, "username", getpass.getuser())
    parser.set(SECTION, "; password", DEFAULT_PASSWORD)
    parser.set(
        SECTION, "config_repo",
        "https://code.engineering.redhat.com/gerrit/rcm/rcm-nexus-config")
    parser.set(
        SECTION, "; write_config_repo",
        "ssh://{user}@code.engineering.redhat.com/rcm/rcm-nexus-config")
    parser.set(SECTION, "target_groups_ga", "product-all")
    parser.set(SECTION, "target_groups_ea", "product-all")
    parser.set(SECTION, "promote_ruleset_ga", "57aa9ee54e2f6")
    parser.set(SECTION, "promote_ruleset_ea", "13091dda10832d")
    parser.set(SECTION, "promote_target_ga", "product-old-releases")
    parser.set(SECTION, "promote_target_ea", "product-old-releases-ea")
    parser.set(SECTION, "deployer_role", "product_deployer")
    parser.set(SECTION, "; " + SSL_VERIFY, DEFAULTS.get(SSL_VERIFY))
    parser.set(SECTION, "; " + PREEMPTIVE_AUTH, DEFAULTS.get(PREEMPTIVE_AUTH))
    parser.set(SECTION, "; " + INTERACTIVE, DEFAULTS.get(INTERACTIVE))

    parser.add_section(ENVIRONMENT_PRODUCTION)
    parser.set(ENVIRONMENT_PRODUCTION, URL,
               "https://repository.jboss.org/nexus")
    parser.set(ENVIRONMENT_PRODUCTION, "; username",
               "{production specific user name}")
    parser.set(ENVIRONMENT_PRODUCTION, "; password",
               "{production specific password}")

    parser.add_section(ENVIRONMENT_STAGE)
    parser.set(ENVIRONMENT_STAGE, URL,
               "https://repository.stage.jboss.org/nexus")
    parser.set(ENVIRONMENT_STAGE, "; username", "{staging specific user name}")
    parser.set(ENVIRONMENT_STAGE, "; password", "{staging specific password}")

    with open(conf_path, "w") as f:
        parser.write(f)
        print(
            "; For more information see: https://mojo.redhat.com/docs/DOC-1132234",
            file=f)
        print(
            "; The config_repo options can be defined in system wide config file",
            file=f)

    return conf_path
Ejemplo n.º 7
0
def read_configuration_file(fp=None, default_options=None):
    '''
    options = read_configuration_file(fp='~/.config/jugrc',
                                      default_options={'':'', ...})

    Parse configuration file.

    Parameters
    ----------
    fp : inputfile, optional
        File to read. If not given, use
    default_options: dictionary, optional
        Dictionary with the default values for all command-line arguments.
        Used to convert settings in the config file to the correct object type.
    '''
    inifile = Options(default_options)

    if fp is None:
        from os import path
        for fp in ['~/.config/jug/jugrc', '~/.config/jugrc', '~/.jug/configrc']:
            fp = path.expanduser(fp)
            if path.exists(fp):
                try:
                    fp = open(fp)
                except IOError:
                    return inifile
                break
        else:
            return inifile

    from six.moves import configparser
    config = configparser.RawConfigParser()
    config.readfp(fp)

    for section in config.sections():
        for key, value in config.items(section):
            if section == "main":
                new_name = key_to_option(key)
            else:
                new_name = "{0}_{1}".format(key_to_option(section), key_to_option(key))

            # Get the type of the default value if a default value exists
            if default_options is not None:
                old_value = getattr(default_options, new_name, None)
                if old_value is not None:
                    # Cast the config object to the same type as the default
                    value = type(old_value)(value)

            logging.debug("Setting %s to %s", new_name, value)
            setattr(inifile, new_name, value)

    return inifile
Ejemplo n.º 8
0
def read_configuration_file(fp=None):
    '''
    options = read_configuration_file(fp='~/.config/jugrc')

    Parse configuration file.

    Parameters
    ----------
    fp : inputfile, optional
        File to read. If not given, use
    '''
    if fp is None:
        from os import path
        for fp in ['~/.config/jugrc', '~/.jug/configrc']:
            if path.exists(fp):
                try:
                    fp = open(fp)
                except IOError:
                    return Options(None)
                break
        else:
            return Options(None)
    from six.moves import configparser
    config = configparser.RawConfigParser()
    config.readfp(fp)
    infile = Options(None)

    def attempt(section, entry, new_name, conv=None):
        try:
            value = config.get(section, entry)
            if conv is not None:
                value = conv(value)
            setattr(infile, new_name, value)
        except configparser.NoOptionError:
            pass
        except configparser.NoSectionError:
            pass

    attempt('main', 'jugdir', 'jugdir')
    attempt('main', 'jugfile', 'jugfile')

    attempt('status', 'cache', 'status_mode')

    attempt('cleanup', 'locks-only', 'cleanup_locks_only', bool)

    attempt('execute', 'aggressive-unload', 'aggressive_unload', _str_to_bool)
    attempt('execute', 'pbd', 'pdb', bool)
    attempt('execute', 'debug', 'debug', bool)
    attempt('execute', 'nr-wait-cycles', 'execute_nr_wait_cycles', int)
    attempt('execute', 'wait-cycle-time', 'execute_wait_cycle_time_secs', int)
    attempt('execute', 'keep-going', 'execute_keep_going', _str_to_bool)
    return infile
Ejemplo n.º 9
0
def check(file_staged_for_commit, options):
    basename = os.path.basename(file_staged_for_commit.path)
    if not fnmatch.fnmatch(basename, options.ini_files):
        return True
    contents = cStringIO.StringIO(file_staged_for_commit.contents)
    parser = configparser.RawConfigParser()
    try:
        parser.readfp(contents, file_staged_for_commit.path)
    except configparser.Error as e:
        print(e)
        return False
    else:
        return True
Ejemplo n.º 10
0
    def _write(self, fileobj):
        p = configparser.RawConfigParser()
        p.add_section('lock')

        locked = '1' if self._locked else '0'
        p.set('lock', 'locked', locked)

        if self._locked:
            expire = self._expire.strftime(self._DATETIME_FORMAT)
            p.set('lock', 'owner', self._owner)
            p.set('lock', 'expire', expire)

        p.write(fileobj)
Ejemplo n.º 11
0
def test_migration_to_43_copies_default_section(cli, config):
    config.config.remove_section('taxi')
    config.save()
    with open(config.path, 'a') as config_fp:
        config_fp.write('[default]\neditor = /bin/false\n')

    cli('status')

    cp = configparser.RawConfigParser()
    cp.read(config.path)

    assert not cp.has_section('default')
    assert cp.get('taxi', 'editor') == '/bin/false'
Ejemplo n.º 12
0
    def __init__(self):
        self._logger = logging.getLogger()

        config_path = os.path.join(BASE_PATH, 'conf', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = configparser.RawConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"), )

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger,
                              **dict(self._config.items('ShiPanE')))

        self._db_path = os.path.join(BASE_PATH, 'db', 'Trader.db')
Ejemplo n.º 13
0
    def setUp(self):
        self.project_path = '/tmp/oct-test'
        self.cmd_opts = CmdOpts(self.project_path + "/results",
                                self.project_path)
        self.bad_cmd_opts = CmdOpts('/bad/project/path', '/bad/project/path')
        create_project(self.project_path)

        # update the runtime for the project
        config = configparser.RawConfigParser()
        config.read(self.project_path + "/config.cfg")
        config.set('global', 'run_time', 10)
        with open(self.project_path + "/config.cfg", 'w') as f:
            config.write(f)
Ejemplo n.º 14
0
def show_config(config):
    parser = configparser.RawConfigParser()

    if not config.envlist_explicit or reporter.verbosity(
    ) >= reporter.Verbosity.INFO:
        tox_info(config, parser)
        version_info(parser)
    tox_envs_info(config, parser)

    content = StringIO()
    parser.write(content)
    value = content.getvalue().rstrip()
    reporter.verbosity0(value)
Ejemplo n.º 15
0
def submit(self, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,
           resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,
           batch_args=None):
    if resubmit_immediate and self.get_value("MACH") in ['mira', 'cetus']:
        logger.warning("resubmit_immediate does not work on Mira/Cetus, submitting normally")
        resubmit_immediate = False

    caseroot = self.get_value("CASEROOT")
    if self.get_value("TEST"):
        casebaseid = self.get_value("CASEBASEID")
        # This should take care of the race condition where the submitted job
        # begins immediately and tries to set RUN phase. We proactively assume
        # a passed SUBMIT phase. If this state is already PASS, don't set it again
        # because then we'll lose RUN phase info if it's there. This info is important
        # for system_tests_common to know if it needs to reinitialize the test or not.
        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
            phase_status = ts.get_status(SUBMIT_PHASE)
            if phase_status != TEST_PASS_STATUS:
                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)

    # If this is a resubmit check the hidden file .submit_options for
    # any submit options used on the original submit and use them again
    submit_options = os.path.join(caseroot, ".submit_options")
    if resubmit and os.path.exists(submit_options):
        config = configparser.RawConfigParser()
        config.read(submit_options)
        if not skip_pnl and config.has_option('SubmitOptions','skip_pnl'):
            skip_pnl = config.getboolean('SubmitOptions', 'skip_pnl')
        if mail_user is None and config.has_option('SubmitOptions', 'mail_user'):
            mail_user = config.get('SubmitOptions', 'mail_user')
        if mail_type is None and config.has_option('SubmitOptions', 'mail_type'):
            mail_type = str(config.get('SubmitOptions', 'mail_type')).split(',')
        if batch_args is None and config.has_option('SubmitOptions', 'batch_args'):
            batch_args = config.get('SubmitOptions', 'batch_args')

    try:
        functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,
                                  allow_fail=allow_fail, resubmit=resubmit,
                                  resubmit_immediate=resubmit_immediate, skip_pnl=skip_pnl,
                                  mail_user=mail_user, mail_type=mail_type,
                                  batch_args=batch_args)
        run_and_log_case_status(functor, "case.submit", caseroot=caseroot,
                                custom_success_msg_functor=verbatim_success_msg)
    except BaseException: # Want to catch KeyboardInterrupt too
        # If something failed in the batch system, make sure to mark
        # the test as failed if we are running a test.
        if self.get_value("TEST"):
            with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
                ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)

        raise
Ejemplo n.º 16
0
def load_config_file(configuration_file=None):
    """
    Load a configuration file with backup directories and rotation schemes.

    :param configuration_file: Override the pathname of the configuration file
                               to load (a string or :data:`None`).
    :returns: A generator of tuples with four values each:

              1. An execution context created using :mod:`executor.contexts`.
              2. The pathname of a directory with backups (a string).
              3. A dictionary with the rotation scheme.
              4. A dictionary with additional options.
    :raises: :exc:`~exceptions.ValueError` when `configuration_file` is given
             but doesn't exist or can't be loaded.

    When `configuration_file` isn't given :data:`LOCAL_CONFIG_FILE` and
    :data:`GLOBAL_CONFIG_FILE` are checked and the first configuration file
    that exists is loaded. This function is used by :class:`RotateBackups` to
    discover user defined rotation schemes and by :mod:`rotate_backups.cli` to
    discover directories for which backup rotation is configured.
    """
    parser = configparser.RawConfigParser()
    if configuration_file:
        logger.verbose("Reading configuration file %s ..", format_path(configuration_file))
        loaded_files = parser.read(configuration_file)
        if len(loaded_files) == 0:
            msg = "Failed to read configuration file! (%s)"
            raise ValueError(msg % configuration_file)
    else:
        for config_file in LOCAL_CONFIG_FILE, GLOBAL_CONFIG_FILE:
            pathname = parse_path(config_file)
            if parser.read(pathname):
                logger.verbose("Reading configuration file %s ..", format_path(pathname))
                break
    for section in parser.sections():
        items = dict(parser.items(section))
        context_options = {}
        if coerce_boolean(items.get('use-sudo')):
            context_options['sudo'] = True
        if items.get('ssh-user'):
            context_options['ssh_user'] = items['ssh-user']
        location = coerce_location(section, **context_options)
        rotation_scheme = dict((name, coerce_retention_period(items[name]))
                               for name in SUPPORTED_FREQUENCIES
                               if name in items)
        options = dict(include_list=split(items.get('include-list', '')),
                       exclude_list=split(items.get('exclude-list', '')),
                       io_scheduling_class=items.get('ionice'),
                       strict=coerce_boolean(items.get('strict', 'yes')),
                       prefer_recent=coerce_boolean(items.get('prefer-recent', 'no')))
        yield location, rotation_scheme, options
Ejemplo n.º 17
0
    def get_file(cls, filename=None):
        """
        Load settings from an tuir configuration file.
        """

        if filename is None:
            filename = Config.CONFIG

        config = configparser.RawConfigParser()
        if os.path.exists(filename):
            with codecs.open(filename, encoding='utf-8') as fp:
                config.readfp(fp)

        return cls._parse_tuir_file(config)
Ejemplo n.º 18
0
    def __init__(self, airflow_home_dir=None, airflow_config_file_path=None):
        if airflow_home_dir is None:
            airflow_home_dir = DEFAULT_AIRFLOW_HOME_DIR
        if airflow_config_file_path is None:
            airflow_config_file_path = airflow_home_dir + "/airflow.cfg"
        self.airflow_home_dir = airflow_home_dir
        self.airflow_config_file_path = airflow_config_file_path

        if not os.path.isfile(airflow_config_file_path):
            print ("Cannot find Airflow Configuration file at '" + str(airflow_config_file_path) + "'!!!")
            sys.exit(1)

        self.conf = configparser.RawConfigParser()
        self.conf.read(airflow_config_file_path)
Ejemplo n.º 19
0
 def update_validation_section(self):
     """Update validation section in tempest.conf"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(self.conf_file)
     if not rconfig.has_section('validation'):
         rconfig.add_section('validation')
     rconfig.set(
         'validation', 'connect_method',
         'floating' if self.ext_net else 'fixed')
     rconfig.set(
         'validation', 'network_for_ssh',
         self.network.name if self.network else env.get("EXTERNAL_NETWORK"))
     with open(self.conf_file, 'w') as config_file:
         rconfig.write(config_file)
Ejemplo n.º 20
0
 def read(self, path):
     logger.info("Loading configuration file %s", path)
     parser = ConfigParser.RawConfigParser()
     parser.read(path)
     self.database.read(parser, 'database')
     self.logging.read(parser, 'logging')
     self.website.read(parser, 'website')
     self.index.read(parser, 'index')
     self.redis.read(parser, 'redis')
     self.replication.read(parser, 'replication')
     self.cluster.read(parser, 'cluster')
     self.rate_limiter.read(parser, 'rate_limiter')
     self.sentry.read(parser, 'sentry')
     self.uwsgi.read(parser, 'uwsgi')
Ejemplo n.º 21
0
 def read_vars(self, config, section='pastescript'):
     """
     Given a configuration filename, this will return a map of values.
     """
     result = {}
     p = configparser.RawConfigParser()
     p.read([config])
     if p.has_section(section):
         for key, value in p.items(section):
             if key.endswith('__eval__'):
                 result[key[:-len('__eval__')]] = eval(value)
             else:
                 result[key] = value
     return result
Ejemplo n.º 22
0
    def load_control_field_overrides(self, control_fields):
        """
        Apply user defined control field overrides.

        Looks for an ``stdeb.cfg`` file inside the Python package's source
        distribution and if found it merges the overrides into the control
        fields that will be embedded in the generated Debian binary package.

        This method first applies any overrides defined in the ``DEFAULT``
        section and then it applies any overrides defined in the section whose
        normalized name (see :func:`~py2deb.utils.package_names_match()`)
        matches that of the Python package.

        :param control_fields: The control field defaults constructed by py2deb
                               (a :class:`debian.deb822.Deb822` object).
        :returns: The merged defaults and overrides (a
                  :class:`debian.deb822.Deb822` object).
        """
        py2deb_cfg = os.path.join(self.requirement.source_directory,
                                  'stdeb.cfg')
        if not os.path.isfile(py2deb_cfg):
            logger.debug("Control field overrides file not found (%s).",
                         py2deb_cfg)
        else:
            logger.debug("Loading control field overrides from %s ..",
                         py2deb_cfg)
            parser = configparser.RawConfigParser()
            parser.read(py2deb_cfg)
            # Prepare to load the overrides from the DEFAULT section and
            # the section whose name matches that of the Python package.
            # DEFAULT is processed first on purpose.
            section_names = ['DEFAULT']
            # Match the normalized package name instead of the raw package
            # name because `python setup.py egg_info' normalizes
            # underscores in package names to dashes which can bite
            # unsuspecting users. For what it's worth, PEP-8 discourages
            # underscores in package names but doesn't forbid them:
            # https://www.python.org/dev/peps/pep-0008/#package-and-module-names
            section_names.extend(
                section_name for section_name in parser.sections()
                if package_names_match(section_name, self.python_name))
            for section_name in section_names:
                if parser.has_section(section_name):
                    overrides = dict(parser.items(section_name))
                    logger.debug(
                        "Found %i control file field override(s) in section %s of %s: %r",
                        len(overrides), section_name, py2deb_cfg, overrides)
                    control_fields = merge_control_fields(
                        control_fields, overrides)
        return control_fields
Ejemplo n.º 23
0
 def clean_rally_conf(rally_conf='/etc/rally/rally.conf'):
     """Clean Rally config"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(rally_conf)
     if rconfig.has_option('openstack', 'img_name_regex'):
         rconfig.remove_option('openstack', 'img_name_regex')
     if rconfig.has_option('openstack', 'swift_operator_role'):
         rconfig.remove_option('openstack', 'swift_operator_role')
     if rconfig.has_option('DEFAULT', 'log-file'):
         rconfig.remove_option('DEFAULT', 'log-file')
     if rconfig.has_option('DEFAULT', 'log_dir'):
         rconfig.remove_option('DEFAULT', 'log_dir')
     with open(rally_conf, 'wb') as config_file:
         rconfig.write(config_file)
Ejemplo n.º 24
0
    def _read_flake8_config(self):
        files = [
            os.path.join(self.working_dir, 'setup.cfg'),
            os.path.join(self.working_dir, 'tox.ini'),
        ]
        parser = configparser.RawConfigParser()
        try:
            parser.read(files)
        except configparser.ParsingError:
            logger.exception('Error parsing flake8 config file %s', files)

        if parser.has_section('flake8'):
            return dict(parser.items('flake8'))
        return {}
Ejemplo n.º 25
0
 def covered_modules(cls):
     """
     List the source modules listed in .coveragerc for which coverage
     will be measured.
     """
     coveragerc = configparser.RawConfigParser()
     coveragerc.read(cls.PYTHON_COVERAGERC)
     modules = coveragerc.get('run', 'source')
     result = []
     for module in modules.split('\n'):
         module = module.strip()
         if module:
             result.append(module)
     return result
Ejemplo n.º 26
0
 def clean_rally_logs(rally_conf='/etc/rally/rally.conf'):
     """Clean Rally config"""
     rconfig = configparser.RawConfigParser()
     rconfig.read(rally_conf)
     if rconfig.has_option('DEFAULT', 'use_stderr'):
         rconfig.remove_option('DEFAULT', 'use_stderr')
     if rconfig.has_option('DEFAULT', 'debug'):
         rconfig.remove_option('DEFAULT', 'debug')
     if rconfig.has_option('DEFAULT', 'log-file'):
         rconfig.remove_option('DEFAULT', 'log-file')
     if rconfig.has_option('DEFAULT', 'log_dir'):
         rconfig.remove_option('DEFAULT', 'log_dir')
     with open(rally_conf, 'w') as config_file:
         rconfig.write(config_file)
Ejemplo n.º 27
0
    def install(self):
        self.setPath()

        key_file = self.options['key-file']
        cert_file = self.options['cert-file']

        key_content = self.options.get('key-content', None)
        cert_content = self.options.get('cert-content', None)
        request_needed = True

        name = self.options['name']
        hash_ = hashlib.sha512(str2bytes(name)).hexdigest()
        key = os.path.join(self.ca_private, hash_ + self.ca_key_ext)
        certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext)

        # XXX Ugly hack to quickly provide custom certificate/key to everyone using the recipe
        if key_content and cert_content:
            self._checkCertificateKeyConsistency(key_content, cert_content)
            open(key, 'w').write(key_content)
            open(certificate, 'w').write(cert_content)
            request_needed = False
        else:
            parser = configparser.RawConfigParser()
            parser.add_section('certificate')
            parser.set('certificate', 'name', name)
            parser.set('certificate', 'key_file', key)
            parser.set('certificate', 'certificate_file', certificate)
            parser.write(open(os.path.join(self.request_directory, hash_),
                              'w'))

        for link in [key_file, cert_file]:
            if os.path.islink(link):
                os.unlink(link)
            elif os.path.exists(link):
                raise OSError("%r file should be a symbolic link." % link)

        os.symlink(key, key_file)
        os.symlink(certificate, cert_file)

        path_list = [key_file, cert_file]
        if request_needed:
            wrapper = self.createWrapper(
                self.options['wrapper'],
                (self.options['executable'], ),
                wait_list=(certificate, key),
            )
            path_list.append(wrapper)

        return path_list
Ejemplo n.º 28
0
    def __init__(self, fake=False, force_new_db=False):
        if not os.path.exists(DEPLOYMENT_FILE):
            subprocess.call(
                ["rally", "--log-file", "/dev/null", "deployment", "config"],
                stdout=open(DEPLOYMENT_FILE, "w"))

        # NOTE(sskripnick): we should change home dir to avoid races
        # and do not touch any user files in ~/.rally
        self.tmp_dir = tempfile.mkdtemp()
        self.env = copy.deepcopy(os.environ)
        self.env["HOME"] = self.tmp_dir
        self.config_filename = None
        self.method_name = None
        self.class_name = None

        caller_frame = inspect.currentframe().f_back
        if caller_frame.f_code.co_name == "__call__":
            caller_frame = caller_frame.f_back

        self.method_name = caller_frame.f_code.co_name
        if self.method_name == "setUp":
            raise Exception("No rally instance should be generated in "
                            "setUp method")

        test_object = caller_frame.f_locals["self"]
        self.class_name = test_object.__class__.__name__

        if force_new_db or ("RCI_KEEP_DB" not in os.environ):
            config_filename = os.path.join(self.tmp_dir, "conf")
            config = configparser.RawConfigParser()
            config.add_section("database")
            config.set("database", "connection",
                       "sqlite:///%s/db" % self.tmp_dir)
            with open(config_filename, "w") as conf:
                config.write(conf)
            self.args = ["rally", "--config-file", config_filename]
            subprocess.call(
                ["rally", "--config-file", config_filename, "db", "recreate"],
                env=self.env)
            self.config_filename = config_filename
        else:
            self.args = ["rally"]
            subprocess.call(["rally", "db", "recreate"], env=self.env)

        self.reports_root = os.environ.get("REPORTS_ROOT",
                                           "rally-cli-output-files")
        self._created_files = []
        self("deployment create --file %s --name MAIN" % DEPLOYMENT_FILE,
             write_report=False)
Ejemplo n.º 29
0
    def __init__(self):
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)-15s %(levelname)-6s %(message)s')
        self._logger = logging.getLogger()

        config_path = os.path.join(os.path.expanduser('~'), '.shipane_sdk',
                                   'config', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = configparser.RawConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"), )

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger,
                              **dict(self._config.items('ShiPanE')))
Ejemplo n.º 30
0
    def load_configuration(self):
        """Loads INI file from specified path.

        Method loads configuration from specified `path`
        and parses it with :py:class:`configparser.RawConfigParser`

        """
        cp = configparser.RawConfigParser()
        try:
            cp.readfp(open(self.CONFIG_FILE, 'r'))
            self._paste_config = cp
        except Exception as ex:
            log.error('Failed to parse %s', self.CONFIG_FILE)
            log.exception(ex)
            raise ex