Skip to content

Commit 8dcbdae

Browse files
authored
Improve Cuttlefish boot reliability with stable build fallback (#4714)
This commit modifies the `flash_to_latest_build_if_needed` function to include a fallback mechanism for booting Cuttlefish. If the device fails to boot using the tip-of-the-tree build, the system will now attempt to boot using a stable build retrieved from GCS. #3950
1 parent fdfd4c1 commit 8dcbdae

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/clusterfuzz/_internal/platforms/android/fetch_artifact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ def get_stable_build_info():
201201
return stable_build_info
202202

203203

204-
def get_latest_artifact_info(branch, target, signed=False):
204+
def get_latest_artifact_info(branch, target, signed=False, stable_build=False):
205205
"""Return latest artifact for a branch and target."""
206206
client = get_client()
207207
if not client:
208208
return None
209209

210210
# TODO(https://github.com/google/clusterfuzz/issues/3950)
211211
# After stabilizing the Cuttlefish image, revert this
212-
if environment.is_android_cuttlefish():
212+
if environment.is_android_cuttlefish() and stable_build:
213213
build_info = get_stable_build_info()
214214
# Use tip-of-tree build if 'bid' is missing or 0.
215215
# Setting 'bid' to 0 in stable_build_info.json

src/clusterfuzz/_internal/platforms/android/flash.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ def download_latest_build(build_info, image_regexes, image_directory):
9191
reader.extract_all(image_directory)
9292

9393

94+
def boot_stable_build_cuttlefish(branch, target, image_directory):
95+
"""Boot cuttlefish instance using stable build id fetched from gcs."""
96+
build_info = fetch_artifact.get_latest_artifact_info(
97+
branch, target, stable_build=True)
98+
download_latest_build(build_info, FLASH_CUTTLEFISH_REGEXES, image_directory)
99+
adb.recreate_cuttlefish_device()
100+
adb.connect_to_cuttlefish_device()
101+
102+
94103
def flash_to_latest_build_if_needed():
95104
"""Wipes user data, resetting the device to original factory state."""
96105
if environment.get_value('LOCAL_DEVELOPMENT'):
@@ -207,12 +216,19 @@ def flash_to_latest_build_if_needed():
207216
locks.release_lock(flash_lock_key_name, by_zone=True)
208217

209218
if adb.get_device_state() != 'device':
210-
monitoring_metrics.CF_TIP_BOOT_FAILED_COUNT.increment({
211-
'build_id': build_info['bid'],
212-
'is_succeeded': False
213-
})
214-
logs.error('Unable to find device. Reimaging failed.')
215-
adb.bad_state_reached()
219+
if environment.is_android_cuttlefish():
220+
logs.info('Trying to boot cuttlefish instance using stable build.')
221+
monitoring_metrics.CF_TIP_BOOT_FAILED_COUNT.increment({
222+
'build_id': build_info['bid'],
223+
'is_succeeded': False
224+
})
225+
boot_stable_build_cuttlefish(branch, target, image_directory)
226+
if adb.get_device_state() != 'device':
227+
logs.error('Unable to find device. Reimaging failed.')
228+
adb.bad_state_reached()
229+
else:
230+
logs.error('Unable to find device. Reimaging failed.')
231+
adb.bad_state_reached()
216232

217233
monitoring_metrics.CF_TIP_BOOT_FAILED_COUNT.increment({
218234
'build_id': build_info['bid'],

0 commit comments

Comments
 (0)