

def test_get_cfg_agents(self):
    self._setup_cfg_agents(True, True)
    agents = self.plugin.get_cfg_agents(self.adminContext)
    self.assertEqual(len(self._agent_dict), len(agents))
    for agent in agents:
        self.assertIn(agent.host, self._agent_dict)
    id_cfg_agent_disabled = self._agent_dict[L3_CFG_HOST_A]['id']
    self._update('agents', id_cfg_agent_disabled, {
        'agent': {
            'admin_state_up': False,
        },
    })
    active_agents = self.plugin.get_cfg_agents(self.adminContext, active=True)
    self.assertEqual(1, len(active_agents))
    self.assertEqual(L3_CFG_HOST_B, active_agents[0].host)
    self._update('agents', id_cfg_agent_disabled, {
        'agent': {
            'admin_state_up': True,
        },
    })
    with mock.patch('networking_cisco.plugins.cisco.db.scheduler.cfg_agentschedulers_db.timeutils.is_older_than') as is_older_mock:
        is_older_mock.side_effect = [False, True]
        alive_agents = self.plugin.get_cfg_agents(self.adminContext, active=True)
        self.assertEqual(1, len(alive_agents))
        self.assertEqual(L3_CFG_HOST_A, alive_agents[0].host)

dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/tests/unit/cisco/device_manager/test_hosting_device_cfg_agent_scheduler.py HostingDeviceConfigAgentSchedulerTestCase.test_get_cfg_agents/original