summaryrefslogtreecommitdiff
path: root/test/fixtures.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2014-08-12 16:24:25 -0700
committerDana Powers <dana.powers@rd.io>2014-08-12 17:23:35 -0700
commit1908ee83d52efbc854c0b51213ff3122e8e81b97 (patch)
treef158e50329e940dcebd3b5c9acc9e0276590a6b0 /test/fixtures.py
parentc37dc89c6c14b27e28a94afa5edd01643e820015 (diff)
downloadkafka-python-1908ee83d52efbc854c0b51213ff3122e8e81b97.tar.gz
Add Fixtures.download_official_distribution to get binaries from apache.org
Diffstat (limited to 'test/fixtures.py')
-rw-r--r--test/fixtures.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/fixtures.py b/test/fixtures.py
index df8cd42..b497601 100644
--- a/test/fixtures.py
+++ b/test/fixtures.py
@@ -1,9 +1,11 @@
import logging
import glob
import os
+import os.path
import shutil
import subprocess
import tempfile
+import urllib2
import uuid
from urlparse import urlparse
@@ -18,6 +20,43 @@ class Fixture(object):
ivy_root = os.environ.get('IVY_ROOT', os.path.expanduser("~/.ivy2/cache"))
@classmethod
+ def download_official_distribution(cls,
+ kafka_version=None,
+ scala_version=None,
+ output_dir=None):
+ if not kafka_version:
+ kafka_version = cls.kafka_version
+ if not scala_version:
+ scala_version = cls.scala_version
+ if not output_dir:
+ output_dir = os.path.join(cls.project_root, 'servers', 'dist')
+
+ distfile = 'kafka_%s-%s' % (scala_version, kafka_version,)
+ url_base = 'https://archive.apache.org/dist/kafka/%s/' % (kafka_version,)
+ output_file = os.path.join(output_dir, distfile + '.tgz')
+
+ if os.path.isfile(output_file):
+ logging.info("Found file already on disk: %s" % output_file)
+ return output_file
+
+ # New tarballs are .tgz, older ones are sometimes .tar.gz
+ try:
+ url = url_base + distfile + '.tgz'
+ logging.info("Attempting to download %s" % (url,))
+ response = urllib2.urlopen(url)
+ except urllib2.HTTPError:
+ logging.exception("HTTP Error")
+ url = url_base + distfile + '.tar.gz'
+ logging.info("Attempting to download %s" % (url,))
+ response = urllib2.urlopen(url)
+
+ logging.info("Saving distribution file to %s" % (output_file,))
+ with open(os.path.join(output_dir, distfile + '.tgz'), 'w') as f:
+ f.write(response.read())
+
+ return output_file
+
+ @classmethod
def test_resource(cls, filename):
return os.path.join(cls.project_root, "servers", cls.kafka_version, "resources", filename)