'Helper to test external gw update for edge router on dvr_snat agent
:param host_match: True if new gw host should be the same as agent host
:param snat_hosted_before: True if agent has already been hosting
snat for the router'

def _test_ext_gw_updated_dvr_edge_router(self, host_match, snat_hosted_before=True):

    router = l3_test_common.prepare_router_data(num_internal_ports=2)
    self._set_ri_kwargs(mock.Mock(), router['id'], router)
    ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
    if snat_hosted_before:
        ri._create_snat_namespace()
        snat_ns_name = ri.snat_namespace.name
    (interface_name, ex_gw_port) = l3_test_common.prepare_ext_gw_test(self, ri)
    ri._external_gateway_added = mock.Mock()
    router['gw_port_host'] = (ri.host if host_match else (ri.host + 'foo'))
    ri.external_gateway_updated(ex_gw_port, interface_name)
    if (not host_match):
        self.assertFalse(ri._external_gateway_added.called)
        if snat_hosted_before:
            self.mock_driver.unplug.assert_called_with(interface_name, bridge=self.conf.external_network_bridge, namespace=snat_ns_name, prefix=namespaces.EXTERNAL_DEV_PREFIX)
    else:
        if (not snat_hosted_before):
            self.assertIsNotNone(ri.snat_namespace)
        self.assertTrue(ri._external_gateway_added.called)
