Пример #1
0
 def test_save_grub_conf_should_work(self):
     # given
     conf = build_kernel.load_conf(TEST_CONF)
     conf["grub_conf_path"] = os.path.join(self.temp_dir, "new-grub.conf")
     grub_conf = build_kernel.load_grub_conf("test/boot/grub.conf")
     self.assertEqual(len(grub_conf["boot"]), 5)
     build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("gentoo-test-v1"), conf)
     build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("test-v1"), conf)
     build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("gentoo-test-v1"), conf)
     self.assertEqual(len(grub_conf["boot"]), 7)
     # when
     build_kernel.save_grub_conf(grub_conf, conf)
     # then
     new_grub_conf = build_kernel.load_grub_conf(os.path.join(self.temp_dir, "new-grub.conf"))
     self.assertEqual(len(new_grub_conf["boot"]), 7)
Пример #2
0
 def test_add_to_grub_conf_and_remove_if_needed_should_work(self):
     # TODO split this test
     # given
     grub_conf = build_kernel.load_grub_conf("test/boot/grub.conf")
     conf = build_kernel.load_conf(TEST_CONF)
     self.assertEqual(len(grub_conf["boot"]), 5)
     # when add one
     removed_kernels = build_kernel.add_to_grub_conf_and_remove_if_needed(
         grub_conf, get_unique_version("gentoo-test-v1"), conf
     )
     # then should +1
     self.assertEqual(len(grub_conf["boot"]), 6)
     self.assertEqual(len(removed_kernels), 0)
     # when add one more
     removed_kernels = build_kernel.add_to_grub_conf_and_remove_if_needed(
         grub_conf, get_unique_version("test-v1"), conf
     )
     # then should +1
     self.assertEqual(len(grub_conf["boot"]), 7)
     self.assertEqual(len(removed_kernels), 0)
     # when add one more
     removed_kernels = build_kernel.add_to_grub_conf_and_remove_if_needed(
         grub_conf, get_unique_version("gentoo-test-v1"), conf
     )
     # then len is not changed
     self.assertEqual(len(grub_conf["boot"]), 7)
     #  because one is removed
     self.assertEqual(len(removed_kernels), 1)
Пример #3
0
 def test_load_grub_conf_should_return_5_kernels(self):
     # given & when
     grub_conf = build_kernel.load_grub_conf("test/boot/grub.conf")
     # then
     self.assertTrue(grub_conf is not None)
     self.assertTrue("boot" in grub_conf)
     self.assertEqual(len(grub_conf["boot"]), 5)
Пример #4
0
 def test_remove_old_kernels_should_work(self):
     # given
     grub_conf = build_kernel.load_grub_conf("test/boot/grub.conf")
     conf = build_kernel.load_conf(TEST_CONF)
     conf["boot_path"] = os.path.join(self.temp_dir, "boot")
     removed_kernels = (
         build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("gentoo-test-v1"), conf)
         + build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("test-v1"), conf)
         + build_kernel.add_to_grub_conf_and_remove_if_needed(grub_conf, get_unique_version("gentoo-test-v1"), conf)
     )
     prepared_removed_kernels = build_kernel.prepare_remove_kernels(removed_kernels, conf)
     print prepared_removed_kernels
     for kernel in prepared_removed_kernels:
         image = kernel[0]
         system_map = kernel[1]
         self.assertTrue(os.path.exists(image))
         self.assertTrue(os.path.exists(system_map))
     build_kernel.remove_old_kernels(prepared_removed_kernels, conf)
     for kernel in prepared_removed_kernels:
         image = kernel[0]
         system_map = kernel[1]
         self.assertFalse(os.path.exists(image))
         self.assertFalse(os.path.exists(system_map))
Пример #5
0
 def test_is_in_grub_conf_should_work(self):
     # given
     grub_conf = build_kernel.load_grub_conf("test/boot/grub.conf")
     # when & then
     self.assertTrue(build_kernel.is_in_grub_conf(grub_conf, "linux-2.6.32-gentoo-r7"))
     self.assertFalse(build_kernel.is_in_grub_conf(grub_conf, "linux-2.6.1"))