Using Snapshots to Store, Reproduce, and Share the State of Virtual Environments
Note
This topic describes how to create and use Lab Management environment snapshots by using the Lab tab in the Microsoft Test Manager Lab Center. You can also create snapshots when you run manual tests in the Test Manager Testing Center. For more information, see Testing Using Virtual Environments.
A snapshot of an environment is a file-based copy of the state, disk data, and configuration of all virtual machines in an environment at a specific point in time. After you take a snapshot, you can continue to work in the environment, taking more snapshots as needed. You can then restore the environment to a previous state. You can also create a link file to a snapshot that enables other members of your team to connect to or re-create the snapshot. You can also save a copy of the environment and its snapshots to the team project library. When you save an environment to the team project library, both the environment and the snapshots are saved in the team project library.
This topic contains the following sections:
Creating Snapshots of an Environment
Restoring an Environment From a Snapshot
Sharing a Snapshot of an Environment
Storing an Environment With Snapshots in the Library
Deleting a Snapshot of an Environment
Creating Snapshots of an Environment
Snapshots are stored on the Hyper-V hosts of the team project. If a snapshot is frequently used a long time after it was created, you must take steps to make the environment usable for long periods of time.
To prepare for a snapshot
Make sure that the virtual machines in the environment have the latest updates for their operating systems.
If any virtual machine in the environment is connected to a domain, open a command prompt and run the command gpupdate /force. This command makes sure that any changes to user policies are updated on the virtual machine. If you do not run this command, your deployment scripts might not work correctly or your tests might not run correctly.
Note
If one or more of the virtual machines in this snapshot are joined to a domain and the snapshot is used for longer than the machine password expiry period, the virtual machines might be unable to join the domain again when the snapshot is restored. One way to avoid this problem is to disable or change the machine password renewal frequency. For more information about password renewal and the security implications for changing or disabling the renewal, see Machine Account Password Process.
Make sure that the state of the environment is Running.
If you have enabled workflows, make sure that the state of the workflow capability is Ready and that the environment is Running.
(Optional) If you want to run tests on the restored snapshot, make sure that the testing capability is Ready.
Note
You should take snapshots only when there are no transactions in progress between the virtual machines within the environment or between the virtual machines inside the environment and machines outside the environment. If there are TCP connections between machines at the time that the snapshot is taken, these connections might break when the machines are stopped to take the snapshot. When the snapshot is restored, the old, active connections will have timed out and will no longer be valid. After the snapshot is restored, the TCP connections are reestablished. You cannot always resume the environment exactly from the point the snapshot is taken.
If the build definition for your workflow reverts to a specific snapshot, the virtual machine cannot be locked when you try to run the tests. You must connect to the machine by using a host based connection or by using a console session before you take the snapshot to use for your workflow. For more information about this, see How to: Connect to a Virtual Environment.
You use the Lab Management Environment Viewer to connect to the environment and take the snapshot.
To create a snapshot
In Microsoft Test Manager, connect to the environment. In the Lab Center, on the Lab tab, select the environment, and then click Connect.
In Microsoft Environment Viewer, click the Snapshots tab.
Click Take snapshot.
In the Snapshot environment dialog box, type a name for the snapshot, and then click Take snapshot.
After the snapshot is completed, you can see the snapshot name in the left pane.
Restoring an Environment From a Snapshot
When you restore a virtual environment from a snapshot, you return the virtual machines in the environment to the exact states that they were in at the time that the snapshot was taken. You can restore an environment to a snapshot that was created before or after the current state of the environment. For example, you can take two snapshots of an environment, one on Monday and one on Tuesday. On Wednesday, you might restore the environment to the snapshot from Monday. Later, you might restore the same environment to the snapshot from Tuesday.
To restore a virtual environment to a snapshot
In Microsoft Test Manager, open the Lab Center, an then click the Lab tab.
Click the environment, and then click Connect.
In Microsoft Environment Viewer, click the Snapshots tab.
In the list of snapshots, select the snapshot that you want to restore, and then click Restore to selected snapshot on the Snapshot toolbar.
If it is necessary, click the Machines tab, select any disconnected machines, and then click Reconnect.
Sharing a Snapshot of an Environment
You can create a link to a snapshot of an environment that you can share with other people. The link (.lvr) file can be opened on any computer on which Microsoft Test Manager is installed by any user who has permissions to operate an environment in the team project.
To create a link to a virtual environment snapshot
In Microsoft Test Manager, in the Lab Center, on the Lab tab, make sure that the environment is Running.
Click the environment, and then click Connect.
In Microsoft Environment Viewer, click the Snapshots tab.
In the list of snapshots, select the snapshot that you want to link to, and then click Share snapshot on the Snapshot toolbar.
Specify a file name for the link (.lvr) file.
You can attach the link file to an e-mail, or place it on a shared directory.
To connect to a snapshot from a snapshot link file
Double-click the snapshot link (.lvr) file.
The Connect to environment dialog box is displayed. Select one of the following options:
Connect to the snapshot in this environment
Restores the exact state of the virtual environment at which the snapshot was taken.
NoteIf you select this option, you might disconnect any user who is currently using this environment and this could lead to loss of their work. A warning message is displayed if the environment is in use.Connect to the environment in its current state
Connects to the environment in its current state and does not revert to the snapshot that was selected when the link file was created.
NoteYou might still disconnect another user who is connected to this environment. However, you will not change the state of the environment.Connect to a new instance of this environment
Available only if a copy of the environment in stored the team project library. Creates a copy of the environment on a team project host group and connects to that copy.
You might want to create a copy if the environment is currently in use, or if you do not want to prevent other people from using the environment.
NoteCreating a copy can take a long time and can also use significant disk space on the team project library. If multiple copies of the environment are to be run at the same time, the original environment must use network isolation. For more information, see How to: Create and Use a Network Isolated Environment.Click Connect to open the environment in Environment Viewer.
Note
When you restore an environment to a snapshot, the network connections between the machines in the snapshot might stop working for a brief amount of time and any transactions that were in process at the time that the snapshot was taken might fail.
Storing an Environment with Snapshots in the Library
Before you can store an environment, the environment must be in the Stopped state. You cannot store an environment that is in the Running state.
If you store an environment and do not plan to delete the original active environment immediately, we recommend that you turn on the network isolation capability of the stored environment. This lets another user to deploy a copy of the stored environment. For the steps to turn on the network isolation capability, see How to: Create and Use a Network Isolated Environment.
To store the environment in the Library
In Microsoft Test Manager, in the Lab Center, on the Lab tab, make sure that the environment is Stopped.
Click the environment that you want to save.
Click Store in library.
In the Store in library dialog box, type the Environment name and Description of the saved environment.
Select the Project library share from the drop-down list, and then click Store.
A progress bar is displayed during the creation process. You can also view the current creation step for each virtual machine. When the process is finished, the stored environment appears in the list of Environments on the Library tab.
Deleting a Snapshot From an Environment
It is easy to accumulate snapshots of an environment. Storing a snapshot requires a significant amount space on the host group. A best practice occasionally reviews the list of snapshots to determine whether there are any that are no longer needed and can be deleted.
To delete a snapshot
In Microsoft Test Manager, in the Lab Center, on the Lab tab, make sure that the environment is started.
Click the virtual environment, and then click Connect.
In Microsoft Environment Viewer, click the Snapshots tab.
Select the snapshot to delete, and then click Delete snapshot.
In the confirmation dialog box, click Delete snapshot.
See Also
Concepts
How to: Run Manual Tests and Create Reproducible Bugs With Virtual Environments