def testDoubleAssignment(): clearDatabase() # Setup Service with license assburner = createService('Assburner') service = createService('Test') host = createHost('Host',[assburner,service]) job1 = createBatchJob('Test1',49,[assburner]) job2 = createBatchJob('Test2',50,[assburner]) host.hostStatus().setAvailableMemory( 50 ).commit() manager.run_loop() manager.run_loop() # Job1 should be assigned assert( job1.jobTasks()[0].host() == host ) # Job2 should not be assigned because it does not have avg memory stats yet assert( host.activeAssignments().size() == 1 ) job2.jobStatus().setAverageMemory( 55 ).commit() manager.run_loop() # Job2 should not be assigned because host does not have enough memory for both jobs assert( host.activeAssignments().size() == 1 ) job2.jobStatus().setAverageMemory( 20 ).commit() manager.run_loop() # Job1 should get assigned to host now that there is enough memory for both assert( host.hostStatus().reload().slaveStatus() == 'ready' ) assert( job2.jobTasks()[0].host() == host )
def testSingleAssignment(): clearDatabase() # Setup Service with license assburner = createService('Assburner') service = createService('Test') host = createHost('Host',[assburner,service]) job1 = createBatchJob('Test1',50,[assburner]) manager.run_loop() # Job1 should get assigned to host assert( host.hostStatus().reload().slaveStatus() == 'ready' ) assert( job1.jobTasks()[0].host() == host ) assert( host.activeAssignments().size() == 1 ) assert( host.activeAssignments()[0] == job1.jobTasks()[0].jobTaskAssignment().jobAssignment() )
def testUnassignment(): clearDatabase() # Setup Service with license assburner = createService('Assburner') service = createService('Test') host = createHost('Host',[assburner,service]) job1 = createBatchJob('Test1',50,[assburner]) manager.run_loop() # Job1 should get assigned to host assert( host.hostStatus().reload().slaveStatus() == 'ready' ) print( job1.jobTasks()[0].dump() ) assert( job1.jobTasks()[0].host() == host ) job2 = createBatchJob('Test2',1,[service]) manager.run_loop() simulateAssburner() assert( job1.jobTasks()[0].status() == 'new' ) manager.run_loop() assert( job2.jobTasks()[0].jobTaskAssignment().host() == host )
def testLicenseUnassignment(): print "\n\nTesting License Unassignment\n\n" clearDatabase() # Setup Service with license lic = License().setTotal(0).commit() assburner = createService('Assburner') service = createService('Test',lic) host = createHost('Host',[service,assburner]) job1 = createBatchJob('Test1',50) manager.run_loop() # Job1 should get assigned to host assert( host.hostStatus().reload().slaveStatus() == 'assigned' ) assert( job1.jobTasks()[0].host() == host ) # Create higher priority job that current has no licenses available job2 = createBatchJob('Test2',1,[service]) # Make sure nothing gets unassigned since it has not licenses manager.run_loop() assert( job1.jobTasks()[0].host() == host ) # Give it a license and test that job Test1 gets unassigned lic.setTotal(1).commit() manager.run_loop() simulateAssburner() assert( job1.jobTasks()[0].status() == 'new' ) manager.run_loop() assert( job2.jobTasks()[0].host() == host ) # Create new high priority job with same license needs job3 = createBatchJob('Test3',1,[service]) # Change current assigned jobs priority job2.setPriority(40).commit() manager.run_loop() simulateAssburner() Database.current().setEchoMode(Database.EchoSelect) print lic.reload().dump() Database.current().setEchoMode(0) assert( job2.jobTasks()[0].status() == 'new' ) manager.run_loop() assert( job3.jobTasks()[0].host() == host )