March 2013 - Posts

Lab Management with SCVMM 2012 and /labenvironmentplacementpolicy:aggressive
Tue, Mar 26 2013 6:05

I did a post a year or so ago about setting up TFS Labs and mentioned command

C:\Program Files\Microsoft Team Foundation Server 2010\Tools>tfsconfig lab /hostgroup /collectionName:myTpc  ​/labenvironmentplacementpolicy:aggressive /edit /Name:"My hosts group"

This can be used tell TFS Lab Management to place VMs using any memory that is assigned stopped environments. This allowed a degree of over commitment of resources.

As I discovered today this command only works for SCVMM 2010 based system. if you try it you just get a message saying not support on SCVMM 2012. There appears to be no equivalent for 2012.

However you can use features such as dynamic memory with in SCVMM 2012 so all is not lost

Kerbal Space Program - Its educational and written in Mono too!
Sun, Mar 24 2013 6:35

image

My son is really taken with Kerbal Space Program. This great games allows you to design your own  space craft and so run your own on-going space program, all with a realistic physics engine.

What is particularly nice is that this cross platform Mono based application is being built in a very agile manner with a new release most weeks, each adding features as well as bug fixes. There also seems to be an active community of people building plug-ins for extra space craft components and rovers.

I am not sure how much orbital mechanics will appear in his school exams this year, but it is certainly educational in the longer term.

TF900548 when using my Typemock 2012 TFS custom build activity
Sat, Mar 23 2013 16:52

Using the Typemock TFS 2012 Build activity I created I had started seen the error

TF900548: An error occurred publishing the Visual Studio test results. Details: 'The following id must have a positive value: testRunId.'

I thought it might be down to having patched our build boxes to TFS 2012 Update 1, maybe it needed to be rebuild due to some dependency? However, on trying the build activity on my development TFS server I found it ran fine.

I made sure I had the same custom assemblies and Typemock autorun folder and build definition on both systems, I did, so it was not that.

Next I tried running the build but targeting an agent on on the same VM as the build controller. This worked, so it seems I have a build controller issues. So I ran Windows update to make sure the OS was patched it to date, it applied a few patches and rebooted. And all was OK my test ran gain.

It does seem that for many build issues the standard switch it off and back on again does the job

Black Marble is hosting the Yorkshire Chapter of the Global Windows Azure Bootcamp on the 27th of April
Thu, Mar 21 2013 7:45

Black Marble is hosting the Yorkshire Chapter of the Global Windows Azure Bootcamp taking place in several locations globally on the April 27th, 2013. This free community organised event is one day deep dive class where you will get you up to speed on developing for Windows Azure. The class includes a trainer with deep real world experience with Windows Azure, as well as a series of labs so you can practice what you just learned.

Black Marble’s event will be run by Robert Hogg (Microsoft Integration MVP) and Steve Spencer (Windows Azure MVP). Come along and join the global Azure event of the year!

Check out the prerequisites you need to install on your PC and here to sign up

Global Azure Bootcamp Logo

Installing a DB from a DACPAC using Powershell as part of TFS Lab Management deployment
Thu, Mar 14 2013 11:45

I have been battling setting up a DB deployed via the SQL 2012 DAC tools and Powershell.  My environment was a network isolated pair of machines

  • DC – the domain controller and SQL 2012 server
  • IIS – A web front end

As this is network isolated I could only run scripts on the IIS server, so my DB deploy needed to be remote. So the script I ended up with was

param(
    [string]$sqlserver = $( throw "Missing: parameter sqlserver"),
    [string]$dacpac = $( throw "Missing: parameter dacpac"),
    [string]$dbname = $( throw "Missing: parameter dbname") )

Write-Host "Deploying the DB with the following settings"
Write-Host "sqlserver:   $sqlserver"
Write-Host "dacpac: $dacpac"
Write-Host "dbname: $dbname"


# load in DAC DLL (requires config file to support .NET 4.0)
# change file location for a 32-bit OS
add-type -path "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll"

# make DacServices object, needs a connection string
$d = new-object Microsoft.SqlServer.Dac.DacServices "server=$sqlserver"

