Ejemplo n.º 1
0
 def __init__(self, file_path, dyn_handler):
     self.file_path = file_path
     try:
         self.string_data = dyn_handler(file_path)
         if self.string_data is None:
             raise FileNotFound(self.file_path)
     except:
         raise FileNotFound(self.file_path)
     self.state = 'active'
Ejemplo n.º 2
0
 def __init__(self, file_path):
     self.file_path = file_path
     try:
         self.file_obj = self.file_path.open('r')
     except IOError:
         raise FileNotFound(self.file_path)
     self.state = 'active'
Ejemplo n.º 3
0
 def test_file_not_found(self):
     tftp = TFTP(BackendFactory(FileNotFound("Not found")),
                 _clock=self.clock)
     tftp.transport = self.transport
     rrq_datagram = RRQDatagram(b'foobar', b'netascii', {})
     tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
     self.clock.advance(1)
     error_datagram = TFTPDatagramFactory(
         *split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_FILE_NOT_FOUND)
Ejemplo n.º 4
0
    def get_page_errback(failure, file_name):
        failure.trap(twisted.web.error.Error)
        # This twisted.web.error.Error.status object ends up being a
        # string for some reason, but the constants we can compare against
        # (both in httplib and twisted.web.http) are ints.
        try:
            status_int = int(failure.value.status)
        except ValueError:
            # Assume that it's some other error and propagate it
            return failure

        if status_int == httplib.NO_CONTENT:
            # Convert HTTP No Content to a TFTP file not found
            raise FileNotFound(file_name)
        else:
            # Otherwise propogate the unknown error
            return failure
Ejemplo n.º 5
0
    def test_render_GET_404_file_not_found(self):
        path = factory.make_name("path")
        ip = factory.make_ip_address()
        request = DummyRequest([path.encode("utf-8")])
        request.requestHeaders = Headers({
            "X-Server-Addr": ["192.168.1.1"],
            "X-Server-Port": ["5248"],
            "X-Forwarded-For": [ip],
            "X-Forwarded-Port": ["%s" % factory.pick_port()],
        })

        self.patch(http.log, "info")
        mock_deferLater = self.patch(http, "deferLater")
        mock_deferLater.side_effect = always_succeed_with(None)

        self.tftp.backend.get_reader.return_value = fail(FileNotFound(path))

        resource = http.HTTPBootResource()
        yield self.render_GET(resource, request)

        self.assertEqual(404, request.responseCode)
        self.assertEqual(b"", b"".join(request.written))
Ejemplo n.º 6
0
    def test_render_GET_404_file_not_found(self):
        path = factory.make_name('path')
        ip = factory.make_ip_address()
        request = DummyRequest([path.encode('utf-8')])
        request.requestHeaders = Headers({
            'X-Server-Addr': ['192.168.1.1'],
            'X-Server-Port': ['5248'],
            'X-Forwarded-For': [ip],
            'X-Forwarded-Port': ['%s' % factory.pick_port()],
        })

        self.patch(http.log, 'info')
        mock_deferLater = self.patch(http, 'deferLater')
        mock_deferLater.side_effect = always_succeed_with(None)

        self.tftp.backend.get_reader.return_value = fail(FileNotFound(path))

        resource = http.HTTPBootResource()
        yield self.render_GET(resource, request)

        self.assertEquals(404, request.responseCode)
        self.assertEquals(b'', b''.join(request.written))
Ejemplo n.º 7
0
 def return_binary_path(data):
     r = params['remote']
     self.clients[r] = {}
     self.clients[r]['data'] = data
     self.clients[r]['is_windows'] = False
     log.msg(">>>>>NODE DETAILS%r" % data)
     release = data.get('release')
     if data.get('purpose') == 'local':
         raise FileNotFound("pxelinux.0")
     if release.startswith('win'):
         self.clients[r]['is_windows'] = True
         path = "pxeboot.0"
         self.base = FilePath(
             '/var/lib/maas/tftp/%s/%s/%s/install/' %
             (data['arch'], data['subarch'], data['release']))
         self.clients[r]['base'] = self.base
     else:
         self.is_windows = False
         self.base = FilePath(Config.load_from_cache()['tftp']['root'])
         self.clients[r]['base'] = self.base
         path = "pxelinux.0"
     return path.encode('utf-8')
Ejemplo n.º 8
0
 def no_response_errback(failure, file_name):
     failure.trap(BootConfigNoResponse)
     # Convert to a TFTP file not found.
     raise FileNotFound(file_name)