示例#1
0
    def test_generate_profile(self, api, create_kernel_initrd, fk_kernel,
                              fk_initrd, cleanup_items):
        # Arrange
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        test_distro = Distro(api)
        test_distro.name = "testdistro"
        test_distro.kernel = kernel_path
        test_distro.initrd = initrd_path
        api.add_distro(test_distro)
        test_profile = Profile(api)
        test_profile.name = "testprofile"
        test_profile.distro = test_distro.name
        api.add_profile(test_profile)
        blendered_data = utils.blender(api, False, test_profile)
        test_builder = AppendLineBuilder(test_distro.name, blendered_data)

        # Act
        result = test_builder.generate_profile("suse")

        # Assert
        # Very basic test yes but this is the expected result atm
        # TODO: Make tests more sophisticated
        assert (
            result ==
            " append initrd=testdistro.img install=http://127.0.0.1:80/cblr/links/testdistro autoyast=default.ks"
        )
示例#2
0
def test_copy_single_distro_files(create_kernel_initrd, fk_initrd, fk_kernel):
    # Arrange
    # Create fake files
    directory = create_kernel_initrd(fk_kernel, fk_initrd)
    # Create test API
    test_api = CobblerAPI()
    # Get Collection Manager used by the API
    test_collection_mgr = test_api._collection_mgr
    # Create a test Distro
    test_distro = Distro(test_api)
    test_distro.name = "test_copy_single_distro_files"
    test_distro.kernel = str(os.path.join(directory, fk_kernel))
    test_distro.initrd = str(os.path.join(directory, fk_initrd))
    # Add test distro to the API
    test_api.add_distro(test_distro)
    # Create class under test
    test_gen = tftpgen.TFTPGen(test_collection_mgr)

    # Act
    test_gen.copy_single_distro_files(test_distro, directory, False)

    # Assert that path created by function under test is actually there
    result_kernel = os.path.join(directory, "images", test_distro.name,
                                 fk_kernel)
    result_initrd = os.path.join(directory, "images", test_distro.name,
                                 fk_initrd)
    assert os.path.exists(result_kernel)
    assert os.path.exists(result_initrd)
示例#3
0
    def test_standalone_run(
        self,
        api,
        create_kernel_initrd,
        fk_kernel,
        fk_initrd,
        create_loaders,
        tmpdir_factory,
        cleanup_items,
    ):
        # Arrange
        iso_directory = tmpdir_factory.mktemp("isodir")
        iso_source = tmpdir_factory.mktemp("isosource")
        iso_location = iso_directory.join("autoinst.iso")
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        test_distro = Distro(api)
        test_distro.name = "testdistro"
        test_distro.kernel = kernel_path
        test_distro.initrd = initrd_path
        api.add_distro(test_distro)
        build_iso = StandaloneBuildiso(api)

        # Act
        build_iso.run(iso=str(iso_location),
                      distro_name=test_distro.name,
                      source=str(iso_source))

        # Assert
        assert iso_location.exists()
示例#4
0
    def test_netboot_run(
        self,
        api,
        create_kernel_initrd,
        fk_kernel,
        fk_initrd,
        cleanup_items,
        create_loaders,
        tmpdir,
    ):
        # Arrange
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        test_distro = Distro(api)
        test_distro.name = "testdistro"
        test_distro.kernel = kernel_path
        test_distro.initrd = initrd_path
        api.add_distro(test_distro)
        build_iso = NetbootBuildiso(api)
        iso_location = tmpdir.join("autoinst.iso")

        # Act
        build_iso.run(iso=str(iso_location), distro_name=test_distro.name)

        # Assert
        assert iso_location.exists()
