示例#1
0
def test_merging_description_modules():
    desc1 = Module({'name': 'foo'}, None, None)

    desc2 = Module({'name': 'mod1',
                    'description': 'mod_desc'}, None, None)

    merged = _merge_descriptors(desc1, desc2)
    assert 'description' not in merged
示例#2
0
def test_module_processing_modules_with_multiple_versions(caplog):
    caplog.set_level(logging.DEBUG, logger="cekit")

    image = Image(
        yaml.safe_load("""
        from: foo
        name: test/foo
        version: 1.9
        """), 'foo')

    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_b = Module(
        yaml.safe_load("""
        name: org.test.module.b
        version: 1.0
        """), 'path', 'artifact_path')

    module_b_1 = Module(
        yaml.safe_load("""
        name: org.test.module.b
        version: 1.1
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)
    module_registry.add_module(module_b)
    module_registry.add_module(module_b_1)

    resulting_install_list = OrderedDict()

    to_install_list = [
        Map({
            'name': 'org.test.module.a',
            'version': '1.0'
        }),
        Map({'name': 'org.test.module.b'})
    ]

    image.process_install_list(image, to_install_list, resulting_install_list,
                               module_registry)

    assert resulting_install_list == OrderedDict([('org.test.module.a', {
        'name': 'org.test.module.a',
        'version': '1.0'
    }), ('org.test.module.b', {
        'name': 'org.test.module.b'
    })])

    assert "Module version not specified for 'org.test.module.b' module, using '1.1' default version" in caplog.text
示例#3
0
def check_module_version(path, version):
    descriptor = Module(
        tools.load_descriptor(os.path.join(path, 'module.yaml')), path,
        os.path.dirname(os.path.abspath(os.path.join(path, 'module.yaml'))))
    if hasattr(descriptor, 'version') and descriptor.version != version:
        raise CekitError("Requested conflicting version '%s' of module '%s'" %
                         (version, descriptor['name']))
示例#4
0
def test_module_processing_fail_when_module_not_found_for_specific_version():
    image = Image(
        yaml.safe_load("""
        from: foo
        name: test/foo
        version: 1.9
        """), 'foo')

    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)

    resulting_install_list = OrderedDict()

    to_install_list = [Map({'name': 'org.test.module.a', 'version': '1.1'})]

    with pytest.raises(CekitError) as excinfo:
        image.process_install_list(image, to_install_list,
                                   resulting_install_list, module_registry)

    assert "Module 'org.test.module.a' with version '1.1' could not be found, available versions: 1.0" in str(
        excinfo.value)
示例#5
0
def test_module_processing_fail_when_no_modules_of_specified_name_can_be_found(
):
    image = Image(
        yaml.safe_load("""
        from: foo
        name: test/foo
        version: 1.9
        """), 'foo')

    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)

    resulting_install_list = OrderedDict()

    to_install_list = [
        Map({
            'name': 'org.test.module.a',
            'version': '1.0'
        }),
        Map({'name': 'org.test.module.b'})
    ]

    with pytest.raises(CekitError) as excinfo:
        image.process_install_list(image, to_install_list,
                                   resulting_install_list, module_registry)

    assert "There are no modules with 'org.test.module.b' name available" in str(
        excinfo.value)
示例#6
0
def test_module_processing_simple_modules_order_to_install():
    image = Image(
        yaml.safe_load("""
        from: foo
        name: test/foo
        version: 1.9
        """), 'foo')

    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_b = Module(
        yaml.safe_load("""
        name: org.test.module.b
        version: 1.0
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)
    module_registry.add_module(module_b)

    resulting_install_list = OrderedDict()

    to_install_list = [
        Map({
            'name': 'org.test.module.a',
            'version': '1.0'
        }),
        Map({'name': 'org.test.module.b'})
    ]

    image.process_install_list(image, to_install_list, resulting_install_list,
                               module_registry)

    assert resulting_install_list == OrderedDict([('org.test.module.a', {
        'name': 'org.test.module.a',
        'version': '1.0'
    }), ('org.test.module.b', {
        'name': 'org.test.module.b'
    })])
示例#7
0
def test_merging_description_image():
    desc1 = Image({'name': 'foo', 'version': 1}, None)

    desc2 = Module({
        'name': 'mod1',
        'version': 2,
        'description': 'mod_desc'
    }, None, None)

    merged = _merge_descriptors(desc1, desc2)
    assert 'description' not in merged
示例#8
0
    def load_repository(self, repo_dir):
        for modules_dir, _, files in os.walk(repo_dir):
            if 'module.yaml' in files:

                module_descriptor_path = os.path.abspath(os.path.expanduser(
                    os.path.normcase(os.path.join(modules_dir, 'module.yaml'))))

                module = Module(tools.load_descriptor(module_descriptor_path),
                                modules_dir,
                                os.path.dirname(module_descriptor_path))
                LOGGER.debug("Adding module '{}', path: '{}'".format(module.name, module.path))
                self._module_registry.add_module(module)
示例#9
0
def test_module_processing_warning_when_a_module_version_cannot_be_parsed_as_pep_440(
        caplog):
    caplog.set_level(logging.DEBUG, logger="cekit")

    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_a1 = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: aa fs df
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)
    module_registry.add_module(module_a1)

    assert "Module's 'org.test.module.a' version 'aa fs df' does not follow PEP 440 versioning scheme (https://www.python.org/dev/peps/pep-0440), we suggest follow this versioning scheme in modules" in caplog.text
