Add waiter for secret_key in orders api tests

The secret creation process is asynchronous and secret_ref
is not present in order when created. The patch adds waiter for this
filed with predefined timeouts.

Related-Prod: PRODX-12928
Change-Id: I5f2369c49e4a19d0d00803f0396241b3056f0c67
diff --git a/barbican_tempest_plugin/tests/api/test_orders.py b/barbican_tempest_plugin/tests/api/test_orders.py
index de8791b..f3d5f84 100644
--- a/barbican_tempest_plugin/tests/api/test_orders.py
+++ b/barbican_tempest_plugin/tests/api/test_orders.py
@@ -12,7 +12,10 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import time
+
 from tempest.lib import decorators
+from tempest.lib import exceptions as lib_exc
 
 from barbican_tempest_plugin.tests.api import base
 
@@ -20,6 +23,23 @@
 class OrdersTest(base.BaseKeyManagerTest):
     """Orders API tests."""
 
+    def _wait_for_orders_secret_ref(self):
+        """Waits for order key."""
+        start = int(time.time())
+        secret_ref_timeout = 15
+        while True:
+            body = self.order_client.list_orders()
+            orders = body.get('orders')
+            secret_ref_res = ['secret_ref' in order.keys() for order in orders]
+            timed_out = int(time.time()) - start >= secret_ref_timeout
+            if timed_out:
+                message = ('The secret_ref is not seen in order keys '
+                           'withing required time %s' % secret_ref_timeout)
+                raise lib_exc.TimeoutException(message)
+            elif all(secret_ref_res):
+                break
+            time.sleep(3)
+
     @decorators.idempotent_id('077c1729-1950-4e62-a29c-daba4aa186ad')
     def test_create_list_delete_orders(self):
         # Confirm that there are no orders
@@ -57,6 +77,7 @@
         self.assertEqual(2, len(body.get('orders')), body)
 
         orders = body.get('orders')
+        self._wait_for_orders_secret_ref()
         for order in orders:
             self.assertIn(
                 base._get_uuid(order.get('order_ref')),