Wait for disk when attaching volumes

It might take some time to discover new device in guest OS.
This patch adds waiter for device after we attached volume.

Change-Id: I1d35f6ed94fcd152a63f61ef6e073bc7fff40daa
Related-Prod: PROD-21942
diff --git a/barbican_tempest_plugin/tests/scenario/test_volume_encryption.py b/barbican_tempest_plugin/tests/scenario/test_volume_encryption.py
index 95ba5d5..51491d4 100644
--- a/barbican_tempest_plugin/tests/scenario/test_volume_encryption.py
+++ b/barbican_tempest_plugin/tests/scenario/test_volume_encryption.py
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import time
+
 from oslo_log import log as logging
 from tempest.common import utils
 from tempest import config
 from tempest.lib import decorators
+from tempest.lib import exceptions as lib_exc
 
 from barbican_tempest_plugin.tests.scenario import barbican_manager
 
@@ -54,12 +57,28 @@
                                     control_location='front-end')
         return self.create_volume(volume_type=volume_type['name'])
 
+    def wait_for_disk(self, server_ip, keypair, device_name, wait_interval=1,
+                      wait_timeout=15):
+        start = int(time.time())
+        ssh_client = self.get_remote_client(
+            server_ip, private_key=keypair['private_key'])
+        disks = ssh_client.get_disks()
+        while True:
+            time.sleep(wait_interval)
+            if device_name in disks:
+                return
+            if int(time.time()) - start >= wait_timeout:
+                message = 'Device %s was not found in %d sec' % wait_timeout
+                raise lib_exc.TimeoutException(message)
+
     def attach_detach_volume(self, server, volume, keypair):
         # Attach volume
         attached_volume = self.nova_volume_attach(server, volume)
 
         # Write a timestamp to volume
         server_ip = self.get_server_ip(server)
+        self.wait_for_disk(server_ip, keypair,
+                           CONF.compute.volume_device_name)
         timestamp = self.create_timestamp(
             server_ip,
             dev_name=CONF.compute.volume_device_name,