示例#10
0
def test_module_processing_fail_when_a_module_aready_exists_in_registry():
    module_a = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_a1 = Module(
        yaml.safe_load("""
        name: org.test.module.a
        version: 1.0
        """), 'path', 'artifact_path')

    module_registry = ModuleRegistry()
    module_registry.add_module(module_a)

    with pytest.raises(CekitError) as excinfo:
        module_registry.add_module(module_a1)

    assert "Module 'org.test.module.a' with version '1.0' already exists in module registry" in str(
        excinfo.value)
示例#11
0
def prepare_generator(target, desc_part, desc_type="image", engine="docker"):
    # create basic descriptor

    desc = basic_config.copy()
    desc.update(desc_part)

    image = Module(desc, '/tmp/', '/tmp')

    generator = Generator.__new__(Generator, image, target, engine, None, {})
    generator.image = image
    generator.target = target
    generator._type = 'docker'
    generator._wipe = False
    generator._params = {}
    generator._fetch_repos = False
    return generator
示例#12
0
def discover_modules(repo_dir):
    """Looks through the directory trees for modules descriptor.
    When module is found, it create cekit.module.Module instance
    and add this instance to the cekit.module.modules list.
    """
    for modules_dir, _, files in os.walk(repo_dir):
        if 'module.yaml' in files:
            module = Module(
                tools.load_descriptor(os.path.join(modules_dir,
                                                   'module.yaml')),
                modules_dir,
                os.path.dirname(
                    os.path.abspath(os.path.join(modules_dir, 'module.yaml'))))
            module.fetch_dependencies(repo_dir)
            logger.debug("Adding module '%s', path: '%s'" %
                         (module.name, module.path))
            modules.append(module)
示例#13
0
def test_issue_322(tmpdir):
    """tests a particular inheritance issue reported as GitHub issue #322"""
    target_dir = str(tmpdir.mkdir('target'))
    artifact_dir = str(tmpdir.mkdir('artifacts'))
    clone_dir = str(tmpdir.mkdir('clone'))

    descriptor = yaml.load(open("tests/issue_322/image.yaml").read())
    image = Module(descriptor=descriptor,
                   path="tests/issue_322",
                   artifact_dir=artifact_dir)
    image.fetch_dependencies(clone_dir)

    generator = Generator.__new__(Generator,
                                  descriptor_path="tests/issue_322",
                                  target=target_dir,
                                  builder="docker",
                                  overrides=None,
                                  params={})
    generator.image = image
    generator.target = target_dir
    generator.prepare_modules()
示例#14
0
def test_modules_repos(tmpdir):
    tmpdir = str(tmpdir.mkdir('target'))
    module = Module(module_desc, os.getcwd(), '/tmp')
    module.fetch_dependencies(tmpdir)
    assert 'foo' in [m['name'] for m in modules]