Merge "Handle a possible volume attachment visibility wait/race issue"
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index a6f2206..c7721b6 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -17,13 +17,15 @@
 
 import time
 
-from cinderclient import exceptions
+from cinderclient import exceptions as cinder_exceptions
 import testtools
 
 from tempest.common import log as logging
 from tempest.common.utils.data_utils import rand_name
 from tempest.common.utils.linux.remote_client import RemoteClient
+from tempest import exceptions
 from tempest.scenario import manager
+import tempest.test
 
 LOG = logging.getLogger(__name__)
 
@@ -110,7 +112,7 @@
         self.addCleanup(self.compute_client.security_group_rules.delete,
                         sg_rule.id)
 
-    def _ssh_to_server(self, server_or_ip):
+    def _remote_client_to_server(self, server_or_ip):
         if isinstance(server_or_ip, basestring):
             ip = server_or_ip
         else:
@@ -120,7 +122,10 @@
         linux_client = RemoteClient(ip,
                                     username,
                                     pkey=self.keypair.private_key)
+        return linux_client
 
+    def _ssh_to_server(self, server_or_ip):
+        linux_client = self._remote_client_to_server(server_or_ip)
         return linux_client.ssh_client
 
     def _create_image(self, server):
@@ -145,7 +150,7 @@
             try:
                 while volume_snapshots.get(snapshot.id):
                     time.sleep(1)
-            except exceptions.NotFound:
+            except cinder_exceptions.NotFound:
                 pass
         self.addCleanup(cleaner)
         self._wait_for_volume_status(volume, 'available')
@@ -186,6 +191,20 @@
         detach_volume_client(server.id, volume.id)
         self._wait_for_volume_status(volume, 'available')
 
+    def _wait_for_volume_availible_on_the_system(self, server_or_ip):
+        ssh = self._remote_client_to_server(server_or_ip)
+        conf = self.config
+
+        def _func():
+            part = ssh.get_partitions()
+            LOG.debug("Partitions:%s" % part)
+            return 'vdb' in part
+
+        if not tempest.test.call_until_true(_func,
+                                            conf.compute.build_timeout,
+                                            conf.compute.build_interval):
+            raise exceptions.TimeoutException
+
     def _create_timestamp(self, server_or_ip):
         ssh_client = self._ssh_to_server(server_or_ip)
         ssh_client.exec_command('sudo /usr/sbin/mkfs.ext4 /dev/vdb')
@@ -219,6 +238,7 @@
             ip_for_server = server
 
         self._attach_volume(server, volume)
+        self._wait_for_volume_availible_on_the_system(ip_for_server)
         self._create_timestamp(ip_for_server)
         self._detach_volume(server, volume)
 
@@ -246,6 +266,7 @@
 
         # attach volume2 to instance2
         self._attach_volume(server_from_snapshot, volume_from_snapshot)
+        self._wait_for_volume_availible_on_the_system(ip_for_snapshot)
 
         # check the existence of the timestamp file in the volume2
         self._check_timestamp(ip_for_snapshot)