Commit 3ff28203 by Michael Roytman

Refactor check_dockerfile_coverage to use docker_images script

parent 99473025
...@@ -5,35 +5,24 @@ import itertools ...@@ -5,35 +5,24 @@ import itertools
import argparse import argparse
import logging import logging
import sys import sys
import docker_images
TRAVIS_BUILD_DIR = os.environ.get("TRAVIS_BUILD_DIR") TRAVIS_BUILD_DIR = os.environ.get("TRAVIS_BUILD_DIR")
CONFIG_FILE_PATH = pathlib2.Path(TRAVIS_BUILD_DIR, "util", "parsefiles_config.yml") CONFIG_FILE_PATH = pathlib2.Path(TRAVIS_BUILD_DIR, "util", "parsefiles_config.yml")
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
def check_coverage(containers): def check_coverage(images, used_images):
# open config file containing container weights """
config_file_path = pathlib2.Path(CONFIG_FILE_PATH) Checks whether all images are described in parsefiles_config.yml and raises an error otherwise, directing toward documentation to resolving the error.
with (config_file_path.open(mode='r')) as file: Input:
try: images: the set of images scheduled to be built
config = yaml.load(file) used_images: the subset of images with their ranks that are in the parsefiles_config.yml file
except yaml.YAMLError, exc: """
LOGGER.error("error in configuration file: %s" % str(exc))
sys.exit(1)
# get container weights
weights = config.get("weights")
# convert all containers in config file to a list of tuples (<container>, <weight>)
weights_list = [x.items() for x in weights]
weights_list = list(itertools.chain.from_iterable(weights_list))
# performs intersection between weighted containers and input containers
used_containers = [x for x in weights_list if x[0] in containers]
# determine which Dockerfiles are not covered; i.e. the set difference of the Dockerfiles to build minus the Dockerfile # determine which Dockerfiles are not covered; i.e. the set difference of the Dockerfiles to build minus the Dockerfile
# available to be built is non-empty # available to be built is non-empty
uncovered = set(containers) - set([x[0] for x in used_containers]) uncovered = set(images) - set([x[0] for x in used_images])
# exit with error code if uncovered Dockerfiles exist # exit with error code if uncovered Dockerfiles exist
if uncovered: if uncovered:
...@@ -42,11 +31,8 @@ def check_coverage(containers): ...@@ -42,11 +31,8 @@ def check_coverage(containers):
def arg_parse(): def arg_parse():
parser = argparse.ArgumentParser(description = 'Given a list of containers as input and a number of shards, ' parser = argparse.ArgumentParser(description = 'Given a list of images as input checks that each input image is described correctly in parsefiles_config.yml')
'finds an approximation of the optimal distribution of the containers over the shards, provided a set of hard-coded weights ' parser.add_argument('images', help = "the Dockerfiles that need to be built as the result of some commit change and whose coverage is checked")
'in parsefiles_config.yml.')
parser.add_argument('containers', help = "the Dockerfiles that need to be built as the result of some commit change and whose coverage is checked")
return parser.parse_args() return parser.parse_args()
if __name__ == '__main__': if __name__ == '__main__':
...@@ -56,9 +42,13 @@ if __name__ == '__main__': ...@@ -56,9 +42,13 @@ if __name__ == '__main__':
# configure logging # configure logging
logging.basicConfig() logging.basicConfig()
containers = [] # read input
images = []
for i in args.images.split():
images.append(i)
for word in args.containers.split(): # get images that are used and described in configuration file
containers.append(word) used_images = docker_images.get_used_images(images)
check_coverage(containers) check_coverage(images, used_images)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment