'Tests that we handle missing instance keypairs.'

@mock.patch.object(objects.Instance, 'get_by_uuid')
def test_metadata_as_json_deleted_keypair(self, mock_inst_get_by_uuid):

    instance = self.instance.obj_clone()
    delattr(instance, 'keypairs')
    mock_inst_get_by_uuid.return_value = instance
    md = fake_InstanceMetadata(self, instance)
    meta = md._metadata_as_json(base.OPENSTACK_VERSIONS[(-1)], path=None)
    meta = jsonutils.loads(meta)
    self.assertNotIn('keys', meta)
    self.assertNotIn('public_keys', meta)
