def test__returns_expected_arguments(self): ifname = factory.make_name("eth") service = BeaconingService(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-beacons")) self.assertTrue(args[2], Equals(ifname.encode("utf-8")))
def test__protocol_logs_stderr(self): logger = self.useFixture(TwistedLoggerFixture()) ifname = factory.make_name('eth') service = BeaconingService(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-beacons[%s]: Lines written to stderr are logged\n" "---\n" "observe-beacons[%s]: with a prefix, with no exceptions." % (ifname, ifname)))
def test__restarts_process_after_finishing(self): ifname = factory.make_name("eth") service = BeaconingService(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()