Example #1
0
 def test_clean_path(self):
     method = WindowsPXEBootMethod()
     parts = [factory.make_string() for _ in range(3)]
     dirty_path = "\\".join(parts)
     valid_path = dirty_path.lower().replace("\\", "/")
     clean_path = method.clean_path(dirty_path)
     self.assertEqual(valid_path, clean_path)
Example #2
0
 def test_get_node_info(self):
     method = WindowsPXEBootMethod()
     mac = factory.make_mac_address()
     self.patch(windows_module, "get_remote_mac").return_value = mac
     mock_request_node_info = self.patch(
         windows_module, "request_node_info_by_mac_address")
     method.get_node_info()
     self.assertThat(mock_request_node_info, MockCalledOnceWith(mac))
Example #3
0
    def test_match_path_lpxelinux_get_node_info_None(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_get_node_info = self.patch(method, "get_node_info")
        mock_get_node_info.return_value = None

        params = yield method.match_path(None, "lpxelinux.0")
        self.assertEqual(params, None)
Example #4
0
    def test_match_path_static_file_clean_path(self):
        method = WindowsPXEBootMethod()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(windows_module, "get_remote_mac")
        mock_get_node_info.return_value = mock_mac

        params = yield method.match_path(None, "\\Boot\\BCD")
        self.assertEqual(mock_mac, params["mac"])
        self.assertEqual("bcd", params["path"])
Example #5
0
    def test_get_reader_static_file(self):
        method = WindowsPXEBootMethod()
        mock_path = factory.make_name("path")
        mock_output_static = self.patch(method, "output_static")
        kernel_params = make_kernel_parameters(osystem="windows")

        method.get_reader(None, kernel_params, path=mock_path)
        self.assertThat(mock_output_static,
                        MockCalledOnceWith(kernel_params, mock_path))
Example #6
0
    def test_match_path_static_file_clean_path(self):
        method = WindowsPXEBootMethod()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(windows_module, 'get_remote_mac')
        mock_get_node_info.return_value = mock_mac

        params = yield method.match_path(None, '\\Boot\\BCD')
        self.assertEqual(mock_mac, params['mac'])
        self.assertEqual('bcd', params['path'])
Example #7
0
 def test_output_static(self):
     method = WindowsPXEBootMethod()
     contents = factory.make_bytes()
     temp_dir = self.make_dir()
     filename = factory.make_file(temp_dir, "resource", contents=contents)
     self.patch(method, "get_resource_path").return_value = filename
     result = method.output_static(None, None)
     self.assertIsInstance(result, FilesystemReader)
     self.assertEqual(contents, result.read(10000))
Example #8
0
    def test_get_reader_bcd(self):
        method = WindowsPXEBootMethod()
        mock_compose_bcd = self.patch(method, 'compose_bcd')
        local_host = factory.make_ipv4_address()
        kernel_params = make_kernel_parameters(osystem='windows')

        method.get_reader(
            None, kernel_params, path='bcd', local_host=local_host)
        self.assertThat(
            mock_compose_bcd, MockCalledOnceWith(kernel_params, local_host))
Example #9
0
 def test_get_resouce_path(self):
     fake_tftproot = self.make_dir()
     self.useFixture(ClusterConfigurationFixture(tftp_root=fake_tftproot))
     method = WindowsPXEBootMethod()
     fake_path = factory.make_name('path')
     fake_kernelparams = make_kernel_parameters()
     result = method.get_resource_path(fake_kernelparams, fake_path)
     expected = os.path.join(
         fake_tftproot, 'windows', fake_kernelparams.arch,
         fake_kernelparams.subarch, fake_kernelparams.release,
         fake_kernelparams.label, fake_path)
     self.assertEqual(expected, result)
Example #10
0
    def test_match_path_lpxelinux_only_on_windows(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(method, "get_node_info")
        mock_get_node_info.return_value = {
            "purpose": "install",
            "osystem": factory.make_string(),
            "mac": mock_mac,
        }

        params = yield method.match_path(None, "lpxelinux.0")
        self.assertEqual(params, None)
Example #11
0
    def test_match_path_pxelinux_only_on_windows(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(method, 'get_node_info')
        mock_get_node_info.return_value = {
            'purpose': 'install',
            'osystem': factory.make_string(),
            'mac': mock_mac,
        }

        params = yield method.match_path(None, 'pxelinux.0')
        self.assertEqual(params, None)
Example #12
0
    def test_match_path_lpxelinux_missing_hivex(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(method, "get_node_info")
        mock_get_node_info.return_value = {
            "purpose": factory.make_string(),
            "osystem": "windows",
            "mac": mock_mac,
        }

        self.patch(windows_module, "HAVE_HIVEX")
        params = yield method.match_path(None, "lpxelinux.0")
        self.assertEqual(params, None)
Example #13
0
    def test_match_path_pxelinux(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(method, "get_node_info")
        mock_get_node_info.return_value = {
            "purpose": "install",
            "osystem": "windows",
            "mac": mock_mac,
        }

        params = yield method.match_path(None, "pxelinux.0")
        self.assertEqual(mock_mac, params["mac"])
        self.assertEqual(method.bootloader_path, params["path"])
Example #14
0
    def test_match_path_pxelinux_missing_hivex(self):
        method = WindowsPXEBootMethod()
        method.remote_path = factory.make_string()
        mock_mac = factory.make_mac_address()
        mock_get_node_info = self.patch(method, 'get_node_info')
        mock_get_node_info.return_value = {
            'purpose': factory.make_string(),
            'osystem': 'windows',
            'mac': mock_mac,
            }

        self.patch(windows_module, 'HAVE_HIVEX', )
        params = yield method.match_path(None, 'pxelinux.0')
        self.assertEqual(params, None)
Example #15
0
    def test_compose_bcd_missing_template(self):
        method = WindowsPXEBootMethod()
        self.patch(method, "get_resource_path").return_value = ""
        local_host = factory.make_ipv4_address()
        kernel_params = make_kernel_parameters()

        self.assertRaises(BootMethodError, method.compose_bcd, kernel_params,
                          local_host)
Example #16
0
    def test_compose_bcd(self):
        method = WindowsPXEBootMethod()
        local_host = factory.make_ipv4_address()
        kernel_params = make_kernel_parameters()

        fake_output = factory.make_string().encode("utf-8")
        self.patch(os.path, "isfile").return_value = True
        self.patch(shutil, "copyfile")
        self.patch(windows_module, "Bcd")

        # https://bugs.python.org/issue23004 -- mock_open() should allow
        # reading binary data -- prevents the use of mock_open() here.
        self.patch(windows_module, "open")
        windows_module.open.return_value = io.BytesIO(fake_output)
        output = method.compose_bcd(kernel_params, local_host)
        self.assertThat(windows_module.open, MockCalledOnceWith(ANY, "rb"))

        self.assertTrue(isinstance(output, BytesReader))
        self.assertEqual(fake_output, output.read(-1))
Example #17
0
 def test_compose_preseed_url(self):
     url = "http://localhost/MAAS"
     expected = "http:\\\\localhost\\^M^A^A^S"
     method = WindowsPXEBootMethod()
     output = method.compose_preseed_url(url)
     self.assertEqual(expected, output)
Example #18
0
    PowerNVBootMethod,
)
from provisioningserver.boot.pxe import PXEBootMethod  # noqa:E402 isort:skip
from provisioningserver.boot.s390x import (  # noqa:E402 isort:skip
    S390XBootMethod,
)
from provisioningserver.boot.uefi_amd64 import (  # noqa:E402 isort:skip
    UEFIAMD64BootMethod,
    UEFIAMD64HTTPBootMethod,
)
from provisioningserver.boot.uefi_arm64 import (  # noqa:E402 isort:skip
    UEFIARM64BootMethod,
)
from provisioningserver.boot.windows import (  # noqa:E402 isort:skip
    WindowsPXEBootMethod,
)

builtin_boot_methods = [
    IPXEBootMethod(),
    PXEBootMethod(),
    UEFIAMD64BootMethod(),
    UEFIAMD64HTTPBootMethod(),
    UEFIARM64BootMethod(),
    OpenFirmwarePPC64ELBootMethod(),
    PowerNVBootMethod(),
    WindowsPXEBootMethod(),
    S390XBootMethod(),
]
for method in builtin_boot_methods:
    BootMethodRegistry.register_item(method.name, method)
Example #19
0
 def test_clean_path_strip_boot(self):
     method = WindowsPXEBootMethod()
     dirty_path = "\\Boot\\BCD"
     clean_path = method.clean_path(dirty_path)
     self.assertEqual("bcd", clean_path)