'spawn network deallocate test.
Make sure that when an instance is not found during spawn
that the network is deallocated'

def test_run_instance_dealloc_network_instance_not_found(self):

    instance = self._create_fake_instance_obj()
    def fake(*args, **kwargs):
        raise exception.InstanceNotFound(instance_id='fake')
    with test.nested(mock.patch.object(self.compute, '_deallocate_network'), mock.patch.object(self.compute.driver, 'spawn')) as (mock_deallocate, mock_spawn):
        mock_spawn.side_effect = fake
        self.compute.build_and_run_instance(self.context, instance, {}, {}, {}, block_device_mapping=[])
        mock_deallocate.assert_called_with(mock.ANY, mock.ANY, None)
        self.assertTrue(mock_spawn.called)
