Ejemplo n.º 1
0
    def test_properties_file_codec(self):
        data = {'key1': [1, "str1", '127.0.0.1', 3.1415926535, True, None],
                'key2': [2.0, 3, 0, "str1 str2"],
                'key3': ['str1', 'str2'],
                'key4': [],
                'key5': 5000,
                'key6': 'str1',
                'key7': 0,
                'key8': None,
                'key9': [['str1', 'str2'], ['str3', 'str4']],
                'key10': [['str1', 'str2', 'str3'], ['str3', 'str4'], 'str5']
                }

        self._test_file_codec(data, PropertiesCodec())
        self._test_file_codec(data, PropertiesCodec(
            string_mappings={'yes': True, 'no': False, "''": None}))
Ejemplo n.º 2
0
    def __init__(self, status):
        self.state_change_wait_time = CONF.state_change_wait_time
        self.status = status
        revision_dir = \
            guestagent_utils.build_file_path(
                os.path.join(MOUNT_POINT,
                             os.path.dirname(system.VERTICA_ADMIN)),
                ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)

        if not operating_system.exists(FAKE_CFG):
            operating_system.write_file(FAKE_CFG, '', as_root=True)
            operating_system.chown(FAKE_CFG,
                                   system.VERTICA_ADMIN,
                                   system.VERTICA_ADMIN_GRP,
                                   as_root=True)
            operating_system.chmod(FAKE_CFG,
                                   FileMode.ADD_GRP_RX_OTH_RX(),
                                   as_root=True)
        self.configuration_manager = \
            ConfigurationManager(FAKE_CFG, system.VERTICA_ADMIN,
                                 system.VERTICA_ADMIN_GRP,
                                 PropertiesCodec(delimiter='='),
                                 requires_root=True,
                                 override_strategy=ImportOverrideStrategy(
                                     revision_dir, "cnf"))
