def build_adapters(systest, tag, branch, local, force_rebuild): """ Builds a docker images for a preCICE adapter, participating in tests """ baseimage_name = "precice-{tag}-{branch}:latest".format(tag=tag, branch=branch) participants = get_test_participants(systest) docker_args = { 'tag': '', 'build_args': { "from": docker.get_namespace() + baseimage_name if local else 'precice/' + baseimage_name }, 'force_rebuild': force_rebuild, 'dockerfile': 'Dockerfile' } with common.chdir(os.path.join(os.getcwd(), 'adapters')): for participant in participants: docker_args['tag'] = '-'.join([participant, tag, branch]) docker_args['dockerfile'] = "Dockerfile." + participant # skip "light-adapters" (e.g. nutils ) if os.path.exists("Dockerfile.{}".format(participant)): try: docker.build_image(**docker_args) except CalledProcessError as e: print("BUILD FAILED WITH: {}".format(e)) raise STBuildException()
def run(systest, tag, branch): """ Runs (create a container from an image) the specified systest. """ test_tag = docker.get_namespace() + systest + "-" + tag + "-" + branch # remove any currently running containers with same name ccall("docker container stop {}; docker container rm {}".format( test_tag, test_tag)) ccall("docker run -it -d --name " + test_tag + " " + test_tag) shutil.rmtree("Output", ignore_errors=True) ccall("docker cp " + test_tag + ":Output . ")
def run(systest, tag, branch): """ Runs (create a container from an image) the specified systest. """ test_tag = docker.get_namespace() + systest + "-" + tag + "-" + branch try: ccall("docker run -it -d --name " + test_tag + " " + test_tag) shutil.rmtree("Output", ignore_errors=True) shutil.rmtree("Logs", ignore_errors=True) ccall("docker cp " + test_tag + ":Output . ") except CalledProcessError as e: print("TEST FAILED WITH: {}".format(e)) raise STRunException()
def run_compose(systest, branch, local, tag, force_rebuild, rm_all): """ Runs necessary systemtest with docker compose """ test_dirname = "TestCompose_{systest}".format(systest=systest) test_basename = systest.split('.')[0] adapter_base_name = "-".join([tag, branch]) # set up environment variables, to detect precice base image, that we # should run with and docker images location commands_main = ["""export PRECICE_BASE=-{base}; {extra_cmd} docker-compose config && bash ../../silent_compose.sh""".format(base = adapter_base_name, extra_cmd =\ "export SYSTEST_REMOTE={remote};".format( remote = docker.get_namespace()) if local else "" ), "docker cp tutorial-data:/Output ."] # rebuild tutorials image if needed if force_rebuild: commands_main.insert(0, "docker-compose build --no-cache") commands_cleanup = ["docker-compose down -v"] test_path = os.path.join(os.getcwd(), 'tests', test_dirname) with common.chdir(test_path): # cleanup previous results shutil.rmtree("Output", ignore_errors=True) try: for command in commands_main: ccall(command) #compare results path_to_ref = os.path.join(os.getcwd(), "referenceOutput") path_to_otp = os.path.join(os.getcwd(), "Output") comparison(path_to_ref, path_to_otp) if rm_all: for command in commands_cleanup: ccall(command) except (CalledProcessError, IncorrectOutput) as e: # cleanup in either case if rm_all: for command in commands_cleanup: ccall(command) # generate a report of failurs for local tests if local: raise e print("TESTS FAILED WITH: {}".format(e)) sys.exit(1)
def build(systest, tag, branch, local, force_rebuild): """ Builds a docker image for systest. """ baseimage_name = "precice-" + tag + "-" + branch + ":latest" test_tag = systest + "-" + tag + "-" + branch if local: docker.build_image( tag=test_tag, build_args={"from": docker.get_namespace() + baseimage_name}, force_rebuild=force_rebuild) else: docker.build_image( tag=test_tag, build_args={"from": 'precicecoupling/' + baseimage_name}, force_rebuild=force_rebuild)
def build(systest, tag, branch, local, force_rebuild): """ Builds a docker image for systest. """ baseimage_name = "precice-{tag}-{branch}:latest".format(tag=tag, branch=branch) test_tag = "-".join([systest, tag, branch]) docker.build_image( tag=test_tag, build_args={ "from": docker.get_namespace() + baseimage_name if local else 'precice/' + baseimage_name }, force_rebuild=force_rebuild)
def build(systest, tag, branch, local, force_rebuild): """ Builds a docker image for systest. """ baseimage_name = "precice-{tag}-{branch}:latest".format(tag=tag, branch=branch) test_tag = "-".join([systest, tag, branch]) try: docker.build_image( tag=test_tag, build_args={ "from": docker.get_namespace() + baseimage_name if local else 'precice/' + baseimage_name }, force_rebuild=force_rebuild) except CalledProcessError as e: print("BUILD FAILED WITH: {}".format(e)) raise STBuildException()
def build(systest, tag, branch, local, force_rebuild): """ Builds a docker image for systest. """ baseimage_name = "precice-" + tag + "-" + branch + ":latest" test_tag = systest + "-" + tag + "-" + branch if local: docker.build_image( tag=test_tag, build_args={"from": docker.get_namespace() + baseimage_name}, force_rebuild=force_rebuild) else: match = re.search(r'ubuntu(\d+)', baseimage_name) if match: ubuntu_version = match.group(1) else: raise Exception("Could not detect preCICE image to import from") docker.build_image(tag=test_tag, build_args={ "from": 'precicecoupling/precice_ubuntu' + ubuntu_version + ':latest' }, force_rebuild=force_rebuild)
def run_compose(systest, branch, local, tag, force_rebuild, rm_all=False, verbose=False): """ Runs necessary systemtest with docker compose """ test_dirname = "TestCompose_{systest}".format(systest=systest) test_basename = systest.split('.')[0] adapter_base_name = "-".join([tag, branch]) # set up environment variables, to detect precice base image, that we # should run with and docker images location export_cmd = "export PRECICE_BASE=-{}; ".format(adapter_base_name) extra_cmd = "export SYSTEST_REMOTE={}; ".format( docker.get_namespace()) if local else "" compose_config_cmd = "mkdir Logs; docker-compose config && " compose_exec_cmd = "bash ../../silent_compose.sh {}".format( 'debug' if verbose else "") copy_cmd = "docker cp tutorial-data:/Output ." log_cmd = "docker-compose logs > Logs/container.log" commands_main = [ export_cmd + extra_cmd + compose_config_cmd + compose_exec_cmd, copy_cmd, log_cmd ] # rebuild tutorials image if needed if force_rebuild: commands_main.insert(0, "docker-compose build --no-cache") commands_cleanup = ["docker-compose down -v"] test_path = os.path.join(os.getcwd(), 'tests', test_dirname) with common.chdir(test_path): # cleanup previous results shutil.rmtree("Output", ignore_errors=True) shutil.rmtree("Logs", ignore_errors=True) try: for command in commands_main: ccall(command) #compare results path_to_ref = os.path.join(os.getcwd(), "referenceOutput") path_to_otp = os.path.join(os.getcwd(), "Output") comparison(path_to_ref, path_to_otp) if rm_all: for command in commands_cleanup: ccall(command) except CalledProcessError as e: print("TEST FAILED WITH: {}".format(e)) raise STRunException() except IncorrectOutput as e: print("TEST FAILED WITH: {}".format(e)) raise STValidateException() finally: # cleanup in either case if rm_all: for command in commands_cleanup: ccall(command)
def run(systest, tag, branch): """ Runs (create a container from an image) the specified systest. """ test_tag = docker.get_namespace() + systest + "-" + tag + "-" + branch ccall("docker run -it -d --name " + test_tag + " " + test_tag) shutil.rmtree("Output", ignore_errors=True) ccall("docker cp " + test_tag + ":Output . ")