Exemple #1
0
    def test_path_config_invalid_setting_in_file(self):
        """Tests detecting invalid settings defined in a TOML configuration
        file.

        Creates a temporary directory and writes a validator.toml config file
        with an invalid setting inside, then loads that config and verifies an exception is thrown.


        The test also attempts to avoid environment variables from interfering
        with the test by clearing os.environ and restoring it after the test.
        """
        orig_environ = dict(os.environ)
        os.environ.clear()
        directory = tempfile.mkdtemp(prefix="test-path-config-")
        try:
            os.environ['SAWTOOTH_HOME'] = directory

            config_dir = os.path.join(directory, 'etc')
            os.mkdir(config_dir)
            filename = os.path.join(config_dir, 'validator.toml')
            with open(filename, 'w') as fd:
                fd.write('invalid = "a value"')
                fd.write(os.linesep)
            with self.assertRaises(LocalConfigurationError):
                load_toml_validator_config(filename)
        finally:
            os.environ.clear()
            os.environ.update(orig_environ)
            shutil.rmtree(directory)
Exemple #2
0
    def test_path_config_invalid_setting_in_file(self):
        """Tests detecting invalid settings defined in a TOML configuration
        file.

        Creates a temporary directory and writes a validator.toml config file
        with an invalid setting inside, then loads that config and verifies an exception is thrown.


        The test also attempts to avoid environment variables from interfering
        with the test by clearing os.environ and restoring it after the test.
        """
        orig_environ = dict(os.environ)
        os.environ.clear()
        directory = tempfile.mkdtemp(prefix="test-path-config-")
        try:
            os.environ['SAWTOOTH_HOME'] = directory

            config_dir = os.path.join(directory, 'etc')
            os.mkdir(config_dir)
            filename = os.path.join(config_dir, 'validator.toml')
            with open(filename, 'w') as fd:
                fd.write('invalid = "a value"')
                fd.write(os.linesep)
            with self.assertRaises(LocalConfigurationError):
                load_toml_validator_config(filename)
        finally:
            os.environ.clear()
            os.environ.update(orig_environ)
            shutil.rmtree(directory)
Exemple #3
0
def load_validator_config(first_config, config_dir):
    default_validator_config = load_default_validator_config()
    conf_file = os.path.join(config_dir, 'validator.toml')

    toml_config = load_toml_validator_config(conf_file)

    return merge_validator_config(
        configs=[first_config, toml_config, default_validator_config])
Exemple #4
0
def load_validator_config(first_config, config_dir):
    default_validator_config = load_default_validator_config()
    conf_file = os.path.join(config_dir, 'validator.toml')

    toml_config = load_toml_validator_config(conf_file)

    return merge_validator_config(
        configs=[first_config, toml_config, default_validator_config])
Exemple #5
0
    def test_validator_config_load_from_file(self):
        """Tests loading config settings from a TOML configuration file.

        Creates a temporary directory and writes a validator.toml config file,
        then loads that config and verifies all the validator settings are
        their expected values.

        The test also attempts to avoid environment variables from interfering
        with the test by clearing os.environ and restoring it after the test.
        """
        orig_environ = dict(os.environ)
        os.environ.clear()
        directory = tempfile.mkdtemp(prefix="test-path-config-")
        try:
            os.environ['SAWTOOTH_HOME'] = directory

            config_dir = os.path.join(directory, 'etc')
            os.mkdir(config_dir)
            filename = os.path.join(config_dir, 'validator.toml')
            with open(filename, 'w') as fd:
                fd.write('bind = ["network:tcp://test:8800",'
                         '"component:tcp://test:4004"]')
                fd.write(os.linesep)
                fd.write('peering = "dynamic"')
                fd.write(os.linesep)
                fd.write('endpoint = "tcp://test:8800"')
                fd.write(os.linesep)
                fd.write('peers = ["tcp://peer:8801"]')
                fd.write(os.linesep)
                fd.write('seeds = ["tcp://peer:8802"]')
                fd.write(os.linesep)
                fd.write('scheduler = "serial"')
                fd.write(os.linesep)
                fd.write('[roles]')
                fd.write(os.linesep)
                fd.write('network = "trust"')
                fd.write(os.linesep)

            config = load_toml_validator_config(filename)
            self.assertEqual(config.bind_network, "tcp://test:8800")
            self.assertEqual(config.bind_component, "tcp://test:4004")
            self.assertEqual(config.peering, "dynamic")
            self.assertEqual(config.endpoint, "tcp://test:8800")
            self.assertEqual(config.peers, ["tcp://peer:8801"])
            self.assertEqual(config.seeds, ["tcp://peer:8802"])
            self.assertEqual(config.scheduler, "serial")
            self.assertEquals(config.roles, {"network": "trust"})

        finally:
            os.environ.clear()
            os.environ.update(orig_environ)
            shutil.rmtree(directory)
