From 1967a3e49cf471519c37090b2fb9b89cf0863b97 Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Thu, 20 Aug 2020 13:44:43 +1200 Subject: [PATCH] Fix fatal error when instance had NVMe instance-store volumes attached --- lib/aws-tools.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/aws-tools.js b/lib/aws-tools.js index bb74638..a9edb11 100644 --- a/lib/aws-tools.js +++ b/lib/aws-tools.js @@ -29,14 +29,15 @@ function getSupportedNVMeTool() { } /** - * + * Filter the list of block devices to only those that belong to the given EBS volume. + * * @param {EC2.Volume} volume * @param {BlockDevice[]} blockDevices * * @returns {Promise} */ function identifyNVMePartitionsForAttachedVolume(volume, blockDevices) { - let + const nvmeTool = getSupportedNVMeTool(); return Promise.all( @@ -47,14 +48,18 @@ function identifyNVMePartitionsForAttachedVolume(volume, blockDevices) { case "ebsnvme-id": child_process.execFile("ebsnvme-id", ["--volume", device.DEVICEPATH], function (error, stdout, stderr) { if (error) { - reject("Failed to ebsnvme-id " + stdout + " " + stderr); + if (stderr.match(/Not an EBS device/)) { + resolve(null); // This is an instance-store volume + } else { + reject("Failed to ebsnvme-id " + stdout + " " + stderr); + } } else { let matches = stdout.match(/vol-[0-9a-zA-Z]+/); if (!matches) { reject("Failed to parse output of ebsnvme-id: " + stdout); - } if (matches[0] === volume.VolumeId) { + } else if (matches[0] === volume.VolumeId) { resolve(device); } else { resolve(null); @@ -67,13 +72,15 @@ function identifyNVMePartitionsForAttachedVolume(volume, blockDevices) { child_process.execFile("nvme", ["id-ctrl", device.DEVICEPATH], function (error, stdout, stderr) { if (error) { reject("Failed to nvme " + stdout + " " + stderr); + } else if (stdout.match(/Amazon EC2 NVMe Instance Storage/)) { + resolve(null); } else { let matches = stdout.match(/vol([0-9a-zA-Z]+)/); if (!matches) { - reject("Failed to parse output of ebsnvme-id: " + stdout); - } if ("vol-" + matches[1] === volume.VolumeId) { + reject("Failed to parse output of nvme: " + stdout); + } else if ("vol-" + matches[1] === volume.VolumeId) { resolve(device); } else { resolve(null);