Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1507,13 +1507,13 @@ public void destroyPatchVbd(final Connection conn, final Set<VM> vms) throws Xml
final VDI patchVDI = findPatchIsoVDI(conn, sr);
for (final VM vm : vms) {
final String vmName = vm.getNameLabel(conn);
try {
if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
return;
}
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
if (Types.VbdType.CD.equals(vbd.getType(conn))) {
if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify the validation, we could use StringUtils.startsWithAny, from commons.lang3:

if (!StringUtils.startsWithAny(vmName, "r-", "s-", v-")) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hesitate to make any further changes at this point. Feel free to raise a PR.

continue;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shwstppr this was the fix :( cc @vladimirpetrov @borisstoyanov

}
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
if (Types.VbdType.CD.equals(vbd.getType(conn))) {
try {
if (!vbd.getEmpty(conn)) {
vbd.eject(conn);
}
Expand All @@ -1522,12 +1522,16 @@ public void destroyPatchVbd(final Connection conn, final Set<VM> vms) throws Xml
vbd.insert(conn, patchVDI);
vbd.eject(conn);
}
} catch (Exception e) {
s_logger.debug("Cannot eject CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an exception be logged in debug?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignorable errors, not logged to avoid confusion for admin/user. 99.99% we'll never hit that.

}
try {
vbd.destroy(conn);
break;
} catch (Exception e) {
s_logger.debug("Cannot destroy CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignorable errors, not logged to avoid confusion for admin/user. 99.99% we'll never hit that.

}
break;
}
} catch (final Exception e) {
s_logger.debug("Cannot destroy CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
}
}
}
Expand Down