Upgrade fixes for LP #1403738 

Two separate fixes here. 

The first changes SetAgentVersion to use a raw transaction as it is called before upgrade steps have run.

The second ensures that container setup in the machine agent is done _after_ upgrades are complete. This involves some reorganisation of the API workers that need to start after upgrades are complete.