'Test dvr router lifecycle
:param enable_ha: sets the ha value for the router.
:param enable_snat:  the value of enable_snat is used
to  set the  agent_mode.'

def _dvr_router_lifecycle(self, enable_ha=False, enable_snat=False, custom_mtu=2000, ip_version=4, dual_stack=False):

    self.agent.conf.agent_mode = ('dvr_snat' if enable_snat else 'dvr')
    router_info = self.generate_dvr_router_info(enable_ha, enable_snat, extra_routes=True)
    for key in ('_interfaces', '_snat_router_interfaces', '_floatingip_agent_interfaces'):
        for port in router_info[key]:
            port['mtu'] = custom_mtu
    router_info['gw_port']['mtu'] = custom_mtu
    if enable_ha:
        router_info['_ha_interface']['mtu'] = custom_mtu
    fip_agent_gw_port = self._get_fip_agent_gw_port_for_router(router_info['gw_port'])
    self.mock_plugin_api.get_agent_gateway_port.return_value = fip_agent_gw_port
    self.mock_plugin_api.get_external_network_id.return_value = router_info['_floatingips'][0]['floating_network_id']
    router = self.manage_router(self.agent, router_info)
    if enable_ha:
        port = router.get_ex_gw_port()
        interface_name = router.get_external_device_name(port['id'])
        self._assert_no_ip_addresses_on_interface(router.ha_namespace, interface_name)
        utils.wait_until_true((lambda : (router.ha_state == 'master')))
        device = router.router[lib_constants.INTERFACE_KEY][(-1)]
        device_exists = functools.partial(self.device_exists_with_ips_and_mac, device, router.get_internal_device_name, router.ns_name)
        utils.wait_until_true(device_exists)
        name = router.get_internal_device_name(device['id'])
        self.assertEqual(custom_mtu, ip_lib.IPDevice(name, router.ns_name).link.mtu)
    ext_gateway_port = router_info['gw_port']
    self.assertTrue(self._namespace_exists(router.ns_name))
    utils.wait_until_true((lambda : self._metadata_proxy_exists(self.agent.conf, router)))
    self._assert_internal_devices(router)
    self._assert_dvr_external_device(router)
    self._assert_dvr_gateway(router)
    self._assert_dvr_floating_ips(router)
    self._assert_snat_chains(router)
    self._assert_floating_ip_chains(router)
    self._assert_metadata_chains(router)
    self._assert_rfp_fpr_mtu(router, custom_mtu)
    if enable_snat:
        ip_versions = ([4, 6] if ((ip_version == 6) or dual_stack) else [4])
        snat_ns_name = dvr_snat_ns.SnatNamespace.get_snat_ns_name(router.router_id)
        self._assert_onlink_subnet_routes(router, ip_versions, snat_ns_name)
        self._assert_extra_routes(router, namespace=snat_ns_name)
    self._delete_router(self.agent, router.router_id)
    self._assert_fip_namespace_deleted(ext_gateway_port)
    self._assert_router_does_not_exist(router)
    self._assert_snat_namespace_does_not_exist(router)
