Skip to content

Commit a85b24f

Browse files
committed
Extract building dist package out of prestoadmin_installer
Build binary files seems to be a better task for the build tool (like make) than for the product tests framework. Moreover product tests framework was caching the result in the `tmp/installer` directory so when the changes were introduced to presto-admin, package was not rebuild. So it was easy to run product tests with the old version of product-tests. Instead of that building distribution package was moved to Makefile. Moreover, disregarding how this file is created it will be stored in `dist` directory. No more need for having `tmp/installer`. Fixes prestodb#189
1 parent c75b74d commit a85b24f

File tree

3 files changed

+22
-90
lines changed

3 files changed

+22
-90
lines changed

Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.PHONY: clean-all clean clean-eggs clean-build clean-pyc clean-test-containers clean-test \
22
clean-docs lint smoke test test-all test-rpm coverage docs open-docs release release-builds \
3-
dist dist-online dist-offline wheel install precommit
3+
dist dist-online dist-offline wheel install precommit \
4+
docker-dist docker-dist-online docker-dist-offline
45

56
help:
67
@echo "precommit - run \`quick' tests and tasks that should pass or succeed prior to pushing"
@@ -25,6 +26,9 @@ help:
2526
@echo "dist - package and build installer that requires an Internet connection"
2627
@echo "dist-online - package and build installer that requires an Internet connection"
2728
@echo "dist-offline - package and build installer that does not require an Internet connection"
29+
@echo "docker-dist - package and build installer (within a docker container) that requires an Internet connection"
30+
@echo "docker-dist-online - package and build installer (within a docker container) that requires an Internet connection"
31+
@echo "docker-dist-offline - package and build installer (within a docker container) that does not require an Internet connection"
2832
@echo "wheel - build wheel only"
2933
@echo "install - install the package to the active Python's site-packages"
3034

@@ -121,6 +125,14 @@ dist-offline: clean-build clean-pyc
121125
python setup.py bdist_prestoadmin
122126
ls -l dist
123127

128+
docker-dist: docker-dist-online
129+
130+
docker-dist-online: clean-build clean-pyc
131+
docker run --rm -v `pwd`:/workdir -w /workdir -u `id -u`:`id -g` teradatalabs/presto-admin-devenv make dist-online
132+
133+
docker-dist-offline: clean-build clean-pyc
134+
docker run --rm -v `pwd`:/workdir -w /workdir -u `id -u`:`id -g` teradatalabs/presto-admin-devenv make dist-offline
135+
124136
wheel: clean
125137
python setup.py bdist_wheel
126138
ls -l dist

tests/docker_cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
DEFAULT_DOCKER_MOUNT_POINT, DEFAULT_LOCAL_MOUNT_POINT, \
3737
BASE_TD_IMAGE_NAME
3838

39-
DIST_DIR = os.path.join(main_dir, 'tmp/installer')
39+
DIST_DIR = os.path.join(main_dir, 'dist')
4040

4141

4242
class DockerCluster(BaseCluster):

tests/product/prestoadmin_installer.py

