VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 5:47:02 PM (6 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168246
Message:

ValidationKit/tests/api/tdSnapshots1.py: Add a new test scenario to
tdSnapshots1.py which verifies that when IMachine::deleteSnapshot()
removes a nested online snapshot it also removes its corresponding saved
state file. Changeset r150959 introduced a regression which left the
saved state (.sav) files beind when deleting a nested live snapshot.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/api/tdSnapshots1.py

    r106061 r108803  
    5454from testdriver import base
    5555from testdriver import reporter
     56from testdriver import vbox
    5657from testdriver import vboxcon
    5758
    5859
    59 class SubTstDrvNestedSnapshots1(base.SubTestDriverBase):
     60class SubTstDrvNestedLiveSnapshots1(base.SubTestDriverBase):
    6061    """
    6162    Sub-test driver for nested snapshot testing.
    6263    """
    6364    def __init__(self, oTstDrv):
    64         base.SubTestDriverBase.__init__(self, oTstDrv, 'nested-snapshots', 'Nested Snapshot Testing');
    65         self.sVmName = 'tst-nested-snapshots';
     65        base.SubTestDriverBase.__init__(self, oTstDrv, 'nested-live-snapshots', 'Nested Live Snapshot Testing');
     66        self.sVmName = 'tst-nested-live-snapshots';
    6667        # Note that any VM can be used here as these tests simply involve taking
    6768        # online snapshots and restoring them.  This OL6 image was chosen based purely
     
    7879        Execute the sub-testcases.
    7980        """
    80         return  self.testRestoreNestedSnapshot() \
    81             and self.testDeleteSnapshots();
     81        return  self.testRestoreNestedLiveSnapshot() \
     82            and self.testDeleteNestedLiveSnapshot() \
     83            and self.testDeleteLiveSnapshots();
    8284
    8385    #
    8486    # Test execution helpers.
    8587    #
    86     def testRestoreNestedSnapshot(self):
     88    def testRestoreNestedLiveSnapshot(self):
    8789        """
    8890        The scenario being exercised here is referenced in xTracker 10252 Comment #9
    89         where the sequence of restoring a nested snapshot and then booting that restored
     91        where the sequence of restoring a nested live snapshot and then booting that restored
    9092        VM would accidentally delete that snapshot's saved state file during boot.  So
    9193        here we perform the following steps to exercise this functionality:
    92           + Take two online snapshots of the VM: 'alpha', and 'beta' (IMachine::takeSnapshot())
     94          + Take three online snapshots of the VM: 'alpha', 'beta' and 'gamma' (IMachine::takeSnapshot())
    9395          + Restore snapshot 'beta' (IMachine::restoreSnapshot())
    9496          + Boot and then poweroff the VM
    9597          + Verify snapshot 'beta' still exists (IMachine::findSnapshot())
    9698        """
    97         reporter.testStart('testRestoreNestedSnapshot');
     99        reporter.testStart('testRestoreNestedLiveSnapshot');
    98100        reporter.log('Verify saved state file exists after nested snapshot restore');
    99101
     
    117119        self.oTstDrv.addTask(oTxsSession);
    118120
    119         # Take two online snapshots.
    120         reporter.log('Taking two online snapshots of test VM: \'%s\'' % self.sVmName);
     121        # Take three online snapshots.
     122        reporter.log('Taking three online snapshots of test VM: \'%s\'' % self.sVmName);
    121123        fRc = oSession.takeSnapshot('alpha');
    122124        fRc = fRc and oSession.takeSnapshot('beta');
     125        fRc = fRc and oSession.takeSnapshot('gamma');
     126        if not fRc:
     127            return reporter.error('Failed to take online snapshot of test VM: \'%s\'' % self.sVmName);
    123128
    124129        # Shutdown the VM and cleanup.
     
    131136        oTxsSession = None;
    132137        if not fRc:
    133             return reporter.error('Failed to take snapshot of test VM: \'%s\'' % self.sVmName);
     138            return reporter.error('Failed to take online snapshot of test VM: \'%s\'' % self.sVmName);
    134139
    135140        oVM = self.oTstDrv.getVmByName(self.sVmName);
     
    180185            return reporter.testFailure('Failed to close session of test VM: \'%s\'' % self.sVmName);
    181186
    182         reporter.log('Verifying nested snapshot \'beta\' still exists.');
     187        reporter.log('Verifying nested online snapshot \'beta\' still exists.');
    183188        oVM = self.oTstDrv.getVmByName(self.sVmName);
    184189        oSession = self.oTstDrv.openSession(oVM);
     
    193198
    194199
    195     def testDeleteSnapshots(self):
     200    def testDeleteNestedLiveSnapshot(self):
     201        """
     202        The scenario being exercised here is to verify that removing a nested online
     203        snapshot also removes its corresponding saved state ('.sav') file.  A regression
     204        caused IMachine::deleteSnapshot() to remove a live snapshot from the VM's
     205        settings but left the '.sav' file behind.  So here we perform the following steps to
     206        exercise this functionality:
     207          + Delete live snapshot 'gamma' (IMachine::deleteSnapshot())
     208          + Check that the 'gamma' snapshot was removed
     209          + Verify that the 'gamma' snapshot's '.sav' file was removed as well
     210        """
     211
     212        reporter.testStart('testDeleteNestedLiveSnapshot');
     213        reporter.log('Verify IMachine::deleteSnapshot() deletes a nested live snapshot along with its .sav file');
     214        oVM = self.oTstDrv.getVmByName(self.sVmName);
     215        oSession = self.oTstDrv.openSession(oVM);
     216        if oSession is None:
     217            return reporter.error('Failed to create session for test VM: \'%s\'' % self.sVmName);
     218
     219        oSnapshot = oSession.findSnapshot('gamma');
     220        if oSnapshot is None:
     221            return reporter.testFailure('Failed to find snapshot \'gamma\' of test VM: \'%s\'' % self.sVmName);
     222
     223        # Save the path to gamma's '.sav' file while the snapshot still exists for querying later.
     224        strSaveFilePath = oSnapshot.machine.stateFilePath;
     225        reporter.log('Calling IMachine::deleteSnapshot() to delete snapshot \'gamma\'');
     226        # Call IMachine::deleteSnapshot() (or its historic equivalent) to remove the
     227        # live snapshot named 'gamma'
     228        fRc = oSession.deleteSnapshot(oSnapshot.id, cMsTimeout = 120 * 1000);
     229        if not fRc:
     230            return reporter.error('Failed to delete snapshot \'gamma\'');
     231
     232        # Verify that the snapshot was indeed removed as well as its corresponding saved
     233        # state file.
     234        reporter.log('Verifying snapshot \'gamma\' was deleted');
     235        try:
     236            oSnapshot = oSession.findSnapshot('gamma');
     237        except vbox.ComException as oXcpt:
     238            if vbox.ComError.notEqual(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
     239                return reporter.testFailure('Failed to delete snapshot \'gamma\' of test VM: \'%s\'' % self.sVmName);
     240
     241        reporter.log('Verifying that the \'gamma\' snapshot\'s \'.sav\' file was deleted');
     242        if os.path.exists(strSaveFilePath):
     243            return reporter.error('The saved state file of snapshot \'gamma\' was not deleted');
     244
     245        return reporter.testDone()[1] == 0;
     246
     247
     248    def testDeleteLiveSnapshots(self):
    196249        """
    197250        The scenario being exercised here is also referenced in xTracker 10252 Comment #9
    198         where unregistering and deleting a VM which contained one or more snapshots would
     251        where unregistering and deleting a VM which contained one or more live snapshots would
    199252        neglect to delete the snapshot(s).  So here we perform the following steps to
    200253        exercise this functionality which conveniently also tidies up our test setup:
     
    204257        """
    205258
    206         reporter.testStart('testDeleteSnapshots');
     259        reporter.testStart('testDeleteLiveSnapshots');
    207260        reporter.log('Verify IMachine::unregister()+IMachine::deleteConfig() deletes snapshots');
    208261        oVM = self.oTstDrv.getVmByName(self.sVmName);
     
    255308    sys.path.append(os.path.dirname(os.path.abspath(__file__)));
    256309    from tdApi1 import tdApi1;      # pylint: disable=relative-import
    257     sys.exit(tdApi1([SubTstDrvNestedSnapshots1]).main(sys.argv))
     310    sys.exit(tdApi1([SubTstDrvNestedLiveSnapshots1]).main(sys.argv))
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette