# Path: neutron/objects/network.py
# class NetworkRBAC(rbac.RBACBaseObject):
# class NetworkDhcpAgentBinding(base.NeutronDbObject):
# class NetworkSegment(base.NeutronDbObject):
# class NetworkPortSecurity(base_ps._PortSecurity):
# class ExternalNetwork(base.NeutronDbObject):
# class Network(rbac_db.NeutronRbacObject):
# class SegmentHostMapping(base.NeutronDbObject):
# class NetworkDNSDomain(base.NeutronDbObject):
#     VERSION = '1.3'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = "1.0"
#     VERSION = '1.0'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = '1.0'
#     def obj_make_compatible(self, primitive, target_version):
#     def get_down_bindings(cls, context, cutoff):
#     def create(self):
#     def update(self):
#     def _attach_hosts(self, hosts):
#     def obj_load_attr(self, attrname):
#     def _load_hosts(self, db_obj=None):
#     def from_db_object(self, db_obj):
#     def get_objects(cls, context, _pager=None, **kwargs):
#     def create(self):
#     def update(self):
#     def _attach_qos_policy(self, qos_policy_id):
#     def _set_dns_domain(self, dns_domain):
#     def modify_fields_from_db(cls, db_obj):
#     def modify_fields_to_db(cls, fields):
#     def from_db_object(self, *objs):
#     def get_bound_project_ids(cls, context, policy_id):
#     def obj_make_compatible(self, primitive, target_version):
#     def get_net_dns_from_port(cls, context, port_id):
# 
# Path: neutron/services/segments/db.py
# _USER_CONFIGURED_SEGMENT_PLUGIN = None
# FOR_NET_DELETE = 'for_net_delete'
#         _USER_CONFIGURED_SEGMENT_PLUGIN = any(
#             p in cfg.CONF.service_plugins for p in ['segments', segment_class])
# def check_user_configured_segment_plugin():
#     def _make_segment_dict(segment_obj, fields=None):
#     def _get_segment(self, context, segment_id):
#     def create_segment(self, context, segment):
#     def _create_segment_db(self, context, segment_id, segment):
#     def update_segment(self, context, uuid, segment):
#     def get_segment(self, context, uuid, fields=None):
#     def get_segments(self, context, filters=None, fields=None,
#                      sorts=None, limit=None, marker=None,
#                      page_reverse=False):
#     def get_segments_count(self, context, filters=None):
#     def get_segments_by_hosts(self, context, hosts):
#     def delete_segment(self, context, uuid, for_net_delete=False):
# def update_segment_host_mapping(context, host, current_segment_ids):
# def get_hosts_mapped_with_segments(context):
# def _get_phys_nets(agent):
# def get_segments_with_phys_nets(context, phys_nets):
# def map_segment_to_hosts(context, segment_id, hosts):
# def _update_segment_host_mapping_for_agent(resource, event, trigger,
#                                            payload=None):
# def _add_segment_host_mapping_for_segment(resource, event, trigger,
#                                           payload=None):
# def _delete_segments_for_network(resource, event, trigger,
#                                  payload=None, **kwargs):
# def subscribe():
# class SegmentDbMixin(object):


import datetime
import random
import testscenarios
from operator import attrgetter
from unittest import mock
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.exceptions import dhcpagentscheduler as das_exc
from oslo_config import cfg
from oslo_utils import importutils
from oslo_utils import uuidutils
from neutron.db import agentschedulers_db as sched_db
from neutron.objects import agent
from neutron.objects import network as network_obj
from neutron.scheduler import dhcp_agent_scheduler
from neutron.services.segments import db as segments_service_db
from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import test_plugin
from neutron.tests.unit import testlib_api
        helpers.register_dhcp_agent(HOST_C)
        segments_service_db.update_segment_host_mapping(
            self.ctx, HOST_C, {seg2_id})
        observed_val_second_segment = scheduler.auto_schedule_networks(
            self.plugin, self.ctx, HOST_C)
        self.assertTrue(observed_val_second_segment)
        agents = self.plugin.get_dhcp_agents_hosting_networks(
            self.ctx, [net_id])
        self.assertEqual(2, len(agents))


class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
                           sched_db.DhcpAgentSchedulerDbMixin):
    def test_auto_schedule_network_excess_agents(self):
        plugin = mock.MagicMock()
        plugin.get_subnets.return_value = (
            [{"network_id": self.network_id, "enable_dhcp": True}])
        plugin.get_network.return_value = {'availability_zone_hints': ['nova']}
        scheduler = dhcp_agent_scheduler.ChanceScheduler()
        dhcpfilter = 'neutron.scheduler.dhcp_agent_scheduler.DhcpFilter'
        self._create_and_set_agents_down(['host-a', 'host-b'])
        expected_hosted_agents = 1
        binding_index = 1
        scheduler.auto_schedule_networks(plugin, self.ctx, 'host-a')
        with mock.patch(
                dhcpfilter + '.get_vacant_network_dhcp_agent_binding_index',
                context=self.ctx, network_id=self.network_id) as ndab:
            ndab.return_value = binding_index
            scheduler.auto_schedule_networks(plugin, self.ctx, 'host-b')
            self.assertTrue(ndab.called)