+8-88
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,11 @@
1616
Module for installing prestoadmin on a cluster.
1717
"""
1818

19-
import errno
2019
import fnmatch
21-
import shutil
2220
import os
2321

24-
import prestoadmin
25-
2622
from tests.base_installer import BaseInstaller
2723
from tests.product.constants import LOCAL_RESOURCES_DIR
28-
from tests.no_hadoop_bare_image_provider import NoHadoopBareImageProvider
29-
30-
from tests.docker_cluster import DockerCluster
3124

3225

3326
class PrestoadminInstaller(BaseInstaller):
@@ -39,17 +32,18 @@ def get_dependencies():
3932
return []
4033

4134
def install(self, cluster=None, dist_dir=None):
42-
# Passing in a cluster supports the installation tests. We need to be
43-
# able to try an installation against an unsupported OS, and for that
44-
# testcase, we create a cluster that is local to the testcase and then
45-
# run the install on it. We can't replace self.cluster with the local
46-
# cluster in the test, because that would prevent the test's "regular"
47-
# cluster from getting torn down.
4835
if not cluster:
4936
cluster = self.testcase.cluster
5037

5138
if not dist_dir:
52-
dist_dir = self._build_dist_if_necessary(cluster)
39+
dist_dir = cluster.get_dist_dir(unique=False)
40+
41+
if (not os.path.isdir(dist_dir) or
42+
len(fnmatch.filter(os.listdir(dist_dir), 'prestoadmin-*.tar.bz2')) == 0):
43+
self.testcase.fail(
44+
'Unable to find presto-admin package. '
45+
'Have you run one of `make dist*` or `make docker-dist*` command?')
46+
5347
self._copy_dist_to_host(cluster, dist_dir, cluster.master)
5448
cluster.copy_to_host(
5549
LOCAL_RESOURCES_DIR + "/install-admin.sh", cluster.master)
@@ -69,80 +63,6 @@ def assert_installed(testcase, msg=None):
6963
def get_keywords(self):
7064
return {}
7165

72-
def _build_dist_if_necessary(self, cluster, unique=False):
73-
if (not os.path.isdir(cluster.get_dist_dir(unique)) or
74-
not fnmatch.filter(
75-
os.listdir(cluster.get_dist_dir(unique)),
76-
'prestoadmin-*.tar.bz2')):
77-
self._build_installer_in_docker(cluster, unique=unique)
78-
return cluster.get_dist_dir(unique)
79-
80-
def _build_installer_in_docker(self, cluster, online_installer=None,
81-
unique=False):
82-
if online_installer is None:
83-
paTestOnlineInstaller = os.environ.get('PA_TEST_ONLINE_INSTALLER')
84-
online_installer = paTestOnlineInstaller is not None
85-
86-
container_name = 'installer'
87-
cluster_type = 'installer_builder'
88-
bare_image_provider = NoHadoopBareImageProvider()
89-
90-
installer_container, created_bare = DockerCluster.start_cluster(
91-
bare_image_provider, cluster_type, 'installer', [])
92-
93-
if created_bare:
94-
installer_container.commit_images(
95-
bare_image_provider, cluster_type)
96-
97-
try:
98-
shutil.copytree(
99-
prestoadmin.main_dir,
100-
os.path.join(
101-
installer_container.get_local_mount_dir(container_name),
102-
'presto-admin'),
103-
ignore=shutil.ignore_patterns('tmp', '.git', 'presto*.rpm')
104-
)
105-
106-
# Pin pip to 7.1.2 because 8.0.0 removed support for distutils
107-
# installed projects, of which the system setuptools is one on our
108-
# Docker image. pip 8.0.1 or 8.0.2 replaced the error with a
109-
# deprecation warning, and also warns that Python 2.6 is
110-
# deprecated. While we still need to support Python 2.6, we'll pin
111-
# pip to a 7.x version, but we should revisit this once we no
112-
# longer need to support 2.6:
113-
# https://github.com/pypa/pip/issues/3384
114-
installer_container.run_script_on_host(
115-
'set -e\n'
116-
'pip install --upgrade pip==7.1.2\n'
117-
'pip install --upgrade wheel==0.23.0\n'
118-
'pip install --upgrade setuptools==20.1.1\n'
119-
'mv %s/presto-admin ~/\n'
120-
'cd ~/presto-admin\n'
121-
'make %s\n'
122-
'cp dist/prestoadmin-*.tar.bz2 %s'
123-
% (installer_container.mount_dir,
124-
'dist' if online_installer else 'dist-offline',
125-
installer_container.mount_dir),
126-
container_name)
127-
128-
try:
129-
os.makedirs(cluster.get_dist_dir(unique))
130-
except OSError, e:
131-
if e.errno != errno.EEXIST:
132-
raise
133-
local_container_dist_dir = os.path.join(
134-
prestoadmin.main_dir,
135-
installer_container.get_local_mount_dir(container_name)
136-
)
137-
installer_file = fnmatch.filter(
138-
os.listdir(local_container_dist_dir),
139-
'prestoadmin-*.tar.bz2')[0]
140-
shutil.copy(
141-
os.path.join(local_container_dist_dir, installer_file),
142-
cluster.get_dist_dir(unique))
143-
finally:
144-
installer_container.tear_down()
145-
14666
@staticmethod
14767
def _copy_dist_to_host(cluster, local_dist_dir, dest_host):
14868
for dist_file in os.listdir(local_dist_dir):

0 commit comments

Comments
 (0)