示例#5
0
    def test_filter_system(self, api, create_kernel_initrd, fk_kernel,
                           fk_initrd):
        # Arrange
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        test_distro = Distro(api)
        test_distro.name = "testdistro"
        test_distro.kernel = kernel_path
        test_distro.initrd = initrd_path
        api.add_distro(test_distro)
        test_profile = Profile(api)
        test_profile.name = "testprofile"
        test_profile.distro = test_distro.name
        api.add_profile(test_profile)
        test_system = System(api)
        test_system.name = "testsystem"
        test_system.profile = test_profile.name
        api.add_system(test_system)
        itemlist = [test_system.name]
        build_iso = NetbootBuildiso(api)
        expected_result = [test_system]

        # Act
        result = build_iso.filter_systems(itemlist)

        # Assert
        assert expected_result == result
示例#6
0
def test_kernel(value, expected_exception):
    # TODO: Create fake kernel so we can set it successfully
    # Arrange
    test_api = CobblerAPI()
    distro = Distro(test_api)

    # Act
    with expected_exception:
        distro.kernel = value

        # Assert
        assert distro.kernel == value
示例#7
0
def test_find_distro_path():
    # Arrange
    test_api = CobblerAPI()
    test_manager = CollectionManager(test_api)
    test_distro = Distro(test_manager)
    test_distro.kernel = "/dev/shm/fakekernelfile"

    # Act
    result = utils.find_distro_path(test_manager.settings(), test_distro)

    # Assert
    assert result == "/dev/shm"
示例#8
0
def test_find_distro_path(create_testfile, tmp_path):
    # Arrange
    test_api = CobblerAPI()
    fk_kernel = "vmlinuz1"
    create_testfile(fk_kernel)
    test_distro = Distro(test_api)
    test_distro.kernel = os.path.join(tmp_path, fk_kernel)

    # Act
    result = utils.find_distro_path(Settings(), test_distro)

    # Assert
    assert result == tmp_path.as_posix()
示例#9
0
def test_make_clone(create_kernel_initrd, fk_kernel, fk_initrd):
    # Arrange
    test_api = CobblerAPI()
    folder = create_kernel_initrd(fk_kernel, fk_initrd)
    utils.load_signatures("/var/lib/cobbler/distro_signatures.json")
    distro = Distro(test_api)
    distro.breed = "suse"
    distro.os_version = "sles15generic"
    distro.kernel = os.path.join(folder, "vmlinuz1")
    distro.initrd = os.path.join(folder, "initrd1.img")

    # Act
    result = distro.make_clone()

    # Assert
    # TODO: When in distro.py the FIXME of this method is done then adjust this here
    assert result != distro
示例#10
0
    def test_copy_boot_files(self, api, create_kernel_initrd, fk_kernel,
                             fk_initrd, tmpdir):
        # Arrange
        target_folder = tmpdir.mkdir("target")
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        build_iso = buildiso.BuildIso(api)
        testdistro = Distro(api)
        testdistro.name = "testdistro"
        testdistro.kernel = kernel_path
        testdistro.initrd = initrd_path

        # Act
        build_iso.copy_boot_files(testdistro, target_folder)

        # Assert
        assert len(os.listdir(target_folder)) == 2
示例#11
0
    def test_filter_profile(self, api, create_kernel_initrd, fk_kernel,
                            fk_initrd, cleanup_items):
        # Arrange
        folder = create_kernel_initrd(fk_kernel, fk_initrd)
        kernel_path = os.path.join(folder, fk_kernel)
        initrd_path = os.path.join(folder, fk_initrd)
        test_distro = Distro(api)
        test_distro.name = "testdistro"
        test_distro.kernel = kernel_path
        test_distro.initrd = initrd_path
        api.add_distro(test_distro)
        test_profile = Profile(api)
        test_profile.name = "testprofile"
        test_profile.distro = test_distro.name
        api.add_profile(test_profile)
        itemlist = [test_profile.name]
        build_iso = buildiso.BuildIso(api)
        expected_result = [test_profile]

        # Act
        result = build_iso.filter_profiles(itemlist)

        # Assert
        assert expected_result == result