Skip to content

Commit

Permalink
Disable interpolation for config file
Browse files Browse the repository at this point in the history
With this commit we disable interpolation in Rally's configuration file.
It causes trouble with certain characters in passwords and was only used
sparingly anyway.

Closes #519
Relates #524
  • Loading branch information
danielmitterdorfer authored Jun 14, 2018
1 parent 54edbcc commit efa3c85
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
12 changes: 8 additions & 4 deletions esrally/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def present(self):
"""
return os.path.isfile(self.location)

def load(self, interpolation=configparser.ExtendedInterpolation()):
config = configparser.ConfigParser(interpolation=interpolation)
def load(self):
config = configparser.ConfigParser()
config.read(self.location, encoding="utf-8")
return config

Expand Down Expand Up @@ -370,7 +370,7 @@ def create_config(self, config_file, advanced_config=False, assume_defaults=Fals
config["source"]["elasticsearch.src.subdir"] = io.basename(source_dir)

config["benchmarks"] = {}
config["benchmarks"]["local.dataset.cache"] = "${node:root.dir}/data"
config["benchmarks"]["local.dataset.cache"] = os.path.join(root_dir, "data")

config["reporting"] = {}
config["reporting"]["datastore.type"] = data_store_type
Expand Down Expand Up @@ -515,7 +515,7 @@ def migrate(config_file, current_version, target_version, out=print, i=input):
% (target_version, current_version))
# but first a backup...
config_file.backup()
config = config_file.load(interpolation=None)
config = config_file.load()

if current_version == 12 and target_version > current_version:
# the current configuration allows to benchmark from sources
Expand Down Expand Up @@ -633,6 +633,10 @@ def warn_if_plugin_build_task_is_in_use(config):

if current_version == 16 and target_version > current_version:
config.pop("runtime", None)
if "benchmarks" in config and "local.dataset.cache" in config["benchmarks"]:
if config["benchmarks"]["local.dataset.cache"] == "${node:root.dir}/data":
root_dir = config["node"]["root.dir"]
config["benchmarks"]["local.dataset.cache"] = os.path.join(root_dir, "data")
current_version = 17
config["meta"]["config.version"] = str(current_version)

Expand Down
32 changes: 29 additions & 3 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,24 @@ def test_create_simple_config(self, guess_install_location, working_copy):
for k, v in config_store.config[section].items():
print("%s::%s: %s" % (section, k, v))

root_dir = io.normalize_path(os.path.abspath("./in-memory/benchmarks"))
self.assertTrue("meta" in config_store.config)
self.assertEqual(str(config.Config.CURRENT_CONFIG_VERSION), config_store.config["meta"]["config.version"])

self.assertTrue("system" in config_store.config)
self.assertEqual("local", config_store.config["system"]["env.name"])

self.assertTrue("node" in config_store.config)
self.assertEqual(io.normalize_path(os.path.abspath("./in-memory/benchmarks")), config_store.config["node"]["root.dir"])
self.assertEqual(io.normalize_path(os.path.abspath("./in-memory/benchmarks/src")), config_store.config["node"]["src.root.dir"])

self.assertEqual(root_dir, config_store.config["node"]["root.dir"])
self.assertEqual(os.path.join(root_dir, "src"), config_store.config["node"]["src.root.dir"])

self.assertTrue("source" in config_store.config)
self.assertEqual("https://github.com/elastic/elasticsearch.git", config_store.config["source"]["remote.repo.url"])
self.assertEqual("elasticsearch", config_store.config["source"]["elasticsearch.src.subdir"])

self.assertTrue("benchmarks" in config_store.config)
self.assertEqual("${node:root.dir}/data", config_store.config["benchmarks"]["local.dataset.cache"])
self.assertEqual(os.path.join(root_dir, "data"), config_store.config["benchmarks"]["local.dataset.cache"])

self.assertTrue("reporting" in config_store.config)
self.assertEqual("in-memory", config_store.config["reporting"]["datastore.type"])
Expand Down Expand Up @@ -765,5 +767,29 @@ def test_migrate_from_15_to_16(self):
self.assertIn("distributions", config_file.config)
self.assertNotIn("release.url", config_file.config["distributions"])

def test_migrate_from_16_to_17(self):
config_file = InMemoryConfigStore("test")
sample_config = {
"meta": {
"config.version": 16
},
"node": {
"root.dir": "/home/user/.rally/benchmarks"
},
"runtime": {
"java.home": "/usr/local/javas/10"
},
"benchmarks": {
"local.dataset.cache": "${node:root.dir}/data"
}
}
config_file.store(sample_config)
config.migrate(config_file, 16, 17, out=null_output)

self.assertTrue(config_file.backup_created)
self.assertEqual("17", config_file.config["meta"]["config.version"])
self.assertNotIn("runtime", config_file.config)
self.assertEqual("/home/user/.rally/benchmarks/data", config_file.config["benchmarks"]["local.dataset.cache"])



0 comments on commit efa3c85

Please sign in to comment.