# register events, if you want 'em
register-objectevent -in $d -eventname Message -source "msg" -action { out-host -in $Event.SourceArgs[1].Message.Message } | Out-Null

# Load dacpac from file & deploy to database named pubsnew
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpac)
$d.Deploy($dp, $dbname, $true) # the true is to allow an upgrade, could be parameterised, also can add further deploy params

# clean up event
unregister-event -source "msg"

Remember the SQL 2012 DAC tools only work with PowerShell 3.0 as they have a .NET 4 dependency.

This was called within the Lab Build using the command line

image

cmd /c powershell $(BuildLocation)\SQLDeploy.ps1 dc $(BuildLocation)\Database.dacpac sabs

All my scripts worked correctly locally when I ran it on the command line, they were also starting from within the build, but failing with errors along the lines of

Deployment Task Logs for Machine: IIS
Accessing the following location using the lab service account: blackmarble\tfslab, \\store\drops.
Deploying the DB with the following settings
sqlserver:   dc
dacpac:
\\store\drops\Main.CI\Main.CI_20130314.2\Debug\Database.dacpac
dbname: Database1
Initializing deployment (Start)
Exception calling "Deploy" with "3" argument(s): "Could not deploy package."
Initializing deployment (Failed)
At
\\store\drops\Main.CI\Main.CI_20130314.2\Debug\SQLDeploy.ps1:26
char:2
+  $d.Deploy($dp, $dbname, $true) # the true is to allow an upgrade
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DacServicesException
Stopped accessing the following location using the lab service account: blackmarble\tfslab, \\store\drops.

Though not obvious from the error message the issue was who the script was running as. The TFS agent runs as a machine account, this had no rights to access the SQL on the DC. Once I granted the computer account IIS$ suitable rights to the SQL box all was OK. The alternative would have been to enable mixed mode authentication and user a connection string in the form 

“server=dc;User ID=sa;Password=mypassword”

So now I can deploy my DB on a new build.

You don’t half get strange errors when two servers have the same SID
Tue, Mar 12 2013 12:30

You don’t half get strange errors when building a test environment if when you run SYSPREP’d each copy of your VM base image you forget to check the ‘generalize’ box

image

If you forget this, as I did, each VM has a different name but the same SID. Basically the domain/AD is completely confused as who is what. The commonest error I saw was that I could not setup application (Report Services, SP 2010 and TFS 2012) with domain service accounts. I all cases I got messages about missing rights or cannot communicate with domain controller.

The fix was to basically start again. I re-SDYSPREP’d one of the pair of boxes I had to it reset it’s SID, I stripped off what I was trying to install, re added it to the domain and installed applications again. Once this was done all was fine.

For more on SID and SYSPREP see Mark Russinovick’s blog

Cannot run Microsoft Fakes based test if Typemock Isolator enabled
Sat, Mar 9 2013 9:07

With Microsoft Fakes moving to the Premium SKU of Visual Studio in 2012.2 (CTP4 is now available) more people will be looking at using them.

I have just installed CTP4 and have seen a behaviour I don’t think I have not seen in the previous version of Visual Studio (I need to check because as well as CTP4  I have recently installed the new version of Typemock Isolator 7.3.0 that addresses issues with Windows 8 and Visual  Studio 2012).

Anyway the error you see when you run a fakes based test is ‘UnitTestIsolation instrumentation failed to initialialize, Please restart Visual Studio and rerun this test’

image

The solution is to disable Typemock Isolator (Menu Typemock > Suspend Mocking), when this is done, without a reboot, the Fakes based test run.

Does mean you can’t have a solution using both Fakes and Isolator, but why would you?

TFS TPC Databases and SQL 2012 availability groups
Sat, Mar 9 2013 7:46

Worth noting that when you create a new TPC in TFS 2012, when the TFS configuration DB and other TPC DBs are in SQL 2012 availability groups, the new TPC DB is not placed in this or any other availability group. You have to add it manually, and historically remove it when servicing TFS. Though the need to remove it for servicing changes with TFS 2012.2 which allows servicing of high availability DBs

