Wait until all router ports are DOWN before migration

In router migration tests, before migration is started, router
is set to admin_state_up=False. This cause that status of all
router ports should be set to DOWN.
This patch adds check (and wait) that all ports are really set
to DOWN state before migration of router is started.

Change-Id: I72ce0d4480c6d26e8ce1c8193e7ec18585df1c06
Related-Bug: #1785582
diff --git a/neutron_tempest_plugin/scenario/test_migration.py b/neutron_tempest_plugin/scenario/test_migration.py
index 5e081f1..f4b918c 100644
--- a/neutron_tempest_plugin/scenario/test_migration.py
+++ b/neutron_tempest_plugin/scenario/test_migration.py
@@ -67,6 +67,19 @@
                 device_owner),
             timeout=300, sleep=5)
 
+    def _wait_until_router_ports_down(self, router_id):
+
+        def _is_port_down(port_id):
+            port = self.os_admin.network_client.show_port(port_id).get('port')
+            return port['status'] == const.DOWN
+
+        ports = self.os_admin.network_client.list_ports(
+            device_id=router_id).get('ports')
+        for port in ports:
+            common_utils.wait_until_true(
+                functools.partial(_is_port_down, port['id']),
+                timeout=300, sleep=5)
+
     def _is_port_active(self, router_id, device_owner):
         ports = self.os_admin.network_client.list_ports(
             device_id=router_id,
@@ -120,6 +133,8 @@
 
         self.os_admin.network_client.update_router(
             router_id=router['id'], admin_state_up=False)
+        self._wait_until_router_ports_down(router['id'])
+
         self.os_admin.network_client.update_router(
             router_id=router['id'], distributed=after_dvr, ha=after_ha)
         self._check_update(router, after_dvr, after_ha)