Skip to content

Commit c11c36d

Browse files
committed
Make module for building images standalone
Previously inherited from BaseProductTest and depended on testing functionality to operate properly.
1 parent e9a14fd commit c11c36d

File tree

4 files changed

+207
-106
lines changed

4 files changed

+207
-106
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ env:
2020
- PRODUCT_TEST_GROUP_SA_PA_PRESTO="tests/product/test_control.py"
2121
- PRODUCT_TEST_GROUP_SA_PA_PRESTO="tests/product/test_server_uninstall.py"
2222
- PRODUCT_TEST_GROUP_YS_PA="tests/product/yarn_slider/test_slider_installation.py"
23-
#-QUARANTINED="tests/product/yarn_slider/test_server_install.py tests/product/test_create_images.py"
24-
install:
23+
#-QUARANTINED="tests/product/yarn_slider/test_server_install.py"
24+
install:
2525
- pip install --upgrade pip==6.1.1
2626
- pip install -r requirements.txt
2727
before_script:
2828
- make docker-images
29-
script:
29+
script:
3030
- |
3131
if [ -v PRODUCT_TEST_GROUP_SA_BARE ]; then
3232
export IMAGE_NAMES="--standalone_bare"

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test-all: clean-test docker-images
8989
IMAGE_NAMES?="--all"
9090

9191
test-images: docker-images
92-
python tests/product/test_create_images.py ${IMAGE_NAMES}
92+
python tests/product/image_builder.py ${IMAGE_NAMES}
9393

9494
docker-images:
9595
docker pull teradatalabs/centos6-ssh-oj8

