Exemple #1
0
 def test_wb_start_session(self):
     prometheus_metrics = create_metrics(
         METRICS_DEFINITIONS,
         registry=prometheus_client.CollectorRegistry())
     stream_session = FakeStreamSession()
     session = FakeSession(stream_session)
     tftp_mock = self.patch(tftp.protocol.TFTP, '_startSession')
     tftp_mock.return_value = succeed(session)
     tracking_tftp = TransferTimeTrackingTFTP(sentinel.backend)
     datagram = RQDatagram(b'file.txt', b'octet', {})
     result = yield tracking_tftp._startSession(
         datagram,
         '192.168.1.1',
         'read',
         prometheus_metrics=prometheus_metrics)
     result.session.cancel()
     metrics = prometheus_metrics.generate_latest().decode('ascii')
     self.assertIs(result, session)
     self.assertTrue(stream_session.cancelled)
     self.assertIn(
         'maas_tftp_file_transfer_latency_count{filename="file.txt"} 1.0',
         metrics)
Exemple #2
0
 def clean_filename(self, path):
     datagram = RQDatagram(path, b"octet", {})
     tftp = TransferTimeTrackingTFTP(sentinel.backend)
     return tftp._clean_filename(datagram)