Repository: elastic/rally

Issue:
Rally cannot differentiate between default and OSS distribution after download
**Rally version** (get with `esrally --version`): all versions

**Description of the problem including expected versus actual behavior**:

When we run a benchmark first with the OSS distribution and then one with the default one, Rally raises the following error:

```
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/.rally/benchmarks/races/2018-06-18-05-44-23/rally-node-0/install/elasticsearch-6.3.0/bin/elasticsearch-certgen'
```

**Steps to reproduce**:

1. Ensure that `~/.rally/benchmarks/distributions/` is empty

2. Run one benchmark with the OSS distribution:

```
esrally --test-mode --distribution-version=6.3.0 --car="defaults"
```

3. Run one benchmark with the default distribution and enable X-Pack Security:

```
esrally --test-mode --distribution-version=6.3.0 --car="defaults,x-pack-security" --client-options="basic_auth_user:'rally',basic_auth_password:'rally-password',use_ssl:true,verify_certs:false,timeout:60,request_timeout:60"
```

Discussion:

Patch:
diff --git a/esrally/mechanic/supplier.py b/esrally/mechanic/supplier.py
index fa001711..a59d640f 100644
--- a/esrally/mechanic/supplier.py
+++ b/esrally/mechanic/supplier.py
@@ -293,8 +293,8 @@ class ElasticsearchDistributionSupplier:
 
     def fetch(self):
         io.ensure_dir(self.distributions_root)
-        distribution_path = "%s/elasticsearch-%s.tar.gz" % (self.distributions_root, self.version)
         download_url = self.repo.download_url
+        distribution_path = os.path.join(self.distributions_root, self.repo.file_name)
         self.logger.info("Resolved download URL [%s] for version [%s]", download_url, self.version)
         if not os.path.isfile(distribution_path) or not self.repo.cache:
             try:
@@ -487,6 +487,11 @@ class DistributionRepository:
         override_key = "{}.url".format(self.name)
         return self._url_for(override_key, default_key)
 
+    @property
+    def file_name(self):
+        url = self.download_url
+        return url[url.rfind("/") + 1:]
+
     def plugin_download_url(self, plugin_name):
         # team repo
         default_key = "plugin_{}_{}_url".format(plugin_name, self.name)


Test patch:
diff --git a/tests/mechanic/supplier_test.py b/tests/mechanic/supplier_test.py
index cbd5dbe6..af16e456 100644
--- a/tests/mechanic/supplier_test.py
+++ b/tests/mechanic/supplier_test.py
@@ -512,6 +512,7 @@ class DistributionRepositoryTests(TestCase):
             "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)
         self.assertTrue(repo.cache)
 
     def test_release_repo_config_with_user_url(self):
@@ -522,6 +523,7 @@ class DistributionRepositoryTests(TestCase):
             "release.cache": "false"
         }, version="2.4.3")
         self.assertEqual("https://es-mirror.example.org/downloads/elasticsearch/elasticsearch-2.4.3.tar.gz", repo.download_url)
+        self.assertEqual("elasticsearch-2.4.3.tar.gz", repo.file_name)
         self.assertFalse(repo.cache)
 
     def test_missing_url(self):