Merge pull request #1132 from wallyworld/lp-1392514

Ensure metadata file gets closed

Fixes: https://bugs.launchpad.net/juju-core/+bug/1392514
Merge pull request #1133 from wallyworld/lp-1392514-1.21

Merge pull request #1132 from wallyworld/lp-1392514

Ensure metadata file gets closed

Fixes: https://bugs.launchpad.net/juju-core/+bug/1392514