Skip to content

Commit

Permalink
Add support for OSNAME and ARCH variables in dist repo URLs. (elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
drawlerr authored Oct 2, 2019
1 parent b4ba737 commit fc211de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
16 changes: 14 additions & 2 deletions esrally/mechanic/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from esrally import exceptions, PROGRAM_NAME
from esrally.exceptions import BuildError, SystemSetupError
from esrally.utils import git, io, process, net, jvm, convert
from esrally.utils import git, io, process, net, jvm, convert, sysstats

# e.g. my-plugin:current - we cannot simply use String#split(":") as this would not work for timestamp-based revisions
REVISION_PATTERN = r"(\w.*?):(.*)"
Expand Down Expand Up @@ -525,7 +525,19 @@ def _url_for(self, user_defined_key, default_key, mandatory=True):
raise exceptions.SystemSetupError("Neither config key [{}] nor [{}] is defined.".format(user_defined_key, default_key))
else:
return None
return url_template.replace("{{VERSION}}", self.version)
return self._substitute_vars(url_template)

def _substitute_vars(self, s):
substitutions = {
"{{VERSION}}": self.version,
"{{OSNAME}}": sysstats.os_name().lower(),
"{{ARCH}}": sysstats.cpu_arch().lower()
}
r = s
for key, replacement in substitutions.items():
r = r.replace(key, replacement)
return r


@property
def cache(self):
Expand Down
7 changes: 7 additions & 0 deletions esrally/utils/sysstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def cpu_model():
return "Unknown"


def cpu_arch():
"""
:return: The CPU architecture name.
"""
return platform.uname().machine


def disks():
# only physical partitions (no memory partitions etc)
return psutil.disk_partitions(all=False)
Expand Down
12 changes: 7 additions & 5 deletions tests/mechanic/supplier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,15 @@ def test_create_suppliers_for_es_and_plugin_source_build(self):


class DistributionRepositoryTests(TestCase):
def test_release_repo_config_with_default_url(self):
@mock.patch("esrally.utils.sysstats.os_name", return_value="Linux")
@mock.patch("esrally.utils.sysstats.cpu_arch", return_value="X86_64")
def test_release_repo_config_with_default_url(self, os_name, cpu_arch):
repo = supplier.DistributionRepository(name="release", distribution_config={
"release_url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
"release_url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz",
"release.cache": "true"
}, version="5.5.0")
self.assertEqual("https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz", repo.download_url)
self.assertEqual("elasticsearch-5.5.0.tar.gz", repo.file_name)
}, version="7.3.2")
self.assertEqual("https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz", repo.download_url)
self.assertEqual("elasticsearch-7.3.2-linux-x86_64.tar.gz", repo.file_name)
self.assertTrue(repo.cache)

def test_release_repo_config_with_user_url(self):
Expand Down

0 comments on commit fc211de

Please sign in to comment.