cmd/jujud: reattempt api.Open if IsCodeNotProvisioned

There is a race between the machine agent starting and
the provisioner recording its instance ID in state.
We modify the agent's logic around opening API
connections to retry for up to one minute if it receives
an error satisfying IsCodeNotProvisioned.

Fixes https://bugs.launchpad.net/juju-core/+bug/1345014
Merge pull request #357 from axw/lp1345014-jujud-wait-provisioned

cmd/jujud: reattempt api.Open if IsCodeNotProvisioned

There is a race between the machine agent starting and
the provisioner recording its instance ID in state.
We modify the agent's logic around opening API
connections to retry for up to one minute if it receives
an error satisfying IsCodeNotProvisioned.

Fixes https://bugs.launchpad.net/juju-core/+bug/1345014
Added MakeMachine mathod to factory.
Factory methods for charms and services.
Add unit methods to factory.
Update style, some code changes.
Comment updates.
Factory improvements - style fixing.
Merge pull request #358 from tasdomas/factory-improvements

Factory improvements

Added methods for creating charms, services and units to the testing factory.
cmd/jujud: fix upgrade worker error handling

If the connection to state is lost then return an error so that the
machine agent will restart. For other errors, don't return the error
because we want the machine agent to stay running wait for user
intervention.

This change also adds tests for the handling of upgradeWorkerContext's
UpgradeComplete channel. This was previously untested.