From 56f0ea68a678ce7990ea616d31464da50d0a3e37 Mon Sep 17 00:00:00 2001 From: brianherrera Date: Wed, 13 Oct 2021 10:29:53 -0700 Subject: [PATCH] Add step to verify disk is in an offline state Some Windows configs will automatically set new drives as online causing diskpart setup script to fail. Signed-off-by: brianherrera --- .../build/bootstrap/incremental_build_util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/build/bootstrap/incremental_build_util.py b/scripts/build/bootstrap/incremental_build_util.py index 5c77559085..a33eb2af80 100644 --- a/scripts/build/bootstrap/incremental_build_util.py +++ b/scripts/build/bootstrap/incremental_build_util.py @@ -252,6 +252,18 @@ def find_snapshot_id(ec2_client, snapshot_hint, repository_name, project, pipeli snapshot_id = snapshot['SnapshotId'] return snapshot_id + +def offline_drive(disk_number=1): + """Use diskpart to offline a Windows drive""" + with tempfile.NamedTemporaryFile(delete=False) as f: + f.write(f""" + select disk {disk_number} + offline disk + """.encode('utf-8')) + subprocess.run(['diskpart', '/s', f.name]) + os.unlink(f.name) + + def create_volume(ec2_client, availability_zone, snapshot_hint, repository_name, project, pipeline, branch, platform, build_type, disk_size, disk_type): # The actual EBS default calculation for IOps is a floating point number, the closest approxmiation is 4x of the disk size for simplicity mount_name = get_mount_name(repository_name, project, pipeline, branch, platform, build_type) @@ -310,6 +322,10 @@ def create_volume(ec2_client, availability_zone, snapshot_hint, repository_name, def mount_volume_to_device(created): print('Mounting volume...') if os.name == 'nt': + # Verify drive is in an offline state. + # Some Windows configs will automatically set new drives as online causing diskpart setup script to fail. + offline_drive() + f = tempfile.NamedTemporaryFile(delete=False) f.write(""" select disk 1