Skip to content

Commit 1d451dd

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 #189
1 parent f5e6c9b commit 1d451dd

6 files changed

+35
-120
lines changed

.travis.yml.disabled

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ env:
1717
- PRODUCT_TEST_GROUP=5
1818
- PRODUCT_TEST_GROUP=6
1919
- PRODUCT_TEST_GROUP=7
20-
install:
20+
before_script:
2121
- pip install --upgrade pip==6.1.1
2222
- pip install -r requirements.txt
23-
before_script:
2423
- make docker-images
24+
install:
25+
- make docker-dist-online
2526
script:
2627
- |
2728
if [ -v PRODUCT_TEST_GROUP ]; then

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:1 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:1 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

+14-94
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,18 +32,13 @@ 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)
53-
self._copy_dist_to_host(cluster, dist_dir, cluster.master)
39+
dist_dir = cluster.get_dist_dir(unique=False)
40+
41+
self.copy_dist_to_master(cluster, dist_dir)
5442
cluster.copy_to_host(
5543
LOCAL_RESOURCES_DIR + "/install-admin.sh", cluster.master)
5644
cluster.exec_cmd_on_host(
@@ -69,84 +57,16 @@ def assert_installed(testcase, msg=None):
6957
def get_keywords(self):
7058
return {}
7159

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-
146-
@staticmethod
147-
def _copy_dist_to_host(cluster, local_dist_dir, dest_host):
148-
for dist_file in os.listdir(local_dist_dir):
60+
def copy_dist_to_master(self, cluster, dist_dir):
61+
if (not os.path.isdir(dist_dir) or
62+
len(fnmatch.filter(
63+
os.listdir(dist_dir),
64+
'prestoadmin-*.tar.bz2')) == 0):
65+
self.testcase.fail(
66+
'Unable to find presto-admin package. Have you run one of '
67+
'`make dist*` or `make docker-dist*` command?')
68+
for dist_file in os.listdir(dist_dir):
14969
if fnmatch.fnmatch(dist_file, "prestoadmin-*.tar.bz2"):
15070
cluster.copy_to_host(
151-
os.path.join(local_dist_dir, dist_file),
152-
dest_host)
71+
os.path.join(dist_dir, dist_file),
72+
cluster.master)

tests/product/standalone/test_installation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def setUp(self):
4545
super(TestInstallation, self).setUp()
4646
self.pa_installer = PrestoadminInstaller(self)
4747
self.setup_cluster(NoHadoopBareImageProvider(), self.BARE_CLUSTER)
48-
dist_dir = self.pa_installer._build_dist_if_necessary(self.cluster)
49-
self.pa_installer._copy_dist_to_host(self.cluster, dist_dir,
50-
self.cluster.master)
48+
self.pa_installer.copy_dist_to_master(
49+
self.cluster,
50+
self.cluster.get_dist_dir(unique=False))
5151

5252
@attr('smoketest')
5353
@docker_only

tests/product/test_installer.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,12 @@ def tearDown(self):
4242
self.centos_container.tear_down()
4343

4444
@attr('smoketest')
45-
def test_online_installer(self):
46-
self.pa_installer._build_installer_in_docker(self.centos_container,
47-
online_installer=True,
48-
unique=True)
45+
def test_installer(self):
4946
self.__verify_third_party_dir(False)
5047
self.pa_installer.install(
5148
dist_dir=self.centos_container.get_dist_dir(unique=True))
5249
self.run_prestoadmin('--help', raise_error=True)
5350

54-
@attr('smoketest', 'offline_installer')
55-
def test_offline_installer(self):
56-
self.pa_installer._build_installer_in_docker(
57-
self.centos_container, online_installer=False, unique=True)
58-
self.__verify_third_party_dir(True)
59-
self.centos_container.exec_cmd_on_host(
60-
# IMPORTANT: ifdown eth0 fails silently without taking the
61-
# interface down if the NET_ADMIN capability isn't set for the
62-
# container. ifconfig eth0 down accomplishes the same thing, but
63-
# results in a failure if it fails.
64-
self.centos_container.master, 'ifconfig eth0 down')
65-
self.pa_installer.install(
66-
dist_dir=self.centos_container.get_dist_dir(unique=True))
67-
self.run_prestoadmin('--help', raise_error=True)
68-
6951
def __create_and_start_single_centos_container(self):
7052
cluster_type = 'installer_tester'
7153
bare_image_provider = NoHadoopBareImageProvider()

0 commit comments

Comments
 (0)