'Method used to allocate networks in the background.
Broken out for testing.'

def _allocate_network_async(self, context, instance, requested_networks, macs, security_groups, is_vpn, dhcp_options):

    if (requested_networks and requested_networks.no_allocate):
        LOG.debug("Not    allocating    networking    since    'none'    was    specified.", instance=instance)
        return network_model.NetworkInfo([])
    LOG.debug('Allocating    IP    information    in    the    background.', instance=instance)
    retries = CONF.network_allocate_retries
    attempts = (retries + 1)
    retry_time = 1
    bind_host_id = self.driver.network_binding_host_id(context, instance)
    for attempt in range(1, (attempts + 1)):
        try:
            nwinfo = self.network_api.allocate_for_instance(context, instance, vpn=is_vpn, requested_networks=requested_networks, macs=macs, security_groups=security_groups, dhcp_options=dhcp_options, bind_host_id=bind_host_id)
            LOG.debug('Instance    network_info:    |%s|', nwinfo, instance=instance)
            instance.system_metadata['network_allocated'] = 'True'
            return nwinfo
        except Exception:
            exc_info = sys.exc_info()
            log_info = {'attempt': attempt, 'attempts': attempts}
            if (attempt == attempts):
                LOG.exception('Instance    failed    network    setup    after    %(attempts)d    attempt(s)', log_info)
                six.reraise(*exc_info)
            LOG.warning('Instance    failed    network    setup    (attempt    %(attempt)d    of    %(attempts)d)', log_info, instance=instance)
            time.sleep(retry_time)
            retry_time *= 2
            if (retry_time > 30):
                retry_time = 30