# Path: neutron/objects/network.py
# class NetworkRBAC(rbac.RBACBaseObject):
# class NetworkDhcpAgentBinding(base.NeutronDbObject):
# class NetworkSegment(base.NeutronDbObject):
# class NetworkPortSecurity(base_ps._PortSecurity):
# class ExternalNetwork(base.NeutronDbObject):
# class Network(rbac_db.NeutronRbacObject):
# class SegmentHostMapping(base.NeutronDbObject):
# class NetworkDNSDomain(base.NeutronDbObject):
#     VERSION = '1.3'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = "1.0"
#     VERSION = '1.0'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = '1.0'
#     def obj_make_compatible(self, primitive, target_version):
#     def get_down_bindings(cls, context, cutoff):
#     def create(self):
#     def update(self):
#     def _attach_hosts(self, hosts):
#     def obj_load_attr(self, attrname):
#     def _load_hosts(self, db_obj=None):
#     def from_db_object(self, db_obj):
#     def get_objects(cls, context, _pager=None, **kwargs):
#     def create(self):
#     def update(self):
#     def _attach_qos_policy(self, qos_policy_id):
#     def _set_dns_domain(self, dns_domain):
#     def modify_fields_from_db(cls, db_obj):
#     def modify_fields_to_db(cls, fields):
#     def from_db_object(self, *objs):
#     def get_bound_project_ids(cls, context, policy_id):
#     def obj_make_compatible(self, primitive, target_version):
#     def get_net_dns_from_port(cls, context, port_id):
# 
# Path: neutron/services/segments/db.py
# _USER_CONFIGURED_SEGMENT_PLUGIN = None
# FOR_NET_DELETE = 'for_net_delete'
#         _USER_CONFIGURED_SEGMENT_PLUGIN = any(
#             p in cfg.CONF.service_plugins for p in ['segments', segment_class])
# def check_user_configured_segment_plugin():
#     def _make_segment_dict(segment_obj, fields=None):
#     def _get_segment(self, context, segment_id):
#     def create_segment(self, context, segment):
#     def _create_segment_db(self, context, segment_id, segment):
#     def update_segment(self, context, uuid, segment):
#     def get_segment(self, context, uuid, fields=None):
#     def get_segments(self, context, filters=None, fields=None,
#                      sorts=None, limit=None, marker=None,
#                      page_reverse=False):
#     def get_segments_count(self, context, filters=None):
#     def get_segments_by_hosts(self, context, hosts):
#     def delete_segment(self, context, uuid, for_net_delete=False):
# def update_segment_host_mapping(context, host, current_segment_ids):
# def get_hosts_mapped_with_segments(context):
# def _get_phys_nets(agent):
# def get_segments_with_phys_nets(context, phys_nets):
# def map_segment_to_hosts(context, segment_id, hosts):
# def _update_segment_host_mapping_for_agent(resource, event, trigger,
#                                            payload=None):
# def _add_segment_host_mapping_for_segment(resource, event, trigger,
#                                           payload=None):
# def _delete_segments_for_network(resource, event, trigger,
#                                  payload=None, **kwargs):
# def subscribe():
# class SegmentDbMixin(object):


# Path: neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
import datetime
import random
import testscenarios
from operator import attrgetter
from unittest import mock
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.exceptions import dhcpagentscheduler as das_exc
from oslo_config import cfg
from oslo_utils import importutils
from oslo_utils import uuidutils
from neutron.db import agentschedulers_db as sched_db
from neutron.objects import agent
from neutron.objects import network as network_obj
from neutron.scheduler import dhcp_agent_scheduler
from neutron.services.segments import db as segments_service_db
from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import test_plugin
from neutron.tests.unit import testlib_api

        helpers.register_dhcp_agent(HOST_C)
        segments_service_db.update_segment_host_mapping(
            self.ctx, HOST_C, {seg2_id})
        observed_val_second_segment = scheduler.auto_schedule_networks(
            self.plugin, self.ctx, HOST_C)
        self.assertTrue(observed_val_second_segment)
        agents = self.plugin.get_dhcp_agents_hosting_networks(
            self.ctx, [net_id])
        self.assertEqual(2, len(agents))


class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
                           sched_db.DhcpAgentSchedulerDbMixin):
    def test_auto_schedule_network_excess_agents(self):
        plugin = mock.MagicMock()
        plugin.get_subnets.return_value = (
            [{"network_id": self.network_id, "enable_dhcp": True}])
        plugin.get_network.return_value = {'availability_zone_hints': ['nova']}
        scheduler = dhcp_agent_scheduler.ChanceScheduler()
        dhcpfilter = 'neutron.scheduler.dhcp_agent_scheduler.DhcpFilter'
        self._create_and_set_agents_down(['host-a', 'host-b'])
        expected_hosted_agents = 1
        binding_index = 1
        scheduler.auto_schedule_networks(plugin, self.ctx, 'host-a')
        with mock.patch(
                dhcpfilter + '.get_vacant_network_dhcp_agent_binding_index',
                context=self.ctx, network_id=self.network_id) as ndab:
            ndab.return_value = binding_index
            scheduler.auto_schedule_networks(plugin, self.ctx, 'host-b')
            self.assertTrue(ndab.called)

        num_hosted_agents = network_obj.NetworkDhcpAgentBinding.count(