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)
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" )
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()
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()
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
def test_check_if_valid(): # Arrange test_api = CobblerAPI() distro = Distro(test_api) distro.name = "testname" # Act distro.check_if_valid() # Assert assert True
def test_clear_from_fields(): # Arrange test_api = CobblerAPI() test_distro = Distro(test_api._collection_mgr) test_distro.name = "Test" # Pre Assert to check this works assert test_distro.name == "Test" # Act utils.clear_from_fields(test_distro, test_distro.get_fields()) # Assert assert test_distro.name == ""
def test_calculate_grub_name(self, input_arch, result_binary_name, expected_exception, api): # Arrange test_builder = buildiso.BuildIso(api) test_distro = Distro(api) test_distro.name = "testdistro" test_distro.arch = input_arch # Act with expected_exception: result = test_builder.calculate_grub_name(test_distro) # Assert assert result == result_binary_name
def test_to_dict(): # Arrange test_api = CobblerAPI() distro = Distro(test_api) distro.name = "testdistro" test_api.add_distro(distro, save=False) profile = Profile(test_api) profile.name = "testprofile" profile.distro = distro.name # Act result = profile.to_dict() # Assert assert len(result) == 44 assert result["distro"] == "testdistro"
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
def test_kopts_overwrite(): # Arrange test_api = CobblerAPI() test_manager = CollectionManager(test_api) test_distro = Distro(test_manager) test_distro.set_breed("suse") test_distro.name = "kopts_test_distro" test_profile = Profile(test_manager) test_profile.distro = test_distro.name test_system = System(test_manager) test_system.name = "kopts_test_system" kopts = {"textmode": False, "text": True} # Act utils.kopts_overwrite(test_system, test_distro, kopts, test_api.settings()) # Assert assert "textmode" in kopts assert "info" in kopts
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