Recovering network isolated lab management environments if you have to recreate your SC-VMM server’s DB
Fri, Mar 8 2013 11:12

Whilst upgrading our Lab Management system we lost the SC-VMM DB. This has meant we needed to recreate environments we already have running on Hyper_V hosts but were unknown to TFS. If they were not network isolated this is straight forward, just recompose the environment (after clear out the XML in the VM descriptions fields). However if they are network isolated and running, then you have do play around a bit.

This is the simplest method I have found thus far. I am interested to hear if you have a better way

  • In SC-VMM (or via PowerShell) find all the VMs in your environment. They are going to have names in the form Lab_[GUID]. If you look at the properties of the VMs in the description field you can see the XML that defines the Lab they belong to.

image

If you are not sure what VMs you need you can of course cross reference the internal machine names with the AD within the network isolated environment. remember this environment is running so you can login to it.

  • Via SC-VMM Shutdown each VM
  • Via SC-VMM store the VM in the library
  • Wait a while…….
  • When all the VMs have been stored, navigate to them in SC-VMM. For each one in turn open the properties and
    • CHECK THE DESCRIPTION XML TO MAKE SURE YOU HAVE THE RIGHT VM AND KNOW THEIR ROLE
    • Change the name to something sensible (not essential if you like GUIDs in environment members names, but as I think it helps) e.g change Lab_[guid] to ‘My Test DC’
    • Delete all the XML in the Description field
    • In the hardware configuration, delete the ‘legacy network’ and connect the ‘Network adaptor’ to your main network – this will all be recreated when you create the new lab

image

Note that a DC will not have any connections to your main network as it is network isolated. For the purpose of this migration it DOES need to be reconnected. Again this will be stored by the tooling when you create the new environment.

  • When all have been update in SC-VMM, open MTM and import the stored VMs into the team project
  • You can now create a new environment using these stored VM. It should deploy out OK, but I have found you might need to restart it before all the test agent connect correctly
  • And that should be it, the environment is known to TFS lab managed and is running network isolated

You might want to delete the stored VMs once you have the environment running. But this will down to your policies, they are not needed as you can store the environment as a whole to archive or duplicate it with network isolation.

Fixing Lab Manager environments with brute force
Tue, Mar 5 2013 11:22

Another post from Rik Fixing Lab Manager environments with brute force following our Lab Management upgrade

Creating VMs for lab management
Tue, Mar 5 2013 6:46

Rik has done a post on creating VMs for Lab management to follow up on the one I did yesterday on our Lab upgrade.

Upgrading our TFS 2012 Lab Management to use SC-VMM 2012 SP1
Mon, Mar 4 2013 11:45

Background

We have been successfully using our TFS Lab Management system for a while. However, we have noticed an issue that when deploying environments the performance of the system slowed. This was down to I/O congestion between our servers and the SAN that provided their main VM storage because the library store and the hyper-v host servers all shared the same SAN.

clip_image002

Also we had the need to start to create environments using Windows 8 and Server 2012. This is not possible using System Center Virtual Machine Manager (SCVMM) 2008 or Hyper-V hosted on earlier than Windows 2012.

So it was time to do an upgrade of both the operating system, and our underlying hardware. The decision was made to dump the SAN and provide each Hyper-V host with its own SAS based RAID 5 disk. The main Lab SCVMM library server would also use local storage. All servers would be moved to Server 2012 and SCVMM would advance to 2012 with Service Pack 1 (required to manage Server 2012).

clip_image004

You might ask why we did not do this sooner, especially the move to support Windows 8 and Server 2012 VMs? The answer is that until TFS 2012 quarterly update 1 there was no support for System Center 2012, which itself had to wait until the SP1 release in January. So the start of the year was the first time we could do the update. We had planned to do very early in the year, but waiting for hardware and scheduling of our time let it drag on.

Hardware

The hardware upgrade was less straightforward than original anticipated as we needed to change the host controller card to support the required RAID5 array of disks. Once that was done on each of the Hyper-V hosts, installing the OS and configuring Hyper-V was quick and easy.

Meanwhile the library server was moved to a different box to allow for the sliding block puzzle of storage move and OS upgrades.

