[TF] Add timeout before check gateway port.

Workaround for PRODX-8489
Related-PROD: PRODX-8489

Change-Id: Ib44a2c9cef582015be4edcaf1041773ad9572d4d
(cherry picked from commit c3bd944ef64af5d66233b7bcb0983377844d24b0)
diff --git a/tempest/api/network/admin/test_routers.py b/tempest/api/network/admin/test_routers.py
index 90e0917..5c32ea4 100644
--- a/tempest/api/network/admin/test_routers.py
+++ b/tempest/api/network/admin/test_routers.py
@@ -12,6 +12,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
+import time
 
 import testtools
 
@@ -22,6 +23,7 @@
 from tempest.lib.common.utils import data_utils
 from tempest.lib.common.utils import test_utils
 from tempest.lib import decorators
+from tempest.lib import exceptions as lib_exc
 
 CONF = config.CONF
 
@@ -115,7 +117,30 @@
         for k, v in exp_ext_gw_info.items():
             self.assertEqual(v, actual_ext_gw_info[k])
 
+    def _wait_for_ports(self, router_id, timeout=30):
+        start = int(time.time())
+        list_body = self.admin_ports_client.list_ports(
+            network_id=CONF.network.public_network_id,
+            device_id=router_id,
+            device_owner="network:router_gateway")
+
+        while not len(list_body['ports']):
+            time.sleep(5)
+            list_body = self.admin_ports_client.list_ports(
+                network_id=CONF.network.public_network_id,
+                device_id=router_id,
+                device_owner="network:router_gateway")
+            timed_out = int(time.time()) - start >= timeout
+            if not len(list_body['ports']) and timed_out:
+                message = ('Router %s failed to attach ports within '
+                           'the required time (%s s).' %
+                           (router_id, timeout))
+                raise lib_exc.TimeoutException(message)
+
     def _verify_gateway_port(self, router_id):
+        # Workaround for PRODX-8489
+        if CONF.get('sdn').get('service_name') == "tungstenfabric":
+            self._wait_for_ports(router_id)
         list_body = self.admin_ports_client.list_ports(
             network_id=CONF.network.public_network_id,
             device_id=router_id,