mirror of https://github.com/apache/cloudstack.git
secondary-storage: delete backedup snapshot dir on delete (#7524)
* secondary-storage: delete backedup snapshot dir on delete Fixes #7516 When a backed-up snapshot is deleted and the snapshot file is present in the same name directory (probably only for VMware), the whole directory can be deleted. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * refactor Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * resolve comment Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
7319debc87
commit
0941d01e97
|
|
@ -1997,6 +1997,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
}
|
||||
}
|
||||
|
||||
protected String getSnapshotFilepathForDelete(String path, String snapshotName) {
|
||||
if (!path.endsWith(snapshotName)) {
|
||||
return path + "/*" + snapshotName + "*";
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(String.format("Snapshot file %s is present in the same name directory %s. Deleting the directory", snapshotName, path));
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
protected Answer deleteSnapshot(final DeleteCommand cmd) {
|
||||
DataTO obj = cmd.getData();
|
||||
DataStoreTO dstore = obj.getDataStore();
|
||||
|
|
@ -2033,7 +2043,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
return new Answer(cmd, true, details);
|
||||
}
|
||||
// delete snapshot in the directory if exists
|
||||
String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
|
||||
String lPath = getSnapshotFilepathForDelete(absoluteSnapshotPath, snapshotName);
|
||||
String result = deleteLocalFile(lPath);
|
||||
if (result != null) {
|
||||
details = "failed to delete snapshot " + lPath + " , err=" + result;
|
||||
|
|
|
|||
|
|
@ -91,4 +91,21 @@ public class NfsSecondaryStorageResourceTest {
|
|||
testLogAppender.assertMessagesLogged();
|
||||
|
||||
}
|
||||
|
||||
private void performGetSnapshotFilepathForDeleteTest(String expected, String path, String name) {
|
||||
Assert.assertEquals("Incorrect resultant snapshot delete path", expected, resource.getSnapshotFilepathForDelete(path, name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSnapshotFilepathForDelete() {
|
||||
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/somename",
|
||||
"/snapshots/2/10/somename",
|
||||
"somename");
|
||||
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/diffName/*diffname*",
|
||||
"/snapshots/2/10/diffName",
|
||||
"diffname");
|
||||
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/*somename*",
|
||||
"/snapshots/2/10",
|
||||
"somename");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue