def test_read_existing_file(self): r = FilesystemReader(self.temp_dir.child("foo")) data = r.read(3) ostring = data while data: data = r.read(3) ostring += data self.assertEqual(r.read(3), "") self.assertEqual(r.read(5), "") self.assertEqual(r.read(7), "") self.failUnless(r.file_obj.closed, "The file has been exhausted and should be in the closed state") self.assertEqual(ostring, self.test_data)
def test_cancel(self): r = FilesystemReader(self.temp_dir.child(b'foo')) r.read(3) r.finish() self.assertTrue( r.file_obj.closed, "The session has been finished, so the file object should be in the closed state" ) r.finish()
def read(self, size): data = FilesystemReader.read(self, size) d = Deferred() def c(ign): return data d.addCallback(c) self._clock.callLater(self.delay, d.callback, None) return d
def output_static(self, kernel_params, path): """Outputs the static file based on the version of Windows.""" # Delayed import; prevent twisted reactor from being # installed to early. from tftp.backend import FilesystemReader actual_path = self.get_resource_path(kernel_params, path) return FilesystemReader(FilePath(actual_path))
def test_cancel(self): r = FilesystemReader(self.temp_dir.child('foo')) r.read(3) r.finish() self.failUnless(r.file_obj.closed, "The session has been finished, so the file object should be in the closed state") r.finish()
def test_read_existing_file(self): r = FilesystemReader(self.temp_dir.child(b'foo')) data = r.read(3) ostring = data while data: data = r.read(3) ostring += data self.assertEqual(r.read(3), b'') self.assertEqual(r.read(5), b'') self.assertEqual(r.read(7), b'') self.assertTrue( r.file_obj.closed, b"The file has been exhausted and should be in the closed state") self.assertEqual(ostring, self.test_data)
def get_reader(self, backend, kernel_params, mac=None, path=None, **extra): """Render a configuration file as a unicode string. :param backend: requesting backend :param kernel_params: An instance of `KernelParameters`. :param path: Optional MAC address discovered by `match_path`. :param path: Optional path discovered by `match_path`. :param extra: Allow for other arguments. This is a safety valve; parameters generated in another component (for example, see `TFTPBackend.get_config_reader`) won't cause this to break. """ if path is not None: # This is a request for a static file, not a configuration file. # The prefix was already trimmed by `match_path` so we need only # return a FilesystemReader for `path` beneath the backend's base. target_path = backend.base.descendant(path.split("/")) return FilesystemReader(target_path) # Return empty config for S390x local. S390x fails to # support the LOCALBOOT flag. Empty config will allow it # to select the first device. if kernel_params.purpose == "local": return BytesReader("".encode("utf-8")) template = self.get_template( kernel_params.purpose, kernel_params.arch, kernel_params.subarch ) namespace = self.compose_template_namespace(kernel_params) # Modify the kernel_command to inject the BOOTIF. S390x fails to # support the IPAPPEND pxelinux flag. def kernel_command(params): cmd_line = compose_kernel_command_line(params) if mac is not None: return "%s BOOTIF=%s" % (cmd_line, format_bootif(mac)) return cmd_line namespace["kernel_command"] = kernel_command return BytesReader(template.substitute(namespace).encode("utf-8"))
def output_static(self, kernel_params, path): """Outputs the static file based on the version of Windows.""" actual_path = self.get_resource_path(kernel_params, path) return FilesystemReader(FilePath(actual_path))
def __init__(self, *args, **kwargs): self.delay = kwargs.pop('delay') self._clock = kwargs.pop('_clock', reactor) FilesystemReader.__init__(self, *args, **kwargs)
def test_size_when_file_removed(self): # FilesystemReader.size uses fstat() to discover the file's size, so # the absence of the file does not matter. r = FilesystemReader(self.temp_dir.child(b'foo')) self.existing_file_name.remove() self.assertEqual(len(self.test_data), r.size)
def test_size_when_reader_finished(self): r = FilesystemReader(self.temp_dir.child(b'foo')) r.finish() self.assertTrue(r.size is None)
def test_size(self): r = FilesystemReader(self.temp_dir.child(b'foo')) self.assertEqual(len(self.test_data), r.size)
def __init__(self, *args, **kwargs): self.delay = kwargs.pop("delay") self._clock = kwargs.pop("_clock", reactor) FilesystemReader.__init__(self, *args, **kwargs)
def test_size_when_reader_finished(self): r = FilesystemReader(self.temp_dir.child('foo')) r.finish() self.assertIsNone(r.size)
def test_size_when_reader_finished(self): r = FilesystemReader(self.temp_dir.child("foo")) r.finish() self.assertTrue(r.size is None)