'Tests that router can be removed from agent and add to a new agent.
1. Verify connectivity
2. Remove router from all l3-agents
3. Verify connectivity is down
4. Assign router to new l3-agent (or old one if no new agent is
available)
5. Verify connectivity'

@test.requires_ext(service='network', extension='l3_agent_scheduler')
@decorators.idempotent_id('2e788c46-fb3f-4ac9-8f82-0561555bea73')
@decorators.attr(type='slow')
@test.services('compute', 'network')
def test_router_rescheduling(self):

    list_hosts = self.os_admin.routers_client.list_l3_agents_hosting_router
    schedule_router = self.os_admin.network_agents_client.create_router_on_l3_agent
    unschedule_router = self.os_admin.network_agents_client.delete_router_from_l3_agent
    agent_list_alive = set((a['id'] for a in self.os_admin.network_agents_client.list_agents(agent_type='L3    agent')['agents'] if (a['alive'] is True)))
    self._setup_network_and_servers()
    admin = self.os_admin.routers_client.show_router(self.router['id'])
    if admin['router'].get('distributed', False):
        msg = 'Rescheduling    test    does    not    apply    to    distributed    routers.'
        raise self.skipException(msg)
    self.check_public_network_connectivity(should_connect=True)
    hosting_agents = set((a['id'] for a in list_hosts(self.router['id'])['agents']))
    no_migration = (agent_list_alive == hosting_agents)
    LOG.info('Router    will    be    assigned    to    {mig}    hosting    agent'.format(mig=('the    same' if no_migration else 'a    new')))
    for hosting_agent in hosting_agents:
        unschedule_router(hosting_agent, self.router['id'])
        self.assertNotIn(hosting_agent, [a['id'] for a in list_hosts(self.router['id'])['agents']], 'unscheduling    router    failed')
    self.check_public_network_connectivity(should_connect=False, msg='after    router    unscheduling')
    target_agent = list((hosting_agents if no_migration else (agent_list_alive - hosting_agents)))[0]
    schedule_router(target_agent, router_id=self.router['id'])
    self.assertEqual(target_agent, list_hosts(self.router['id'])['agents'][0]['id'], "Router    failed    to    reschedule.    Hosting    agent    doesn't    match    target    agent")
    self.check_public_network_connectivity(should_connect=True, msg='After    router    rescheduling')
