'Tests that we call volume_api.terminate_connection when we found
a stashed connector in the bdm.connection_info dict.'

@mock.patch.object(objects.BlockDeviceMapping, 'destroy')
def test_local_cleanup_bdm_volumes_stashed_connector(self, mock_destroy):

    inst = self._create_instance_obj()
    conn_info = {'connector': {'host': inst.host}}
    vol_bdm = objects.BlockDeviceMapping(self.context, id=1, instance_uuid=inst.uuid, volume_id=uuids.volume_id, source_type='volume', destination_type='volume', delete_on_termination=True, connection_info=jsonutils.dumps(conn_info), attachment_id=None)
    loc_bdm = objects.BlockDeviceMapping(self.context, id=2, instance_uuid=inst.uuid, volume_id=uuids.volume_id2, source_type='blank', destination_type='local')
    bdms = objects.BlockDeviceMappingList(objects=[vol_bdm, loc_bdm])
    @mock.patch.object(self.compute_api.volume_api, 'terminate_connection')
    @mock.patch.object(self.compute_api.volume_api, 'detach')
    @mock.patch.object(self.compute_api.volume_api, 'delete')
    @mock.patch.object(self.context, 'elevated', return_value=self.context)
    def do_test(self, mock_elevated, mock_delete, mock_detach, mock_terminate):
        self.compute_api._local_cleanup_bdm_volumes(bdms, inst, self.context)
        mock_terminate.assert_called_once_with(self.context, uuids.volume_id, conn_info['connector'])
        mock_detach.assert_called_once_with(self.context, uuids.volume_id, inst.uuid)
        mock_delete.assert_called_once_with(self.context, uuids.volume_id)
        self.assertEqual(2, mock_destroy.call_count)
    do_test(self)
