Merge "OVO for SegmentHostMapping"
This commit is contained in:
commit
0fc308bac1
@ -219,3 +219,18 @@ class Network(rbac_db.NeutronRbacObject):
|
||||
def get_bound_tenant_ids(cls, context, policy_id):
|
||||
# TODO(ihrachys): provide actual implementation
|
||||
return set()
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
class SegmentHostMapping(base.NeutronDbObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
db_model = segment_model.SegmentHostMapping
|
||||
|
||||
fields = {
|
||||
'segment_id': obj_fields.UUIDField(),
|
||||
'host': obj_fields.StringField(),
|
||||
}
|
||||
|
||||
primary_keys = ['segment_id', 'host']
|
||||
|
@ -27,9 +27,9 @@ from neutron._i18n import _LI, _LW
|
||||
from neutron.agent.common import utils as agent_utils
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import agent as agent_model
|
||||
from neutron.db.models import segment as segment_model
|
||||
from neutron.db.network_dhcp_agent_binding import models as ndab_model
|
||||
from neutron.extensions import availability_zone as az_ext
|
||||
from neutron.objects import network
|
||||
from neutron.scheduler import base_resource_filter
|
||||
from neutron.scheduler import base_scheduler
|
||||
|
||||
@ -66,10 +66,10 @@ class AutoScheduler(object):
|
||||
agent_model.Agent.admin_state_up == sql.true())
|
||||
dhcp_agents = query.all()
|
||||
|
||||
query = context.session.query(
|
||||
segment_model.SegmentHostMapping.segment_id)
|
||||
query = query.filter(segment_model.SegmentHostMapping.host == host)
|
||||
segments_on_host = {s.segment_id for s in query}
|
||||
segment_host_mapping = network.SegmentHostMapping.get_objects(
|
||||
context, host=host)
|
||||
|
||||
segments_on_host = {s.segment_id for s in segment_host_mapping}
|
||||
|
||||
for dhcp_agent in dhcp_agents:
|
||||
if agent_utils.is_agent_down(
|
||||
|
@ -34,6 +34,7 @@ from neutron.db.models import segment as segment_model
|
||||
from neutron.db import segments_db as db
|
||||
from neutron.extensions import segment as extension
|
||||
from neutron import manager
|
||||
from neutron.objects import network
|
||||
from neutron.services.segments import exceptions
|
||||
|
||||
_deprecate._moved_global('SegmentHostMapping', new_module=segment_model)
|
||||
@ -160,10 +161,9 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
|
||||
def get_segments_by_hosts(self, context, hosts):
|
||||
if not hosts:
|
||||
return []
|
||||
query = context.session.query(
|
||||
segment_model.SegmentHostMapping).filter(
|
||||
segment_model.SegmentHostMapping.host.in_(hosts))
|
||||
return list({mapping.segment_id for mapping in query})
|
||||
segment_host_mapping = network.SegmentHostMapping.get_objects(
|
||||
context, host=hosts)
|
||||
return list({mapping.segment_id for mapping in segment_host_mapping})
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete_segment(self, context, uuid):
|
||||
@ -192,19 +192,18 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
|
||||
|
||||
def update_segment_host_mapping(context, host, current_segment_ids):
|
||||
with context.session.begin(subtransactions=True):
|
||||
segments_host_query = context.session.query(
|
||||
segment_model.SegmentHostMapping).filter_by(host=host)
|
||||
segment_host_mapping = network.SegmentHostMapping.get_objects(
|
||||
context, host=host)
|
||||
previous_segment_ids = {
|
||||
seg_host['segment_id'] for seg_host in segments_host_query}
|
||||
seg_host['segment_id'] for seg_host in segment_host_mapping}
|
||||
for segment_id in current_segment_ids - previous_segment_ids:
|
||||
context.session.add(segment_model.SegmentHostMapping(
|
||||
segment_id=segment_id,
|
||||
host=host))
|
||||
network.SegmentHostMapping(
|
||||
context, segment_id=segment_id, host=host).create()
|
||||
stale_segment_ids = previous_segment_ids - current_segment_ids
|
||||
if stale_segment_ids:
|
||||
segments_host_query.filter(
|
||||
segment_model.SegmentHostMapping.segment_id.in_(
|
||||
stale_segment_ids)).delete(synchronize_session=False)
|
||||
for entry in segment_host_mapping:
|
||||
if entry.segment_id in stale_segment_ids:
|
||||
entry.delete()
|
||||
|
||||
|
||||
def get_hosts_mapped_with_segments(context):
|
||||
@ -213,8 +212,8 @@ def get_hosts_mapped_with_segments(context):
|
||||
L2 providers can use this method to get an overview of SegmentHostMapping,
|
||||
and then delete the stale SegmentHostMapping.
|
||||
"""
|
||||
query = context.session.query(segment_model.SegmentHostMapping.host)
|
||||
return {row.host for row in query}
|
||||
segment_host_mapping = network.SegmentHostMapping.get_objects(context)
|
||||
return {row.host for row in segment_host_mapping}
|
||||
|
||||
|
||||
def _get_phys_nets(agent):
|
||||
@ -252,9 +251,8 @@ def map_segment_to_hosts(context, segment_id, hosts):
|
||||
"""Map segment to a collection of hosts."""
|
||||
with db_api.autonested_transaction(context.session):
|
||||
for host in hosts:
|
||||
context.session.add(
|
||||
segment_model.SegmentHostMapping(segment_id=segment_id,
|
||||
host=host))
|
||||
network.SegmentHostMapping(
|
||||
context, segment_id=segment_id, host=host).create()
|
||||
|
||||
|
||||
def _update_segment_host_mapping_for_agent(resource, event, trigger,
|
||||
|
@ -28,13 +28,13 @@ from neutron import context
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db.models import segment as segment_model
|
||||
from neutron.db import portbindings_db
|
||||
from neutron.db import segments_db
|
||||
from neutron.extensions import ip_allocation
|
||||
from neutron.extensions import l2_adjacency
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import segment as ext_segment
|
||||
from neutron.objects import network
|
||||
from neutron.plugins.common import constants as p_constants
|
||||
from neutron.plugins.ml2 import config
|
||||
from neutron.services.segments import db
|
||||
@ -471,10 +471,10 @@ class HostSegmentMappingTestCase(SegmentTestCase):
|
||||
|
||||
def _get_segments_for_host(self, host):
|
||||
ctx = context.get_admin_context()
|
||||
segments_host_list = ctx.session.query(
|
||||
segment_model.SegmentHostMapping).filter_by(host=host)
|
||||
segment_host_mapping = network.SegmentHostMapping.get_objects(
|
||||
ctx, host=host)
|
||||
return {seg_host['segment_id']: seg_host
|
||||
for seg_host in segments_host_list}
|
||||
for seg_host in segment_host_mapping}
|
||||
|
||||
def _register_agent(self, host, mappings=None, plugin=None,
|
||||
start_flag=True):
|
||||
@ -787,12 +787,9 @@ class TestMl2HostSegmentMappingAgentServerSynch(HostSegmentMappingTestCase):
|
||||
class TestSegmentAwareIpam(SegmentTestCase):
|
||||
def _setup_host_mappings(self, mappings=()):
|
||||
ctx = context.get_admin_context()
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
for segment_id, host in mappings:
|
||||
record = segment_model.SegmentHostMapping(
|
||||
segment_id=segment_id,
|
||||
host=host)
|
||||
ctx.session.add(record)
|
||||
for segment_id, host in mappings:
|
||||
network.SegmentHostMapping(
|
||||
ctx, segment_id=segment_id, host=host).create()
|
||||
|
||||
def _create_test_segment_with_subnet(self,
|
||||
network=None,
|
||||
|
@ -154,3 +154,22 @@ class NetworkDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
|
||||
obj = network.Network.get_object(self.context, id=obj.id)
|
||||
self.assertEqual('bar.com', obj.dns_domain)
|
||||
|
||||
|
||||
class SegmentHostMappingIfaceObjectTestCase(
|
||||
obj_test_base.BaseObjectIfaceTestCase):
|
||||
|
||||
_test_class = network.SegmentHostMapping
|
||||
|
||||
|
||||
class SegmentHostMappingDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
testlib_api.SqlTestCase):
|
||||
|
||||
_test_class = network.SegmentHostMapping
|
||||
|
||||
def setUp(self):
|
||||
super(SegmentHostMappingDbObjectTestCase, self).setUp()
|
||||
self._create_test_network()
|
||||
self._create_test_segment(network=self._network)
|
||||
for obj in itertools.chain(self.db_objs, self.obj_fields, self.objs):
|
||||
obj['segment_id'] = self._segment['id']
|
||||
|
@ -52,6 +52,7 @@ object_data = {
|
||||
'RouterRoute': '1.0-07fc5337c801fb8c6ccfbcc5afb45907',
|
||||
'SecurityGroup': '1.0-e26b90c409b31fd2e3c6fcec402ac0b9',
|
||||
'SecurityGroupRule': '1.0-e9b8dace9d48b936c62ad40fe1f339d5',
|
||||
'SegmentHostMapping': '1.0-521597cf82ead26217c3bd10738f00f0',
|
||||
'Subnet': '1.0-b71e720f45fff2a39759940e010be7d1',
|
||||
'SubnetPool': '1.0-e8300bfbc4762cc88a7f6205b52da2f8',
|
||||
'SubnetPoolPrefix': '1.0-13c15144135eb869faa4a76dc3ee3b6c',
|
||||
|
@ -41,9 +41,11 @@ HOST_D = 'host-d'
|
||||
|
||||
|
||||
class TestDhcpSchedulerBaseTestCase(testlib_api.SqlTestCase):
|
||||
CORE_PLUGIN = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
|
||||
|
||||
def setUp(self):
|
||||
super(TestDhcpSchedulerBaseTestCase, self).setUp()
|
||||
self.setup_coreplugin(self.CORE_PLUGIN)
|
||||
self.ctx = context.get_admin_context()
|
||||
self.network = {'id': 'foo_network_id'}
|
||||
self.network_id = 'foo_network_id'
|
||||
|
Loading…
Reference in New Issue
Block a user