def test_tenant_dn_root(self): manager = aci_tenant.AciTenantManager( 'tn-test', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager)) self.assertEqual('uni/tn-test', manager.tenant.dn) manager = aci_tenant.AciTenantManager( 'phys-test', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager)) self.assertEqual('uni/phys-test', manager.tenant.dn) manager = aci_tenant.AciTenantManager( 'pod-test', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager)) self.assertEqual('topology/pod-test', manager.tenant.dn)
def test_event_loop_failure(self): manager = aci_tenant.AciTenantManager( 'tn-1', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager)) manager.ws_context.has_event = mock.Mock(side_effect=KeyError) # Main loop is not raising manager._main_loop()
def setUp(self): super(TestAciTenant, self).setUp() self._do_aci_mocks() self.backend_state = {} universe = aci_universe.AciUniverse().initialize( aim_cfg.ConfigManager(self.ctx, 'h1'), []) self.manager = aci_tenant.AciTenantManager( 'tn-tenant-1', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager), get_resources=universe.get_resources) self.manager._get_full_state = mock.Mock( return_value=[self.backend_state])
def test_tenant_reset(self): manager = aci_tenant.AciTenantManager( 'tn-1', self.cfg_manager, aci_universe.AciUniverse.establish_aci_session(self.cfg_manager), aci_universe.get_websocket_context(self.cfg_manager)) manager.polling_yield = 0 self.assertIsNone(getattr(manager, 'scheduled_reset', None)) min = time.time() + (aci_tenant.RESET_INTERVAL - aci_tenant.RESET_INTERVAL * 0.2) max = time.time() + (aci_tenant.RESET_INTERVAL + aci_tenant.RESET_INTERVAL * 0.2) + 1 manager._unsubscribe_tenant = mock.Mock() manager.num_loop_runs = 1 manager._main_loop() self.assertTrue(min < manager.scheduled_reset < max) manager.scheduled_reset = 0 # We don't want subscribe tenant to screw up the reset time manager._subscribe_tenant = mock.Mock() self.assertEqual(0, manager._unsubscribe_tenant.call_count) manager.num_loop_runs = 1 # Exception is raised here manager._main_loop() self.assertEqual(1, manager._unsubscribe_tenant.call_count)