예제 #1
0
파일: test_pxe.py 프로젝트: sydneypdx/maas
    def test_link_bootloader_copies_previously_downloaded_files(self):
        method = PXEBootMethod()
        with tempdir() as tmp:
            new_dir = os.path.join(tmp, "new")
            current_dir = os.path.join(tmp, "current")
            os.makedirs(new_dir)
            os.makedirs(current_dir)
            factory.make_file(current_dir, method.bootloader_files[0])
            for bootloader_file in method.bootloader_files[1:]:
                factory.make_file(current_dir, bootloader_file)
            real_syslinux_dir = os.path.join(tmp, "syslinux")
            os.makedirs(real_syslinux_dir)
            atomic_symlink(
                real_syslinux_dir, os.path.join(current_dir, "syslinux")
            )

            method.link_bootloader(new_dir)

            for bootloader_file in method.bootloader_files:
                bootloader_file_path = os.path.join(new_dir, bootloader_file)
                self.assertTrue(os.path.isfile(bootloader_file_path))
            syslinux_link = os.path.join(new_dir, "syslinux")
            self.assertTrue(os.path.islink(syslinux_link))
            self.assertEqual(
                real_syslinux_dir, os.path.realpath(syslinux_link)
            )
예제 #2
0
    def test_link_bootloader_links_files_found_on_fs(self):
        method = PXEBootMethod()
        bootloader_dir = ('/var/lib/maas/boot-resources/snapshot-%s' %
                          factory.make_name('snapshot'))

        def fake_exists(path):
            if '/usr/lib/syslinux/modules/bios' in path:
                return True
            else:
                return False

        self.patch(pxe_module.os.path, 'exists').side_effect = fake_exists
        mock_atomic_copy = self.patch(pxe_module, 'atomic_copy')
        mock_atomic_symlink = self.patch(pxe_module, 'atomic_symlink')
        mock_shutil_copy = self.patch(pxe_module.shutil, 'copy')

        method.link_bootloader(bootloader_dir)

        self.assertThat(mock_atomic_copy, MockNotCalled())
        self.assertThat(mock_shutil_copy, MockNotCalled())
        for bootloader_file in method.bootloader_files:
            bootloader_src = os.path.join('/usr/lib/syslinux/modules/bios',
                                          bootloader_file)
            bootloader_dst = os.path.join(bootloader_dir, bootloader_file)
            self.assertThat(mock_atomic_symlink,
                            MockAnyCall(bootloader_src, bootloader_dst))
        self.assertThat(
            mock_atomic_symlink,
            MockAnyCall('/usr/lib/syslinux/modules/bios',
                        os.path.join(bootloader_dir, 'syslinux')))
예제 #3
0
    def test_link_bootloader_links_files_found_on_fs(self):
        method = PXEBootMethod()
        bootloader_dir = ("/var/lib/maas/boot-resources/snapshot-%s" %
                          factory.make_name("snapshot"))

        def fake_exists(path):
            if "/usr/lib/syslinux/modules/bios" in path:
                return True
            else:
                return False

        self.patch(pxe_module.os.path, "exists").side_effect = fake_exists
        mock_atomic_copy = self.patch(pxe_module, "atomic_copy")
        mock_atomic_symlink = self.patch(pxe_module, "atomic_symlink")
        mock_shutil_copy = self.patch(pxe_module.shutil, "copy")

        method.link_bootloader(bootloader_dir)

        self.assertThat(mock_atomic_copy, MockNotCalled())
        self.assertThat(mock_shutil_copy, MockNotCalled())
        for bootloader_file in method.bootloader_files:
            bootloader_src = os.path.join("/usr/lib/syslinux/modules/bios",
                                          bootloader_file)
            bootloader_dst = os.path.join(bootloader_dir, bootloader_file)
            self.assertThat(
                mock_atomic_symlink,
                MockAnyCall(bootloader_src, bootloader_dst),
            )
        self.assertThat(
            mock_atomic_symlink,
            MockAnyCall(
                "/usr/lib/syslinux/modules/bios",
                os.path.join(bootloader_dir, "syslinux"),
            ),
        )
예제 #4
0
파일: test_pxe.py 프로젝트: uraniid/maas
 def test_link_bootloader_logs_missing_files(self):
     method = PXEBootMethod()
     mock_maaslog = self.patch(maaslog, 'error')
     # If we don't mock the return value and the test system has the
     # pxelinux and syslinux-common package installed the fallback kicks
     # which makes PXE work but this test fail.
     self.patch(os.path, 'exists').return_value = False
     method.link_bootloader('foo')
     self.assertThat(mock_maaslog, MockCalledOnce())
예제 #5
0
파일: test_pxe.py 프로젝트: sydneypdx/maas
 def test_link_bootloader_logs_missing_files(self):
     method = PXEBootMethod()
     mock_maaslog = self.patch(maaslog, "error")
     # If we don't mock the return value and the test system has the
     # pxelinux and syslinux-common package installed the fallback kicks
     # which makes PXE work but this test fail.
     self.patch(os.path, "exists").return_value = False
     self.patch(pxe_module, "atomic_symlink")
     method.link_bootloader("foo")
     self.assertTrue(mock_maaslog.called)
예제 #6
0
    def test_link_simplestream_bootloaders_creates_lpxelinux_and_links(self):
        method = PXEBootMethod()
        with tempdir() as tmp:
            stream_path = os.path.join(tmp, 'bootloader',
                                       method.bios_boot_method,
                                       method.bootloader_arches[0])
            os.makedirs(stream_path)
            for bootloader_file in method.bootloader_files:
                factory.make_file(stream_path, bootloader_file)

            method.link_bootloader(tmp)

            self.assertTrue(os.path.exists(os.path.join(tmp, 'lpxelinux.0')))
            self.assertTrue(os.path.islink(os.path.join(tmp, 'pxelinux.0')))
예제 #7
0
    def test_link_simplestream_bootloaders_creates_syslinux_link(self):
        method = PXEBootMethod()
        with tempdir() as tmp:
            stream_path = os.path.join(tmp, 'bootloader',
                                       method.bios_boot_method,
                                       method.bootloader_arches[0])
            os.makedirs(stream_path)
            for bootloader_file in method.bootloader_files:
                factory.make_file(stream_path, bootloader_file)

            method.link_bootloader(tmp)

            for bootloader_file in method.bootloader_files:
                bootloader_file_path = os.path.join(tmp, bootloader_file)
                self.assertTrue(os.path.islink(bootloader_file_path))
            syslinux_link = os.path.join(tmp, 'syslinux')
            self.assertTrue(os.path.islink(syslinux_link))
            self.assertEquals(stream_path, os.path.realpath(syslinux_link))