def test_attached_callRemote_getSlaveInfo(self): slave = self.createBuildslave() yield slave.startService() ENVIRON = {} bot = createRemoteBot() bot.response['getSlaveInfo'] = mock.Mock( return_value=defer.succeed({ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'environ': ENVIRON, 'basedir': 'TheBaseDir', 'system': 'TheSlaveSystem' })) yield slave.attached(bot) # check that things were all good self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) # check the values get set right self.assertEqual(slave.slave_status.getAdmin(), "TheAdmin") self.assertEqual(slave.slave_status.getHost(), "TheHost") self.assertEqual(slave.slave_status.getAccessURI(), "TheURI") self.assertEqual(slave.slave_environ, ENVIRON) self.assertEqual(slave.slave_basedir, 'TheBaseDir') self.assertEqual(slave.slave_system, 'TheSlaveSystem')
def test_attached_remoteGetSlaveInfo(self): slave = self.createBuildslave() yield slave.startService() ENVIRON = {} COMMANDS = {'cmd1': '1', 'cmd2': '1'} conn = fakeprotocol.FakeConnection(slave.master, slave) conn.info = { 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'environ': ENVIRON, 'basedir': 'TheBaseDir', 'system': 'TheSlaveSystem', 'version': 'version', 'slave_commands': COMMANDS, } yield slave.attached(conn) # check the values get set right self.assertEqual(slave.slave_status.getAdmin(), "TheAdmin") self.assertEqual(slave.slave_status.getHost(), "TheHost") self.assertEqual(slave.slave_status.getAccessURI(), "TheURI") self.assertEqual(slave.slave_environ, ENVIRON) self.assertEqual(slave.slave_basedir, 'TheBaseDir') self.assertEqual(slave.slave_system, 'TheSlaveSystem') self.assertEqual(slave.slave_commands, COMMANDS)
def test_startService_setSlaveInfo_UpdatesDb(self): self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'version': 'TheVersion', 'key': 'value', }) ]) slave = self.createBuildslave() yield slave.startService() # change a value slave.slave_status.updateInfo(key='new-value') self.clock.pump( [0]) # we overrode the reactor, so gotta force the calls yield eventual.flushEventualQueue() # and the db is updated too: slave_db = yield self.master.db.buildslaves.getBuildslaveByName("bot") self.assertEqual(slave_db['slaveinfo']['admin'], 'TheAdmin') self.assertEqual(slave_db['slaveinfo']['host'], 'TheHost') self.assertEqual(slave_db['slaveinfo']['access_uri'], 'TheURI') self.assertEqual(slave_db['slaveinfo']['version'], 'TheVersion') self.assertEqual(slave_db['slaveinfo']['key'], 'new-value')
def test_startService_setSlaveInfo_UpdatesDb(self): self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'version': 'TheVersion', 'key': 'value', }) ]) slave = self.createBuildslave() yield slave.startService() # change a value slave.slave_status.updateInfo(key='new-value') self.clock.pump([0]) # we overrode the reactor, so gotta force the calls yield eventual.flushEventualQueue() # and the db is updated too: slave_db = yield self.master.db.buildslaves.getBuildslaveByName("bot") self.assertEqual(slave_db['slaveinfo']['admin'], 'TheAdmin') self.assertEqual(slave_db['slaveinfo']['host'], 'TheHost') self.assertEqual(slave_db['slaveinfo']['access_uri'], 'TheURI') self.assertEqual(slave_db['slaveinfo']['version'], 'TheVersion') self.assertEqual(slave_db['slaveinfo']['key'], 'new-value')
def test_attached_slaveInfoUpdates(self): # put in stale info: self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'WrongAdmin', 'host': 'WrongHost', 'access_uri': 'WrongURI', 'version': 'WrongVersion' }) ]) slave = self.createBuildslave() yield slave.startService() conn = fakeprotocol.FakeConnection(slave.master, slave) conn.info = { 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'version': 'TheVersion', } yield slave.attached(conn) self.assertEqual(slave.slave_status.getAdmin(), 'TheAdmin') self.assertEqual(slave.slave_status.getHost(), 'TheHost') self.assertEqual(slave.slave_status.getAccessURI(), 'TheURI') self.assertEqual(slave.slave_status.getVersion(), 'TheVersion') # and the db is updated too: buildslave = yield self.master.db.buildslaves.getBuildslave(name="bot") self.assertEqual(buildslave['slaveinfo']['admin'], 'TheAdmin') self.assertEqual(buildslave['slaveinfo']['host'], 'TheHost') self.assertEqual(buildslave['slaveinfo']['access_uri'], 'TheURI') self.assertEqual(buildslave['slaveinfo']['version'], 'TheVersion')
def test_slave_shutdown(self): slave = self.createBuildslave(attached=True) yield slave.startService() yield slave.shutdown() self.assertEqual(slave.conn.remoteCalls, [('remoteSetBuilderList', []), ('remoteShutdown', )])
def test_attached_callRemote_getSlaveInfo(self): slave = self.createBuildslave() yield slave.startService() ENVIRON = {} bot = createRemoteBot() bot.response['getSlaveInfo'] = mock.Mock(return_value=defer.succeed({ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'environ': ENVIRON, 'basedir': 'TheBaseDir', 'system': 'TheSlaveSystem' })) yield slave.attached(bot) # check that things were all good self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) # check the values get set right self.assertEqual(slave.slave_status.getAdmin(), "TheAdmin") self.assertEqual(slave.slave_status.getHost(), "TheHost") self.assertEqual(slave.slave_status.getAccessURI(), "TheURI") self.assertEqual(slave.slave_environ, ENVIRON) self.assertEqual(slave.slave_basedir, 'TheBaseDir') self.assertEqual(slave.slave_system, 'TheSlaveSystem')
def test_attached_slaveInfoUpdates(self): # put in stale info: self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'WrongAdmin', 'host': 'WrongHost', 'access_uri': 'WrongURI', 'version': 'WrongVersion' }) ]) slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() bot.response['getVersion'] = mock.Mock( return_value=defer.succeed("TheVersion")) bot.response['getSlaveInfo'] = mock.Mock(return_value=defer.succeed({ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', })) yield slave.attached(bot) self.assertEqual(slave.slave_status.getAdmin(), 'TheAdmin') self.assertEqual(slave.slave_status.getHost(), 'TheHost') self.assertEqual(slave.slave_status.getAccessURI(), 'TheURI') self.assertEqual(slave.slave_status.getVersion(), 'TheVersion') # and the db is updated too: buildslave = yield self.master.db.buildslaves.getBuildslaveByName("bot") self.assertEqual(buildslave['slaveinfo']['admin'], 'TheAdmin') self.assertEqual(buildslave['slaveinfo']['host'], 'TheHost') self.assertEqual(buildslave['slaveinfo']['access_uri'], 'TheURI') self.assertEqual(buildslave['slaveinfo']['version'], 'TheVersion')
def test_startService_getSlaveInfo_empty(self): slave = self.createBuildslave() yield slave.startService() self.assertEqual(slave.slave_status.getAdmin(), None) self.assertEqual(slave.slave_status.getHost(), None) self.assertEqual(slave.slave_status.getAccessURI(), None) self.assertEqual(slave.slave_status.getVersion(), None)
def test_attached_callsMaybeStartBuildsForSlave(self): slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() yield slave.attached(bot) self.assertEqual(self.botmaster.buildsStartedForSlaves, ["bot"])
def test_attached_callsMaybeStartBuildsForSlave(self): slave = self.createBuildslave() yield slave.startService() conn = fakeprotocol.FakeConnection(slave.master, slave) conn.info = {} yield slave.attached(conn) self.assertEqual(self.botmaster.buildsStartedForSlaves, ["bot"])
def test_stopService(self): slave = self.createBuildslave() yield slave.startService() reg = slave.registration yield slave.stopService() self.assertTrue(reg.unregistered) self.assertEqual(slave.registration, None)
def test_attached_callRemote_print_raises(self): slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() bot.response['print'] = mock.Mock( return_value=defer.fail(ValueError())) yield slave.attached(bot) # just check that things still go on self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands))
def test_startService_getSlaveInfo_empty(self): slave = self.createBuildslave() yield slave.startService() self.assertEqual(slave.slave_status.getAdmin(), None) self.assertEqual(slave.slave_status.getHost(), None) self.assertEqual(slave.slave_status.getAccessURI(), None) self.assertEqual(slave.slave_status.getVersion(), None) # check that a new slave row was added for this buildslave bs = yield self.master.db.buildslaves.getBuildslave(name='bot') self.assertEqual(bs['name'], 'bot')
def test_attached_checkRemoteCalls(self): slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() yield slave.attached(bot) self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) self.assertEqual(bot.commands[0], ('print', 'attached')) self.assertEqual(bot.commands[1], ('getSlaveInfo',)) self.assertEqual(bot.commands[2], ('getVersion',)) self.assertEqual(bot.commands[3], ('getCommands',)) self.assertEqual(bot.commands[4], ('setBuilderList', []))
def test_attached_checkRemoteCalls(self): slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() yield slave.attached(bot) self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) self.assertEqual(bot.commands[0], ('print', 'attached')) self.assertEqual(bot.commands[1], ('getSlaveInfo', )) self.assertEqual(bot.commands[2], ('getVersion', )) self.assertEqual(bot.commands[3], ('getCommands', )) self.assertEqual(bot.commands[4], ('setBuilderList', []))
def test_attached_callRemote_getVersion(self): slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() bot.response['getVersion'] = mock.Mock( return_value=defer.succeed("TheVersion")) yield slave.attached(bot) # check that things were all good self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) # check the values get set right self.assertEqual(slave.slave_status.getVersion(), "TheVersion")
def test_stopService(self): slave = self.createBuildslave() yield slave.startService() config = mock.Mock() config.protocols = {'pb': {'port': 'tcp:1234'}} config.slaves = [slave] yield slave.reconfigService(config) yield slave.stopService() self.assertEqual(self.master.pbmanager._unregistrations, [('tcp:1234', 'bot')]) self.assertEqual(self.master.pbmanager._registrations, [('tcp:1234', 'bot', 'pass')])
def test_stopService(self): slave = self.createBuildslave() yield slave.startService() config = mock.Mock() config.protocols = {'pb': {'port': 'tcp:1234'}} config.slaves = [slave] yield slave.reconfigService(config) reg = slave.registration yield slave.stopService() self.assertTrue(reg.unregistered) self.assertEqual(slave.registration, None)
def test_startService_getSlaveInfo_fromDb(self): self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'version': 'TheVersion' }) ]) slave = self.createBuildslave() yield slave.startService() self.assertEqual(slave.slave_status.getAdmin(), 'TheAdmin') self.assertEqual(slave.slave_status.getHost(), 'TheHost') self.assertEqual(slave.slave_status.getAccessURI(), 'TheURI') self.assertEqual(slave.slave_status.getVersion(), 'TheVersion')
def test_attached_callRemote_getCommands(self): slave = self.createBuildslave() yield slave.startService() COMMANDS = ['a', 'b'] bot = createRemoteBot() bot.response['getCommands'] = mock.Mock( return_value=defer.succeed(COMMANDS)) yield slave.attached(bot) # check that things were all good self.assertEqual(True, slave.slave_status.isConnected()) self.assertEqual(5, len(bot.commands)) # check the values get set right self.assertEqual(slave.slave_commands, COMMANDS)
def test_startService_getSlaveInfo_fromDb(self): self.master.db.insertTestData([ fakedb.Buildslave(id=9292, name='bot', info={ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', 'version': 'TheVersion' }) ]) slave = self.createBuildslave() yield slave.startService() self.assertEqual(slave.buildslaveid, 9292) self.assertEqual(slave.slave_status.getAdmin(), 'TheAdmin') self.assertEqual(slave.slave_status.getHost(), 'TheHost') self.assertEqual(slave.slave_status.getAccessURI(), 'TheURI') self.assertEqual(slave.slave_status.getVersion(), 'TheVersion')
def test_attached_slaveInfoUpdates(self): # put in stale info: self.master.db.insertTestData([ fakedb.Buildslave(name='bot', info={ 'admin': 'WrongAdmin', 'host': 'WrongHost', 'access_uri': 'WrongURI', 'version': 'WrongVersion', 'key': 'value', }) ]) slave = self.createBuildslave() yield slave.startService() bot = createRemoteBot() bot.response['getVersion'] = mock.Mock( return_value=defer.succeed("TheVersion")) bot.response['getSlaveInfo'] = mock.Mock( return_value=defer.succeed({ 'admin': 'TheAdmin', 'host': 'TheHost', 'access_uri': 'TheURI', })) yield slave.attached(bot) self.assertEqual(slave.slave_status.getAdmin(), 'TheAdmin') self.assertEqual(slave.slave_status.getHost(), 'TheHost') self.assertEqual(slave.slave_status.getAccessURI(), 'TheURI') self.assertEqual(slave.slave_status.getVersion(), 'TheVersion') self.assertEqual(slave.slave_status.getInfo('key'), 'value') self.clock.pump( [0]) # we overrode the reactor, so gotta force the calls yield eventual.flushEventualQueue() # and the db is updated too: buildslave = yield self.master.db.buildslaves.getBuildslaveByName( "bot") self.assertEqual(buildslave['slaveinfo']['admin'], 'TheAdmin') self.assertEqual(buildslave['slaveinfo']['host'], 'TheHost') self.assertEqual(buildslave['slaveinfo']['access_uri'], 'TheURI') self.assertEqual(buildslave['slaveinfo']['version'], 'TheVersion')
def test_slave_shutdown(self): slave = self.createBuildslave(attached=True) yield slave.startService() yield slave.shutdown() self.assertEqual(slave.conn.remoteCalls, [('remoteShutdown',)])
def test_slave_shutdown_not_connected(self): slave = self.createBuildslave(attached=False) yield slave.startService() # No exceptions should be raised here yield slave.shutdown()
def test_shutdownRequested(self): slave = self.createBuildslave(attached=False) yield slave.startService() yield slave.shutdownRequested() self.assertEqual(slave.slave_status.getGraceful(), True)