The Plan

After much thought we decided our upgrade path would be

  1. Stop all environments
  2. Rebuild each Hyper-V server with Server 2012 on their mirrored boot disks, adding the new SAS hardware and removing the SAN disks.
  3. Build the new SCVMM 2012SP1 server on Server 2012. The DB server would also move from an in-place SQL 2008 R2 instance to be hosted on our resilient SQL 2012 with Always On (also now supported in SCVMM 2012 SP1). This would mean an upgrade with existing database, as far as SCVMM is concerned.
  4. Add the rebuilt Hyper-V hosts to SCVMM
  5. Get the deployed VMs off SAN and onto the new SAS disks, along with a transfer of the library share.
  6. Reconfigure TFS to point to the new SCVMM server

What really happened

SCVMM Upgrade

The major problem we found was that you can’t upgrade the database from SCVMM 2008 R2 SP1 to SCVMM 2012 SP1. It need to be upgraded to SCVMM 2012 first.

In fact the SCVMM install process then suffered a cascade of issues:

  • SCVMM 2008 R2 needed the WAIK for Vista. SCVMM 2012 required the Win7 WAIK and SCVMM 2012 SP1 wanted the Windows 8 Automated Deployment kit.
  • Each time SCVMM wanted to upgrade its database, the database had to be in Simple Recovery mode. This is incompatible with Always On, which requires Full Recovery mode. This meant that the DB couldn’t be moved into the Availability group until the final installation was complete.

In the end we built a temporary VM for SCVMM 2012. The original host was left on Server 2008 R2 with the Vista WAIK; the intermediate host had Server 2008 R2 with the Windows 7 WAIK and the final host had Server 2012 with the Windows 8 ADK.

The problem we then found was that the final SCVMM 2012 SP1 system failed to start the Virtual Machine Manager service. The error we saw was:

Problem signature:
P1: vmmservice
P2: 3.1.6011.0
P3: Utils
P4: 3.1.6011.0
P5: M.V.D.SqlRetryCommand.InternalExecuteReader
P6: M.V.DB.CarmineSqlException
P7: b82c

We rolled back and repeated the process a number of time, and even tried a final in-place upgrade of the original host. Each resulted in the same fault. The internet turned up no help – two or three people reported the same fault and each one required a clean SCVMM installation to fix the fault.

Interestingly, our original DB size was around 700Mb. Each time, the upgrade process left a final DB of around 70Mb, suggesting something had gone wrong during DB updates. Whether this had anything to do with the presence of Lab we don’t know.

In the end we had no choice but to install SCVMM 2012 SP1 clean, with a new database. Once we did that everything worked just fine from the SCVMM point of view.

TFS

First we repointed TFS at the new SCVMM server

Tfsconfig.exe lab /settings / scvmmservername:my_new_scvmmservername /force

This worked OK, we then tried to run to upgrade the schema

tfsconfig lab /upgradeSCVMM /collectionName:*.

But this errored. Also when we tried to change the library and host groups both via the UI and command line we also got errors. The problem was that TFS thought there were libraries and host groups on the now retired old SCVMM server.

The solution was to open Microsoft Test Manager (MTM) and delete the live environments and stored environments, VMs and templates. This had no effect on the new SCVVM server as these entries referred to the now no-existent SCVMM host. It just removed the entries in the TFS databases.

Once this was done we could run the command

tfsconfig lab /upgradeSCVMM /collectionName:*.

And we could also reset the library and host groups to point to the new server.

So what do we have?

The upgrade (reinstall?) is now done and what do we have? On the Hyper-V hosts we have running VMs, and due to the effort of our IT team we have wired back the virtual networks previously created for Lab Management for network isolation. It is a mess and need doing via MTM, but it works for now.

The SCVMM library contains loads of stored environments. However as they were stored using the GUID based names used in Lab management their purpose is not that obvious.

As we had to delete the SCVMM database and TFS entries we have lost that index of GUIDs to sensible names.

The next step?

We need to manually take VMs and get them imported correctly into the new SCVMM library so that they can be deployed.

