def test_keepalive_called(self): # set up to fire this deferred on receipt of a keepalive d = defer.Deferred() def on_keepalive(): # need to wait long enough for the remote_keepalive call to # finish, but not for another one to queue up reactor.callLater(0.01, d.callback, None) persp = MasterPerspective(on_keepalive=on_keepalive) # start up the master and slave, with a very short keepalive port = self.start_master(persp) self.buildslave = bot.BuildSlave("127.0.0.1", port, "testy", "westy", self.basedir, keepalive=0.1, keepaliveTimeout=0.05, usePTY=False) self.buildslave.startService() # and wait for it to keepalive return d
def test_constructor_083_tac(self): # invocation as made from default 083 tac files bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False, umask=0o123, maxdelay=10)
def test_hostname_file(self): self.buildslave = bot.BuildSlave("127.0.0.1", 9999, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=022) self.assertEqual( open(os.path.join(self.basedir, "twistd.hostname")).read().strip(), 'test-hostname.domain.com')
def test_constructor_full(self): # invocation with all args bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False, umask=0o123, maxdelay=10, keepaliveTimeout=10, unicode_encoding='utf8', allow_shutdown=True)
def test_buildslave_shutdown(self): """Test watching an existing shutdown_file results in gracefulShutdown being called.""" buildslave = bot.BuildSlave("127.0.0.1", 1234, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=0o22, allow_shutdown='file') # Mock out gracefulShutdown buildslave.gracefulShutdown = Mock() # Mock out os.path methods exists = Mock() mtime = Mock() self.patch(os.path, 'exists', exists) self.patch(os.path, 'getmtime', mtime) # Pretend that the shutdown file doesn't exist mtime.return_value = 0 exists.return_value = False buildslave._checkShutdownFile() # We shouldn't have called gracefulShutdown self.assertEquals(buildslave.gracefulShutdown.call_count, 0) # Pretend that the file exists now, with an mtime of 2 exists.return_value = True mtime.return_value = 2 buildslave._checkShutdownFile() # Now we should have changed gracefulShutdown self.assertEquals(buildslave.gracefulShutdown.call_count, 1) # Bump the mtime again, and make sure we call shutdown again mtime.return_value = 3 buildslave._checkShutdownFile() self.assertEquals(buildslave.gracefulShutdown.call_count, 2) # Try again, we shouldn't call shutdown another time buildslave._checkShutdownFile() self.assertEquals(buildslave.gracefulShutdown.call_count, 2)
def test_recordHostname_uname(self): self.patch_os_uname(lambda: [0, 'test-hostname.domain.com']) self.buildslave = bot.BuildSlave("127.0.0.1", 9999, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=0o22) self.buildslave.recordHostname(self.basedir) self.assertEqual( open(os.path.join(self.basedir, "twistd.hostname")).read().strip(), 'test-hostname.domain.com')
def test_recordHostname_getfqdn(self): def missing(): raise AttributeError self.patch_os_uname(missing) self.patch(socket, "getfqdn", lambda: 'test-hostname.domain.com') self.buildslave = bot.BuildSlave("127.0.0.1", 9999, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=0o22) self.buildslave.recordHostname(self.basedir) self.assertEqual( open(os.path.join(self.basedir, "twistd.hostname")).read().strip(), 'test-hostname.domain.com')
def test_buildslave_graceful_shutdown(self): """Test that running the build slave's gracefulShutdown method results in a call to the master's shutdown method""" d = defer.Deferred() fakepersp = Mock() called = [] def fakeCallRemote(*args): called.append(args) d1 = defer.succeed(None) return d1 fakepersp.callRemote = fakeCallRemote # set up to call shutdown when we are attached, and chain the results onto # the deferred for the whole test def call_shutdown(mind): self.buildslave.bf.perspective = fakepersp shutdown_d = self.buildslave.gracefulShutdown() shutdown_d.addCallbacks(d.callback, d.errback) persp = MasterPerspective() port = self.start_master(persp, on_attachment=call_shutdown) self.buildslave = bot.BuildSlave("127.0.0.1", port, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=0o22) self.buildslave.startService() def check(ign): self.assertEquals(called, [('shutdown', )]) d.addCallback(check) return d
def test_buildslave_print(self): d = defer.Deferred() # set up to call print when we are attached, and chain the results onto # the deferred for the whole test def call_print(mind): print_d = mind.callRemote("print", "Hi, slave.") print_d.addCallbacks(d.callback, d.errback) # start up the master and slave persp = MasterPerspective() port = self.start_master(persp, on_attachment=call_print) self.buildslave = bot.BuildSlave("127.0.0.1", port, "testy", "westy", self.basedir, keepalive=0, usePTY=False, umask=0o22) self.buildslave.startService() # and wait for the result of the print return d
def test_constructor_minimal(self): # only required arguments bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False)