Jaa


Creating and Working with Virtual Environments

Today as we build more and more complex applications the complexity of development and testing environments have increased significantly. Development and testing of complex N tier application on single machine results in late discovery of bugs in pre-production or worse in production environments. Ideally we would like to develop and test applications in an environment which is as close to production as possible (due to cost and other infrastructure limitations we may never get identical). Unfortunately today setting up these N tier environments on physical machines is a time consuming and error prone process and keeps dev/tests focus away from their core activities. This results in not only loss of productivity but also impact product quality.

VSTS Lab Management supports creation of virtual environment in minutes as oppose to days. This allows development and test teams to develop and test code against production like environments without spending days in setup which results in improved productivity and quality. As setting up these environments is so easy, it encourages sharing of hardware resources across the team and self service as oppose to dependence on a IT Administrators. With sharing and self service your total cost of ownership of running labs reduces significantly. In this post we’ll cover how to create and work with virtual environments.

A virtual environment is defined as a collection of virtual machines (VM). e.g. a typical 3 tier application environment will have 3 virtual machines namely client , web server and database server. In order to create this environment you first need the individual virtual machines which can play different roles as mentioned above namely client, web server etc.

Since majority of applications will have similar needs as above, Lab Management enables you to create these basic virtual machines (also known as Golden VMs) once and store in the library as virtual machine templates so that any time you want to create an environment you can reuse these virtual machine templates.

Creating Virtual Machine Template

1. First step is to have the base virtual machine which you want to use as virtual machine template (Golden VM) for different environments. If you already have a virtual machine just copy the virtual machine folder with all the necessary files into the System Centre Virtual Machine Manager (SCVMM) library share. In case you do not have a virtual machine you can easily create one using SCVMM Admin Console which comes with Lab Management SKU (we will cover this in more detail in one of the upcoming posts).

2. Now launch “Microsoft Test and Lab Manager” from All Programs -> Microsoft Visual Studio 10.0  -> Microsoft Test and Lab Manager

3. Connect to the TFS Server and your team project. Click on “Don’t Set context” when prompted. Go to Lab Center (from top left) and click on “Virtual Machine Templates” on the ‘Library’ activity.

image

4. Click “New” to create a virtual machine template. This opens up the wizard where first you need to select the library share where you want  Lab Management to store this virtual machine template.

image

5. Then select the virtual machine from SCVMM library share by clicking the browse button. The below list shows the virtual machines which you have created earlier either using SCVMM Admin console or copied into SCVMM library share (in case you already had virtual machine).

 image

In this list you only see virtual machines available in SCVMM library shares. So if you have existing VHD which you want to create a virtual machine template from, use SCVMM to create a VM using this VHD, and store it in the library.

6. After selecting the virtual machine now you can enter the name and description for this virtual machine template. Also you can assign a role to help select appropriate virtual machine template during environment creation e.g. all the virtual machine templates with different configurations (version, OS etc) of SQL server can be assigned role as “Database Server”. Similarly all the virtual machine templates with different configurations (version, OS etc) of IIS server can be assigned role as  “Web Server” etc.

image

7. That's it!. Just press finish and you have created your first virtual machine template as you can see in your list of virtual machine templates.

image

8. Repeat above steps to create another virtual machine template for IIS Server.

 

Creating Virtual Environment

Now as you have created virtual machine templates (Golden VMs) you are all set to create your first virtual environment. Majority of team members in your team can start directly here as once someone creates a set of virtual machine templates everyone can start using them to create environments.

1. Click on “Environment” activity in Lab Center. Click “New” to create a new environment.

2.  Provide a name and optionally a description for the environment you are about to create. Let’s give it a name “Dinner Now Test Environment” as we will use this for testing Dinner Now application.

3. Select Virtual as the type of environment

4. Select one of the host groups from the host group drop down list & click “Next”

image

5. From the list of available roles, select the Database Server role and the Web Server role, by clicking on each and then clicking on the Add button. Note that you can also add your own roles by clicking on the New Role button on top of the roles lists. Click “Next”.

image

6. Assign a VM template for each of the roles. On the right side you can see the list of VM templates from library as created in earlier step. e.g. Assign VM template Win2k3-IIS to Web Server role and Win2k3-SQL to Database server role.

image

7. That’s it! Just press finish and your first virtual environment creation is started. Virtual environment creation may take several minutes depending on number and size of VM templates selected above.

image

Working with Virtual Environment

Like physical environment you can start, stop and connect to different machines of your virtual environment. In addition, virtual environment provides some advantages over physical environments such as snapshot & restore. You can take a snapshot of your complete virtual environment (data and memory state of all machines) at a point in time and later restore that snapshot. This is really useful to debug complex bugs which are difficult to reproduced on a developer machine as now developer has access to the environment with the same configuration, same build and same meta data when the bug was found. With this capability you can significantly reduce the no. of non-reproducible bugs. Stay tuned for more details on this scenario in an upcoming blog post.

To work with any environment you can just double click on any of the virtual machines of the environments and it opens up “Lab Environment Viewer” tool. This tool allows you to connect to different machines of the environment without remembering their names/IP addresses for terminal services (TS) sessions. Also Lab Environment Viewer shows you all the virtual machines on the left and avoid painful switching between TS sessions. While you are working on one of the machines you can also get a quick preview of other machines with the cool thumbnail view.

image

To start, stop, snapshot or pause an environment you can simply click the necessary action from the environment tool-bar at the top-left corner. when you perform an action it applies to all the virtual machines of the environment. So to snapshot a multi machine environment you just need to take snapshot for the environment as oppose to individually taking snapshot of each machine.

image

All the snapshots of the environment are available under snapshots tab of environment viewer. At any point of time you can revert your environment to any of these snapshots with a single click of revert and all the machines will be restored to that snapshot. e.g. you may want to take a snapshot after the environment is setup first time calling it “Clean state” and than deploying regular builds on this environment can be simplified significantly as you can revert the environment to clean state before every build deployment. Lab Management also offers great automation to automate regular build, deployment and test cycles.

image

Also at any point you can access to an older build with a simple revert to the snapshot of that particular build. This is really helpful when you need a prior build for debugging a issue as unlike with physical machines where you may spend hours (to uninstall the current builds and then install new build and even then not sure if everything is fine as uninstall may have issues) now you can get to a prior build with just a button click “Revert to Snapshot”.

image

image

In this post we have covered the basic Lab scenario, of creating and working with virtual environment. Stay tuned for the next post about leveraging virtual environment for testing.

Comments