For running environment that don’t require network isolation we can compose new environments to wrapper the VMs. However, if we need network isolation we can’t see any method other than to push each VM up into the library and re-deploy them as a new network isolated environment, more posts to follow as I am sure we will learn stuff doing this.

Points of note:

  • Lab Manager shoves a load of XML into the notes field of a VM on Hyper-V. If that xml is present, lab assumes the VM is part of an environment and won’t show that as being a VM for use in new environment. Deleting the XML makes the VM magically reappear.
  • Allowing developers to make lots of snapshots, particularly with save states is a bad idea. When migrating between server versions, the Hyper-V save states are incompatible so you will lose lots and lots and lots of work if you’re not careful.
  • Having lots of snapshots with configuration variations might also cause confusion. Collapsing snapshots overall is a not a bad idea.
  • If you have a VM in the library (we now have multiple libraries to make sure people using Lab can’t accidentally delete key VM images) with the same VM ID as a running machine SCVMM won’t show you the one that is running. If you think it through this makes sense – SCVMM doesn’t export and import VM folders, it simply hefts them around the network. This is just like copying a VM form one Win8 box to another – the default option is to import the machine with the same ‘unique’ identifier.
    The solution to this one is to import a new copy of the source VM onto the hyper-v host, choosing the ‘make a copy and generate a new ID’ option. This new VM can then be manipulated with SCVMM and you still have a ‘gold master’ in your library.
  • Enabling server 2012 data deduplication on your SCVMM library shares is a very good plan. Ours is saving 75% of disk space. The only thing to be wary of is that if you pull a VM from the library onto Hyper-V and then store it back to the library the file will take up the ‘correct’ amount of disk space until the dedupe job runs again. If you’re not careful you can ‘overfill’ your disk this way!
  • SCVMM 2012 and SP1 like clouds and offer all kinds of technology solutions that can build a virtual infrastructure for you with VLANs and all kinds of cleverness. This will confuse the life out of Lab Manager so don’t do it for your Lab Environment. We now have a couple of ‘clouds’ in SCVMM and the Lab one consists of little more than the Hyper-V hosts and associated libraries. There is one virtual switch and one logical switch, both of which exist only to hook up our main network. Anything more complex will confuse Lab.
    Meanwhile, Lab still creates new Hyper-V Virtual Switches. SCVMM will know nothing of these so you need to be aware of that when inspecting VMs in SCVMM.

If we were doing it again…

So what have we learnt? The upgrade of the SCVMM database is critical. If this fails you have no other option other than to rebuild and manual recreate from the basic VMs

Even with SC-VMM 2012 SP1 and Lab Management there are still many moving parts you have to consider to get the system working. The change from 2008 to 2012 is like going from Imperial to Metric measurements. It is the same basic idea, it just feels like everything has changed.

Thanks to Rik and Rob for helping with this post

ALM Rangers ship more guidance
Sat, Mar 2 2013 9:24

Yesterday two new ALM Ranger projects shipped, practical guidance on the use of Microsoft Fakes (which I worked on) and for Team Foundation Server (TFS) Disaster Recovery avoidance, planning and step-step recovery walkthroughs for the worst case scenarios.

Also updates for the Coded UI test tooling guide and the TFS Upgrade guide were released..

For more details see below to follow the links to the Ranger blogs and CodePlex to download the materials.

  Better Unit Testing with Microsoft Fakes v1 eBook

Contains practical guidance for migrating to and unit testing with Microsoft Fakes. Walk-throughs allow you to navigate basic and advanced concepts, giving you a comfortable and confident start in implementing Microsoft Fakes as a mocking solution. The eBook PDF format will be complimented with other eReader formats, i.e. MOBI, in an upcoming update as part of our new content and style dog-fooding adventure.
clip_image005
clip_image003

Team Foundation Server Planning Guide v1.1
featuring new sections on Disaster Avoidance and Recovery Planning, allowing you to spot the “smoke” before you are confronted by a “raging fire”.
clip_image005[1]

Test Tooling Guide (Coded UI) v1
clip_image002

Team Foundation Server Upgrade Guide v2.1
clip_image002[1]