Skip to content

Commit

Permalink
Update Windows EBS volume watcher behavior to return deviceName
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuchoe authored and mye956 committed Jun 3, 2024
1 parent 405b0ea commit 55a8199
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions ecs-agent/api/attachment/resource/ebs_discovery_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func (api *EBSDiscoveryClient) ConfirmEBSVolumeIsAttached(deviceName, volumeID s
return "", errors.Wrapf(err, "failed to run ebsnvme-id.exe: %s", string(output))
}

_, err = parseExecutableOutput(output, volumeID, deviceName)
actualDeviceName, err := parseExecutableOutput(output, volumeID)
if err != nil {
return "", errors.Wrapf(err, "failed to parse ebsnvme-id.exe output for volumeID: %s and deviceName: %s",
volumeID, deviceName)
}

log.Info(fmt.Sprintf("found volume with volumeID: %s and deviceName: %s", volumeID, deviceName))
log.Info(fmt.Sprintf("found volume with volumeID: %s and deviceName: %s", volumeID, actualDeviceName))

return "", nil
return actualDeviceName, nil
}

// parseExecutableOutput parses the output of `ebsnvme-id.exe` and returns the volumeId.
func parseExecutableOutput(output []byte, candidateVolumeId string, candidateDeviceName string) (string, error) {
// parseExecutableOutput parses the output of `ebsnvme-id.exe` and returns the deviceName.
func parseExecutableOutput(output []byte, candidateVolumeId string) (string, error) {
/* The output of the ebsnvme-id.exe is emitted like the following:
Disk Number: 0
Volume ID: vol-0a1234f340444abcd
Expand All @@ -76,12 +76,12 @@ func parseExecutableOutput(output []byte, candidateVolumeId string, candidateDev
for volumeIndex := 0; volumeIndex <= len(volumeInfo)-volumeInfoLength; volumeIndex = volumeIndex + volumeInfoLength {
_, volumeId, deviceName, err := parseSet(volumeInfo[volumeIndex : volumeIndex+volumeInfoLength])
if err != nil {
return "", errors.Wrapf(err, "failed to parse the output for volumeID: %s and deviceName: %s. "+
"Output:%s", candidateVolumeId, candidateDeviceName, out)
return "", errors.Wrapf(err, "failed to parse the output for volumeID: %s. "+
"Output:%s", candidateVolumeId, out)
}

if volumeId == candidateVolumeId && deviceName == candidateDeviceName {
return volumeId, nil
if volumeId == candidateVolumeId {
return deviceName, nil
}

}
Expand Down
28 changes: 8 additions & 20 deletions ecs-agent/api/attachment/resource/ebs_discovery_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestParseExecutableOutputWithHappyPath(t *testing.T) {
"Disk Number: 1\r\n"+
"Volume ID: %s\r\n"+
"Device Name: %s\r\n\r\n", testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.NoError(t, err)
assert.True(t, strings.Contains(parsedOutput, testVolumeID))
assert.True(t, strings.Contains(parsedOutput, deviceName))
}

func TestParseExecutableOutputWithMissingDiskNumber(t *testing.T) {
Expand All @@ -48,7 +48,7 @@ func TestParseExecutableOutputWithMissingDiskNumber(t *testing.T) {
"Device Name: sda1\r\n\r\n"+
"Volume ID: %s\r\n"+
"Device Name: %s\r\n\r\n", testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}
Expand All @@ -59,7 +59,7 @@ func TestParseExecutableOutputWithMissingVolumeInformation(t *testing.T) {
"Device Name: sda1\r\n\r\n"+
"Disk Number: 1\r\n"+
"Device Name: %s\r\n\r\n", deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}
Expand All @@ -70,7 +70,7 @@ func TestParseExecutableOutputWithMissingDeviceName(t *testing.T) {
"Device Name: sda1\r\n\r\n"+
"Disk Number: 1\r\n"+
"Volume ID: %s\r\n\r\n", testVolumeID)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}
Expand All @@ -82,19 +82,7 @@ func TestParseExecutableOutputWithVolumeNameMismatch(t *testing.T) {
"Disk Number: 1\r\n"+
"Volume ID: %s\r\n"+
"Device Name: %s\r\n\r\n", testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), "MismatchedVolumeName", deviceName)
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}

func TestParseExecutableOutputWithDeviceNameMismatch(t *testing.T) {
output := fmt.Sprintf("Disk Number: 0\r\n"+
"Volume ID: vol-abcdef1234567890a\r\n"+
"Device Name: sda1\r\n\r\n"+
"Disk Number: 1\r\n"+
"Volume ID: %s\r\n"+
"Device Name: %s\r\n\r\n", testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, "MismatchedDeviceName")
parsedOutput, err := parseExecutableOutput([]byte(output), "MismatchedVolumeName")
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}
Expand All @@ -105,14 +93,14 @@ func TestParseExecutableOutputWithTruncatedOutputBuffer(t *testing.T) {
"Device Name: sda1\r\n\r\n" +
"Disk Number: 1\r\n" +
"Volume ID: TruncatedBuffer..."
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.Error(t, err)
assert.Equal(t, "", parsedOutput)
}

func TestParseExecutableOutputWithUnexpectedOutput(t *testing.T) {
output := "No EBS NVMe disks found."
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID, deviceName)
parsedOutput, err := parseExecutableOutput([]byte(output), testVolumeID)
require.Error(t, err, "cannot find the volume ID: %s", output)
assert.Equal(t, "", parsedOutput)
}

0 comments on commit 55a8199

Please sign in to comment.