This is an automated email from the ASF dual-hosted git repository.

lfrolov pushed a commit to branch DLAB-1864
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit fdd657683fe8a0a81b963df9260b3925a89a8a37
Author: leonidfrolov <frolovl...@gmail.com>
AuthorDate: Wed Aug 26 16:09:55 2020 +0300

    [DLAB-1864]: added retries in case of failure during disk prepare
---
 .../src/general/lib/azure/actions_lib.py           | 36 ++++++++++++++++------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/infrastructure-provisioning/src/general/lib/azure/actions_lib.py 
b/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
index 4f2057a..34c65ce 100644
--- a/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
+++ b/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
@@ -1221,16 +1221,32 @@ def prepare_vm_for_image(creds=False, os_user='', 
hostname='', keyfile=''):
 def prepare_disk(os_user):
     if not exists('/home/' + os_user + '/.ensure_dir/disk_ensured'):
         try:
-            remount_azure_disk()
-            disk_name = sudo("lsblk | grep disk | awk '{print $1}' | sort | 
tail -n 1")
-            with settings(warn_only=True):
-                sudo('umount -l /dev/{}1'.format(disk_name))
-            sudo('''bash -c 'echo -e "o\nn\np\n1\n\n\nw" | fdisk /dev/{}' 
'''.format(disk_name))
-            sudo('mkfs.ext4 -F /dev/{}1'.format(disk_name))
-            sudo('mount /dev/{}1 /opt/'.format(disk_name))
-            sudo(''' bash -c "echo '/dev/{}1 /opt/ ext4 errors=remount-ro 0 1' 
>> /etc/fstab" '''.format(disk_name))
-            sudo('touch /home/' + os_user + '/.ensure_dir/disk_ensured')
-        except:
+            allow = False
+            counter = 0
+            while not allow:
+                if counter > 4:
+                    print("Unable to prepare disk")
+                    sys.exit(1)
+                else:
+                    remount_azure_disk()
+                    disk_name = sudo("lsblk | grep disk | awk '{print $1}' | 
sort | tail -n 1")
+                    with settings(warn_only=True):
+                        sudo('umount -l /dev/{}1'.format(disk_name))
+                    sudo('''bash -c 'echo -e "o\nn\np\n1\n\n\nw" | fdisk 
/dev/{}' 2>&1 | tee /tmp/tee.tmp '''.format(
+                        disk_name), warn_only=True)
+                    out = sudo('cat /tmp/tee.tmp')
+                    if 'Syncing disks' in out:
+                        allow = True
+                        sudo('mkfs.ext4 -F /dev/{}1'.format(disk_name))
+                        sudo('mount /dev/{}1 /opt/'.format(disk_name))
+                        sudo(''' bash -c "echo '/dev/{}1 /opt/ ext4 
errors=remount-ro 0 1' >> /etc/fstab" '''.format(
+                            disk_name))
+                        sudo('touch /home/' + os_user + 
'/.ensure_dir/disk_ensured')
+                    else:
+                        counter += 1
+                        time.sleep(5)
+        except Exception as err:
+            print('Error:', str(err))
             sys.exit(1)
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org
For additional commands, e-mail: commits-h...@dlab.apache.org

Reply via email to