def test_multiplay(caplog):
    set_logging()
    p = PbVarsParser(multiplay_path)
    b, m = p.get_build_and_metadata()

    assert b.target_image != "nope"
    assert "Variables are loaded only from the first play." == caplog.records[0].msg
    assert "no bender data found in the playbook" == caplog.records[1].msg
Exemple #2
0
 def set_logging(debug=False, verbose=False):
     """ configure logging """
     if debug:
         set_logging(level=logging.DEBUG)
     elif verbose:
         set_logging(level=logging.INFO)
         set_logging(logger_name=OUT_LOGGER, level=logging.INFO, format=OUT_LOGGER_FORMAT,
                     handler_kwargs={"stream": sys.stdout})
     else:
         set_logging(level=logging.WARNING)
         set_logging(logger_name=OUT_LOGGER, level=logging.INFO, format=OUT_LOGGER_FORMAT,
                     handler_kwargs={"stream": sys.stdout})
Exemple #3
0
def test_buildah_sanity_check_extra_args(caplog):
    set_logging(level=logging.DEBUG)
    build = Build()
    build.base_image = base_image
    build.buildah_from_extra_args = "--help"
    b = BuildahBuilder(build, debug=True)
    b.ansible_host = "cacao"
    with pytest.raises(CalledProcessError):
        b.sanity_check()
    for r in caplog.records:
        if "-h, --help" in r.message:
            break
    else:
        assert 1/0, "it seems that buildah_from_extra_args were not passed to sanity check"
Exemple #4
0
import logging
import os
import random
import string
import subprocess

import pytest

from ansible_bender.builders.buildah_builder import buildah
from ansible_bender.utils import set_logging

set_logging(level=logging.DEBUG)

tests_dir = os.path.dirname(os.path.abspath(__file__))
project_dir = os.path.dirname(tests_dir)
data_dir = os.path.abspath(os.path.join(tests_dir, "data"))
roles_dir = os.path.join(data_dir, "roles")
buildah_inspect_data_path = os.path.join(data_dir, "buildah_inspect.json")
basic_playbook_path = os.path.join(data_dir, "basic_playbook.yaml")
multiplay_path = os.path.join(data_dir, "multiplay.yaml")
non_ex_pb = os.path.join(data_dir, "non_ex_pb.yaml")
b_p_w_vars_path = os.path.join(data_dir, "b_p_w_vars.yaml")
p_w_vars_files_path = os.path.join(data_dir, "p_w_vars_files.yaml")
full_conf_pb_path = os.path.join(data_dir, "full_conf_pb.yaml")
basic_playbook_path_w_bv = os.path.join(data_dir,
                                        "basic_playbook_with_volume.yaml")
dont_cache_playbook_path_pre = os.path.join(data_dir,
                                            "dont_cache_playbook_pre.yaml")
dont_cache_playbook_path = os.path.join(data_dir, "dont_cache_playbook.yaml")
small_basic_playbook_path = os.path.join(data_dir, "small_basic_playbook.yaml")
change_layering_playbook = os.path.join(data_dir, "change_layering.yaml")
Exemple #5
0
TODO:
* introduce a new fixture which verifies that a container runtime is working properly: if not, skip tests which require the functional container runtime
"""
import logging
import subprocess

import pytest

from ansible_bender.api import Application
from ansible_bender.builders.base import BuildState
from ansible_bender.builders.buildah_builder import buildah
from ansible_bender.conf import ImageMetadata, Build
from ansible_bender.utils import set_logging
from .spellbook import random_word, basic_playbook_path, base_image, project_dir

logger = set_logging(level=logging.DEBUG)


@pytest.fixture()
def target_image():
    im = "registry.example.com/ab-test-" + random_word(12) + ":oldest"
    yield im
    try:
        buildah("rmi", [
            im
        ])  # FIXME: use builder interface instead for sake of other backends
        # FIXME: also remove everything from cache
    except subprocess.CalledProcessError as ex:
        print(ex)