Skip to content

Commit

Permalink
Fix fatal error when instance had NVMe instance-store volumes attached
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed Aug 20, 2020
1 parent f9e38bc commit 1967a3e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/aws-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockDevice[]>}
*/
function identifyNVMePartitionsForAttachedVolume(volume, blockDevices) {
let
const
nvmeTool = getSupportedNVMeTool();

return Promise.all(
Expand 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);
Expand All @@ -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);
Expand Down

0 comments on commit 1967a3e

Please sign in to comment.