Ejemplo n.º 3
0
    def __init__(self, state_change_wait_time=None):
        """
        Sets default status and state_change_wait_time
        """
        if state_change_wait_time:
            self.state_change_wait_time = state_change_wait_time
        else:
            self.state_change_wait_time = CONF.state_change_wait_time

        revision_dir = guestagent_utils.build_file_path(
            os.path.dirname(system.REDIS_CONFIG),
            ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
        config_value_mappings = {'yes': True, 'no': False, "''": None}
        self._value_converter = StringConverter(config_value_mappings)
        self.configuration_manager = ConfigurationManager(
            system.REDIS_CONFIG,
            system.REDIS_OWNER,
            system.REDIS_OWNER,
            PropertiesCodec(unpack_singletons=False,
                            string_mappings=config_value_mappings),
            requires_root=True,
            override_strategy=OneFileOverrideStrategy(revision_dir))

        self.admin = self._build_admin_client()
        self.status = RedisAppStatus(self.admin)
Ejemplo n.º 4
0
    def init_config(self):
        if not operating_system.exists(MOUNT_POINT, True):
            operating_system.create_directory(MOUNT_POINT,
                                              system.DB2_INSTANCE_OWNER,
                                              system.DB2_INSTANCE_OWNER,
                                              as_root=True)
        """
        The database manager configuration file - db2systm is stored  under the
        /home/db2inst1/sqllib directory. To update the configuration
        parameters, DB2 recommends using the command - UPDATE DBM CONFIGURATION
        commands instead of directly updating the config file.

        The existing PropertiesCodec implementation has been reused to handle
        text-file operations. Configuration overrides are implemented using
        the ImportOverrideStrategy of the guestagent configuration manager.
        """
        LOG.debug("Initialize DB2 configuration")
        revision_dir = (
            guestagent_utils.build_file_path(
                os.path.join(MOUNT_POINT,
                             os.path.dirname(system.DB2_INSTANCE_OWNER)),
                ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
        )
        if not operating_system.exists(FAKE_CFG):
            operating_system.write_file(FAKE_CFG, '', as_root=True)
            operating_system.chown(FAKE_CFG, system.DB2_INSTANCE_OWNER,
                                   system.DB2_INSTANCE_OWNER, as_root=True)
        self.configuration_manager = (
            ConfigurationManager(FAKE_CFG, system.DB2_INSTANCE_OWNER,
                                 system.DB2_INSTANCE_OWNER,
                                 PropertiesCodec(delimiter='='),
                                 requires_root=True,
                                 override_strategy=ImportOverrideStrategy(
                                     revision_dir, "cnf"))
        )
        '''
        Below we are getting the database manager default configuration and
        saving it to the DB2_DEFAULT_CFG file. This is done to help with
        correctly resetting the configurations to the original values when
        user wants to detach a user-defined configuration group from an
        instance. DB2 provides a command to reset the database manager
        configuration parameters (RESET DBM CONFIGURATION) but this command
        resets all the configuration parameters to the system defaults. When
        we build a DB2 guest image there are certain configurations
        parameters like SVCENAME which we set so that the instance can start
        correctly. Hence resetting this value to the system default will
        render the instance in an unstable state. Instead, the recommended
        way for resetting a subset of configuration parameters is to save
        the output of GET DBM CONFIGURATION of the original configuration
        and then call UPDATE DBM CONFIGURATION to reset the value.
          http://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/
        com.ibm.db2.luw.admin.cmd.doc/doc/r0001970.html
        '''
        if not operating_system.exists(DB2_DEFAULT_CFG):
            run_command(system.GET_DBM_CONFIGURATION % {
                "dbm_config": DB2_DEFAULT_CFG})
        self.process_default_dbm_config()
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super(PgSqlConfig, self).__init__(*args, **kwargs)

        revision_dir = guestagent_utils.build_file_path(
            os.path.dirname(self.pgsql_config),
            ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
        self._configuration_manager = ConfigurationManager(
            self.pgsql_config, self.PGSQL_OWNER, self.PGSQL_OWNER,
            PropertiesCodec(
                delimiter='=',
                string_mappings={'on': True, 'off': False, "''": None}),
            requires_root=True,
            override_strategy=OneFileOverrideStrategy(revision_dir))
Ejemplo n.º 6
0
 def __init__(self):
     self._configuration_manager = ConfigurationManager(
         self.PGSQL_CONFIG,
         self.PGSQL_OWNER,
         self.PGSQL_OWNER,
         PropertiesCodec(delimiter='=',
                         string_mappings={
                             'on': True,
                             'off': False,
                             "''": None
                         }),
         requires_root=True,
         override_strategy=OneFileOverrideStrategy(
             self._init_overrides_dir()))
Ejemplo n.º 7
0
    def _apply_access_rules(self):
        LOG.debug("Applying database access rules.")

        # Connections to all resources are granted.
        #
        # Local access from administrative users is implicitly trusted.
        #
        # Remote access from the Trove's account is always rejected as
        # it is not needed and could be used by malicious users to hijack the
        # instance.
        #
        # Connections from other accounts always require a double-MD5-hashed
        # password.
        #
        # Make the rules readable only by the Postgres service.
        #
        # NOTE: The order of entries is important.
        # The first failure to authenticate stops the lookup.
        # That is why the 'local' connections validate first.
        # The OrderedDict is necessary to guarantee the iteration order.
        local_admins = ','.join([self.default_superuser_name, self.ADMIN_USER])
        remote_admins = self.ADMIN_USER
        access_rules = OrderedDict([
            ('local', [['all', local_admins, None, 'trust'],
                       ['replication', local_admins, None, 'trust'],
                       ['all', 'all', None, 'md5']]),
            ('host', [['all', local_admins, '127.0.0.1/32', 'trust'],
                      ['all', local_admins, '::1/128', 'trust'],
                      ['all', local_admins, 'localhost', 'trust'],
                      ['all', remote_admins, '0.0.0.0/0', 'reject'],
                      ['all', remote_admins, '::/0', 'reject'],
                      ['all', 'all', '0.0.0.0/0', 'md5'],
                      ['all', 'all', '::/0', 'md5']])
        ])
        operating_system.write_file(
            self.pgsql_hba_config,
            access_rules,
            PropertiesCodec(string_mappings={'\t': None}),
            as_root=True)
        operating_system.chown(self.pgsql_hba_config,
                               self.pgsql_owner,
                               self.pgsql_owner,
                               as_root=True)
        operating_system.chmod(self.pgsql_hba_config,
                               FileMode.SET_USR_RO,
                               as_root=True)
Ejemplo n.º 8
0
    def __init__(self):
        super(PgSqlApp, self).__init__()

        self._current_admin_user = None
        self.status = PgSqlAppStatus(self.pgsql_extra_bin_dir)

        revision_dir = guestagent_utils.build_file_path(
            os.path.dirname(self.pgsql_config),
            ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
        self.configuration_manager = ConfigurationManager(
            self.pgsql_config,
            self.pgsql_owner,
            self.pgsql_owner,
            PropertiesCodec(delimiter='=',
                            string_mappings={
                                'on': True,
                                'off': False,
                                "''": None
                            }),
            requires_root=True,
            override_strategy=OneFileOverrideStrategy(revision_dir))