def test__preserves_version_type_and_payload__discards_bytes(self):
     test_bytes = factory.make_bytes()
     test_version = factory.make_string()
     test_type = factory.make_string()
     test_payload = {factory.make_string(): factory.make_string()}
     beacon = BeaconPayload(test_bytes, test_version, test_type,
                            test_payload)
     beacon_json = beacon_to_json(beacon)
     self.assertThat(beacon_json["version"], Equals(test_version))
     self.assertThat(beacon_json["type"], Equals(test_type))
     self.assertThat(beacon_json["payload"], Equals(test_payload))
     self.assertThat(beacon_json, Not(Contains("bytes")))
     self.assertThat(beacon_json, HasLength(3))
Exemple #2
0
    def datagramReceived(self, datagram, addr):
        """Called by Twisted when a UDP datagram is received.

        Note: In the typical use case, the MAAS server will ignore packets
        coming into this method. We need to listen to the socket normally,
        however, so that the underlying network stack will send ICMP
        destination (port) unreachable replies to anyone trying to send us
        beacons. However, at other times, (such as while running the test
        commands), we *will* listen to the socket layer for beacons.
        """
        if self.process_incoming is True:
            context = {"source_ip": addr[0], "source_port": addr[1]}
            beacon_json = beacon_to_json(read_beacon_payload(datagram))
            beacon_json.update(context)
            self.beaconReceived(beacon_json)