Exemple #6
0
    def test_validator_config_load_from_file(self):
        """Tests loading config settings from a TOML configuration file.

        Creates a temporary directory and writes a validator.toml config file,
        then loads that config and verifies all the validator settings are
        their expected values.

        The test also attempts to avoid environment variables from interfering
        with the test by clearing os.environ and restoring it after the test.
        """
        orig_environ = dict(os.environ)
        os.environ.clear()
        directory = tempfile.mkdtemp(prefix="test-path-config-")
        try:
            os.environ['SAWTOOTH_HOME'] = directory

            config_dir = os.path.join(directory, 'etc')
            os.mkdir(config_dir)
            filename = os.path.join(config_dir, 'validator.toml')
            with open(filename, 'w') as fd:
                fd.write('bind = ["network:tcp://test:8800",'
                         '"component:tcp://test:4004"]')
                fd.write(os.linesep)
                fd.write('peering = "dynamic"')
                fd.write(os.linesep)
                fd.write('endpoint = "tcp://test:8800"')
                fd.write(os.linesep)
                fd.write('peers = ["tcp://peer:8801"]')
                fd.write(os.linesep)
                fd.write('seeds = ["tcp://peer:8802"]')

            config = load_toml_validator_config(filename)
            self.assertEqual(config.bind_network, "tcp://test:8800")
            self.assertEqual(config.bind_component, "tcp://test:4004")
            self.assertEqual(config.peering, "dynamic")
            self.assertEqual(config.endpoint, "tcp://test:8800")
            self.assertEqual(config.peers, ["tcp://peer:8801"])
            self.assertEqual(config.seeds, ["tcp://peer:8802"])
        finally:
            os.environ.clear()
            os.environ.update(orig_environ)
            shutil.rmtree(directory)
Exemple #7
0
    def test_validator_config_load_from_file(self):
        """Tests loading config settings from a TOML configuration file.

        Creates a temporary directory and writes a validator.toml config file,
        then loads that config and verifies all the validator settings are
        their expected values.

        The test also attempts to avoid environment variables from interfering
        with the test by clearing os.environ and restoring it after the test.
        """
        orig_environ = dict(os.environ)
        os.environ.clear()
        directory = tempfile.mkdtemp(prefix="test-path-config-")
        try:
            os.environ['SAWTOOTH_HOME'] = directory

            config_dir = os.path.join(directory, 'etc')
            os.mkdir(config_dir)
            filename = os.path.join(config_dir, 'validator.toml')
            with open(filename, 'w') as fd:
                fd.write('bind = ["network:tcp://test:8800",'
                         '"component:tcp://test:4004"]')
                fd.write(os.linesep)
                fd.write('peering = "dynamic"')
                fd.write(os.linesep)
                fd.write('endpoint = "tcp://test:8800"')
                fd.write(os.linesep)
                fd.write('peers = ["tcp://peer:8801"]')
                fd.write(os.linesep)
                fd.write('seeds = ["tcp://peer:8802"]')
                fd.write(os.linesep)
                fd.write('scheduler = "serial"')
                fd.write(os.linesep)
                fd.write('opentsdb_db = "data_base"')
                fd.write(os.linesep)
                fd.write('opentsdb_url = "http://data_base:0000"')
                fd.write(os.linesep)
                fd.write('opentsdb_username = "******"')
                fd.write(os.linesep)
                fd.write('opentsdb_password = "******"')
                fd.write(os.linesep)
                fd.write('minimum_peer_connectivity = 1')
                fd.write(os.linesep)
                fd.write('maximum_peer_connectivity = 100')
                fd.write(os.linesep)
                fd.write('[roles]')
                fd.write(os.linesep)
                fd.write('network = "trust"')
                fd.write(os.linesep)

            config = load_toml_validator_config(filename)
            self.assertEqual(config.bind_network, "tcp://test:8800")
            self.assertEqual(config.bind_component, "tcp://test:4004")
            self.assertEqual(config.peering, "dynamic")
            self.assertEqual(config.endpoint, "tcp://test:8800")
            self.assertEqual(config.peers, ["tcp://peer:8801"])
            self.assertEqual(config.seeds, ["tcp://peer:8802"])
            self.assertEqual(config.scheduler, "serial")
            self.assertEqual(config.roles, {"network": "trust"})
            self.assertEqual(config.opentsdb_db, "data_base")
            self.assertEqual(config.opentsdb_url, "http://data_base:0000")
            self.assertEqual(config.opentsdb_username, "name")
            self.assertEqual(config.opentsdb_password, "secret")
            self.assertEqual(config.minimum_peer_connectivity, 1)
            self.assertEqual(config.maximum_peer_connectivity, 100)

        finally:
            os.environ.clear()
            os.environ.update(orig_environ)
            shutil.rmtree(directory)