Esempio n. 1
0
 def test__returns_expected_arguments(self):
     ifname = factory.make_name("eth")
     service = NeighbourDiscoveryService(ifname, Mock())
     args = service.getProcessParameters()
     self.assertThat(args, HasLength(3))
     self.assertTrue(args[0].endswith(b"maas-common"))
     self.assertTrue(args[1], Equals(b"observe-arp"))
     self.assertTrue(args[2], Equals(ifname.encode("utf-8")))
Esempio n. 2
0
 def test__protocol_logs_stderr(self):
     logger = self.useFixture(TwistedLoggerFixture())
     ifname = factory.make_name('eth')
     service = NeighbourDiscoveryService(ifname, lambda _: None)
     protocol = service.createProcessProtocol()
     reactor.spawnProcess(protocol, b"sh", (b"sh", b"-c", b"exec cat >&2"))
     protocol.transport.write(b"Lines written to stderr are logged\n"
                              b"with a prefix, with no exceptions.\n")
     protocol.transport.closeStdin()
     yield protocol.done
     self.assertThat(
         logger.output,
         Equals("observe-arp[%s]: Lines written to stderr are logged\n"
                "---\n"
                "observe-arp[%s]: with a prefix, with no exceptions." %
                (ifname, ifname)))
Esempio n. 3
0
 def test__restarts_process_after_finishing(self):
     ifname = factory.make_name("eth")
     service = NeighbourDiscoveryService(ifname, Mock())
     mock_process_params = self.patch(service, "getProcessParameters")
     mock_process_params.return_value = [b"/bin/echo", b"{}"]
     service.clock = Clock()
     service.startService()
     # Wait for the protocol to finish
     service.clock.advance(0.0)
     yield service._protocol.done
     # Advance the clock (should start the service again)
     interval = service.step
     service.clock.advance(interval)
     # The Deferred should have been recreated.
     self.assertThat(service._protocol.done, Not(IsFiredDeferred()))
     yield service._protocol.done
     service.stopService()