def test_explain_placement(self): """Test explain placement""" app1 = scheduler.Application('foo.xxx#1', 100, demand=[1, 1, 1], affinity='foo.xxx') alloc = (self.cell.partitions['_default'].allocation.get_sub_alloc( 't1').get_sub_alloc('t3').get_sub_alloc('a2')) self.cell.add_app(alloc, app1) df = reports.explain_placement(self.cell, app1, mode='full') self.assertEqual(len(df), 7) df = reports.explain_placement(self.cell, app1, mode='servers') self.assertEqual(len(df), 4)
def placement(instance, mode): """Explain application placement""" cell_master = make_readonly_master() if instance not in cell_master.cell.apps: cli.bad_exit('Instance not found.') app = cell_master.cell.apps[instance] if app.server: cli.bad_exit('Instace already placed on %s' % app.server) frame = reports.explain_placement(cell_master.cell, app, mode) _print(frame, explain=True)
def _explain(inst_id): """Explain application placement""" with lc.LogContext(_LOGGER, inst_id): start = time.time() ro_scheduler = get_readonly_scheduler() _LOGGER.info('ro_scheduler was ready in %s secs', time.time() - start) try: instance = ro_scheduler.cell.apps[inst_id] except KeyError: raise exc.NotFoundError(inst_id) if instance.server: raise exc.FoundError('instance {} is already placed on {}'.format( inst_id, instance.server)) return reports.explain_placement(ro_scheduler.cell, instance, 'servers')