tests/product/image_builder.py

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
from subprocess import check_output
2+
from sys import argv, exit
3+
from tests.configurable_cluster import ConfigurableCluster
4+
from tests.docker_cluster import DockerCluster, DockerClusterException
5+
from tests.no_hadoop_bare_image_provider import NoHadoopBareImageProvider
6+
7+
from tests.product.mode_installers import StandaloneModeInstaller, \
8+
YarnSliderModeInstaller
9+
from tests.product.prestoadmin_installer import PrestoadminInstaller
10+
from tests.product.standalone.presto_installer import StandalonePrestoInstaller
11+
from tests.product.topology_installer import TopologyInstaller
12+
from tests.product.yarn_slider.slider_installer import SliderInstaller
13+
14+
import argparse
15+
16+
17+
class ProductTestImageBuilder:
18+
STANDALONE_BARE_CLUSTER = 'bare'
19+
BARE_CLUSTER = 'bare'
20+
PA_ONLY_CLUSTER = 'pa_only_standalone'
21+
STANDALONE_PRESTO_CLUSTER = 'presto'
22+
23+
PA_ONLY_YS_CLUSTER = 'pa_only_ys'
24+
PA_SLIDER_CLUSTER = 'pa_slider'
25+
26+
_cluster_types = {
27+
BARE_CLUSTER: [],
28+
PA_ONLY_CLUSTER: [PrestoadminInstaller,
29+
StandaloneModeInstaller],
30+
STANDALONE_PRESTO_CLUSTER: [PrestoadminInstaller,
31+
StandaloneModeInstaller,
32+
TopologyInstaller,
33+
StandalonePrestoInstaller],
34+
PA_ONLY_YS_CLUSTER: [PrestoadminInstaller,
35+
YarnSliderModeInstaller],
36+
PA_SLIDER_CLUSTER: [PrestoadminInstaller,
37+
YarnSliderModeInstaller,
38+
SliderInstaller]
39+
}
40+
41+
def __init__(self):
42+
self.maxDiff = None
43+
self.cluster = None
44+
self.default_keywords = {}
45+
46+
def _apply_post_install_hooks(self, installers):
47+
for installer in installers:
48+
self.cluster.postinstall(installer)
49+
50+
def _update_replacement_keywords(self, installers):
51+
for installer in installers:
52+
installer_instance = installer(self)
53+
self.default_keywords.update(installer_instance.get_keywords())
54+
55+
def _run_installers(self, installers):
56+
cluster = self.cluster
57+
for installer in installers:
58+
dependencies = installer.get_dependencies()
59+
60+
for dependency in dependencies:
61+
dependency.assert_installed(self)
62+
63+
installer_instance = installer(self)
64+
installer_instance.install()
65+
66+
self.default_keywords.update(installer_instance.get_keywords())
67+
cluster.postinstall(installer)
68+
69+
def _setup_cluster(self, bare_image_provider, cluster_type):
70+
installers = None
71+
try:
72+
installers = self._cluster_types[cluster_type]
73+
except KeyError:
74+
print '%s is not a valid cluster type. Valid cluster types are %s' % \
75+
(cluster_type, ', '.join(self._cluster_types.keys()))
76+
exit(1)
77+
78+
config_filename = ConfigurableCluster.check_for_cluster_config()
79+
80+
if config_filename:
81+
self.cluster = ConfigurableCluster.start_bare_cluster(
82+
config_filename, self,
83+
StandalonePrestoInstaller.assert_installed)
84+
else:
85+
try:
86+
self.cluster, bare_cluster = DockerCluster.start_cluster(
87+
bare_image_provider, cluster_type)
88+
89+
# If we've found images and started a non-bare cluster, the
90+
# containers have already had the installers applied to them.
91+
# We do need to get the test environment in sync with the
92+
# containers by calling the following two functions.
93+
#
94+
# Once that's done, the cluster and test environment is in the
95+
# same state it would be as if we'd called _run_installers on
96+
# a bare cluster, and we can return.
97+
#
98+
# We do this to save the cost of running the installers on the
99+
# docker containers every time we run a test. In practice,
100+
# that turns out to be a fairly expensive thing to do.
101+
if not bare_cluster:
102+
self._apply_post_install_hooks(installers)
103+
self._update_replacement_keywords(installers)
104+
return
105+
except DockerClusterException as e:
106+
print e.msg
107+
exit(1)
108+
109+
# If we got a bare cluster back, we need to run the installers on it.
110+
# applying the post-install hooks and updating the replacement
111+
# keywords is handled internally in _run_installers.
112+
self._run_installers(installers)
113+
114+
if isinstance(self.cluster, DockerCluster):
115+
self.cluster.commit_images(bare_image_provider, cluster_type)
116+
117+
def _get_expected_image_names(self, cluster_type):
118+
if cluster_type == self.BARE_CLUSTER:
119+
slave_image_name = 'teradatalabs/pa_test/nohadoop_bare_slave'
120+
master_image_name = 'teradatalabs/pa_test/nohadoop_bare_master'
121+
return [slave_image_name, master_image_name]
122+
elif cluster_type == self.PA_ONLY_CLUSTER:
123+
slave_image_name = 'teradatalabs/pa_test/nohadoop_pa_only_standalone_slave'
124+
master_image_name = 'teradatalabs/pa_test/nohadoop_pa_only_standalone_master'
125+
return [slave_image_name, master_image_name]
126+
elif cluster_type == self.STANDALONE_PRESTO_CLUSTER:
127+
slave_image_name = 'teradatalabs/pa_test/nohadoop_presto_slave'
128+
master_image_name = 'teradatalabs/pa_test/nohadoop_presto_master'
129+
return [slave_image_name, master_image_name]
130+
elif cluster_type == self.PA_ONLY_YS_CLUSTER:
131+
slave_image_name = 'teradatalabs/pa_test/nohadoop_pa_only_ys_slave'
132+
master_image_name = 'teradatalabs/pa_test/nohadoop_pa_only_ys_master'
133+
return [slave_image_name, master_image_name]
134+
else:
135+
return []
136+
137+
def _assert_expected_images_created(self, cluster_type):
138+
docker_images = check_output(['docker', 'images'])
139+
expected_images = self._get_expected_image_names(cluster_type)
140+
for expected_image in expected_images:
141+
assert expected_image in docker_images
142+
143+
def _setup_cluster_with_no_hadoop_provider_assert_images(self, cluster_type):
144+
self._setup_cluster(NoHadoopBareImageProvider(),
145+
cluster_type)
146+
self._assert_expected_images_created(cluster_type)
147+
148+
def test_setup_standalone_presto_images(self):
149+
cluster_type = self.STANDALONE_PRESTO_CLUSTER
150+
self._setup_cluster_with_no_hadoop_provider_assert_images(cluster_type)
151+
152+
def test_setup_standalone_pa_only_images(self):
153+
cluster_type = self.PA_ONLY_CLUSTER
154+
self._setup_cluster_with_no_hadoop_provider_assert_images(cluster_type)
155+
156+
def test_setup_standalone_bare_images(self):
157+
cluster_type = self.BARE_CLUSTER
158+
self._setup_cluster_with_no_hadoop_provider_assert_images(cluster_type)
159+
160+
def test_setup_yarn_slider_pa_only_images(self):
161+
cluster_type = self.PA_ONLY_YS_CLUSTER
162+
self._setup_cluster_with_no_hadoop_provider_assert_images(cluster_type)
163+
164+
if __name__ == "__main__":
165+
parser = argparse.ArgumentParser()
166+
parser.add_argument("--standalone_presto",
167+
help="Create standalone presto images",
168+
action="store_true")
169+
parser.add_argument("--standalone_pa",
170+
help="Create standalone presto-admin only images",
171+
action="store_true")
172+
parser.add_argument("--standalone_bare",
173+
help="Create standalone bare images",
174+
action="store_true")
175+
parser.add_argument("--yarn_slider_pa",
176+
help="Create yarn-slider presto-admin only images",
177+
action="store_true")
178+
parser.add_argument("--all",
179+
help="Create standalone presto, standalone presto-admin only,"
180+
"standalone bare, and yarn-slider presto-admin only images",
181+
action="store_true")
182+
183+
if len(argv) <= 1:
184+
parser.print_help()
185+
exit(1)
186+
187+
image_builder = ProductTestImageBuilder()
188+
189+
args = parser.parse_args()
190+
if args.all:
191+
image_builder.test_setup_standalone_pa_only_images()
192+
image_builder.test_setup_standalone_pa_only_images()
193+
image_builder.test_setup_standalone_bare_images()
194+
image_builder.test_setup_yarn_slider_pa_only_images()
195+
else:
196+
if args.standalone_presto:
197+
image_builder.test_setup_standalone_presto_images()
198+
if args.standalone_pa:
199+
image_builder.test_setup_standalone_pa_only_images()
200+
if args.standalone_bare:
201+
image_builder.test_setup_standalone_bare_images()
202+
if args.yarn_slider_pa:
203+
image_builder.test_setup_yarn_slider_pa_only_images()

tests/product/test_create_images.py

-102
This file was deleted.

0 commit comments

Comments
 (0)