From 6c04a9344bb258044430c707bde347d4718ea397 Mon Sep 17 00:00:00 2001 From: Eric Diven Date: Mon, 26 Sep 2016 14:56:15 -0400 Subject: [PATCH] Move base images tag info into its own file This makes it possible to run tests through pycharm or nosetests without fiddling with environment variables. --- .travis.yml | 1 - Makefile | 28 +++++++++++++++------------- base-images-tag.json | 3 +++ tests/product/constants.py | 13 +++++++++++-- 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 base-images-tag.json diff --git a/.travis.yml b/.travis.yml index 78a43a28..67539f4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ services: - docker env: global: - - BASE_IMAGES_TAG=6 - PA_TEST_ONLINE_INSTALLER=true - PYTHONPATH=$PYTHONPATH:$(pwd) - LONG_PRODUCT_TESTS="tests/product/test_server_install.py tests/product/test_status.py tests/product/test_collect.py tests/product/test_connectors.py tests/product/test_control.py tests/product/test_server_uninstall.py" diff --git a/Makefile b/Makefile index 61debb2c..0c012496 100644 --- a/Makefile +++ b/Makefile @@ -111,22 +111,24 @@ _test-all: IMAGE_NAMES?="all" # -# The canonical source of the BASE_IMAGES_TAG is .travis.yml because we don't -# have a good way to get that information into travis from somewhere else. +# The build process and product tests rely on several base Docker images. +# Teradata builds and releases a number of Docker images from the same +# repository, all versioned together. This makes it simple to verify that your +# test environment is sane: if all of the images are the same version, they +# should work together. # -# Note that this is conditionally assigned. If you export -# BASE_IMAGES_TAG="something else" before invoking e.g. `make smoke', you'll -# get that value, not the one here. This makes it possible to test new docker -# images without modifying the Makefile +# As part of the process of releasing those images, we tag all of the images +# with the version number of the release. This means that anything that uses +# the images can reference them as `teradatalabs/image_name:version'. The +# Makefile needs to know that to pull the images, and the python code needs to +# know that for various reasons. # -# To confirm the value of BASE_IMAGES_TAG that make is using, run `make bit' +# base-images-tag.json is the canonical source of the tag information for the +# repository. The python code parses it properly with the json module, and the +# Makefile parses it adequately with awk ;-) # -BASE_IMAGES_TAG ?= $(shell awk '/BASE_IMAGES_TAG/ {split($$0, a, "="); print a[2]}' .travis.yml) -export BASE_IMAGES_TAG - -.PHONY: bit -bit: - echo $(BASE_IMAGES_TAG) +BASE_IMAGES_TAG := $(shell awk '/base_images_tag/ \ + {split($$NF, a, "\""); print a[2]}' base-images-tag.json) test-images: docker-images presto-server-rpm.rpm python tests/product/image_builder.py $(IMAGE_NAMES) diff --git a/base-images-tag.json b/base-images-tag.json new file mode 100644 index 00000000..c3b55b74 --- /dev/null +++ b/base-images-tag.json @@ -0,0 +1,3 @@ +{ + "base_images_tag": "6" +} diff --git a/tests/product/constants.py b/tests/product/constants.py index 36d88273..ef01f8b2 100644 --- a/tests/product/constants.py +++ b/tests/product/constants.py @@ -16,16 +16,25 @@ Module defining constants global to the product tests """ +import json import os import sys import prestoadmin from prestoadmin import main_dir +BASE_IMAGES_TAG_CONFIG = 'base-images-tag.json' + +# +# See the Makefile for an in-depth explanation of how we're using the base +# Docker images. +# try: - BASE_IMAGES_TAG = os.environ['BASE_IMAGES_TAG'] + with open(os.path.join(main_dir, BASE_IMAGES_TAG_CONFIG)) as tag_config: + tag_json = json.load(tag_config) + BASE_IMAGES_TAG = tag_json['base_images_tag'] except KeyError: - print "BASE_IMAGES_TAG must be set in the environment" + print "base_images_tag must be set in %s" % (BASE_IMAGES_TAG_CONFIG,) sys.exit(1)