本文整理汇总了Python中neutron.services.segments.db.update_segment_host_mapping函数的典型用法代码示例。如果您正苦于以下问题:Python update_segment_host_mapping函数的具体用法?Python update_segment_host_mapping怎么用?Python update_segment_host_mapping使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_segment_host_mapping函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auto_schedule_one_network_two_segments_with_one_subnet_each
def test_auto_schedule_one_network_two_segments_with_one_subnet_each(self):
net_id = self._create_network()
seg1_id = self._create_segment(net_id)
self._create_subnet(seg1_id, net_id)
helpers.register_dhcp_agent(HOST_D)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_D, {seg1_id})
scheduler = dhcp_agent_scheduler.ChanceScheduler()
observed_val_first_segment = scheduler.auto_schedule_networks(
self.plugin, self.ctx, HOST_D)
self.assertTrue(observed_val_first_segment)
agents = self.plugin.get_dhcp_agents_hosting_networks(
self.ctx, [net_id])
self.assertEqual(1, len(agents))
seg2_id = self._create_segment(net_id)
self._create_subnet(seg2_id, net_id, '192.168.11.0/24')
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))
示例2: update_segment_host_mapping
def update_segment_host_mapping(self, host, phy_nets):
"""Update SegmentHostMapping in DB"""
if not host:
return
ctx = n_context.get_admin_context()
segments = segment_service_db.get_segments_with_phys_nets(ctx, phy_nets)
available_seg_ids = {segment["id"] for segment in segments if segment["network_type"] in ("flat", "vlan")}
segment_service_db.update_segment_host_mapping(ctx, host, available_seg_ids)
示例3: test_schedule_segment_one_hostable_agent
def test_schedule_segment_one_hostable_agent(self):
net_id = self._create_network()
seg_id = self._create_segment(net_id)
helpers.register_dhcp_agent(HOST_C)
helpers.register_dhcp_agent(HOST_D)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_C, {seg_id})
net = self._get_network_with_candidate_hosts(net_id, seg_id)
agents = self.plugin.network_scheduler.schedule(
self.plugin, self.ctx, net)
self.assertEqual(1, len(agents))
self.assertEqual(HOST_C, agents[0].host)
示例4: test_ovn_sb_sync_update_existing_host
def test_ovn_sb_sync_update_existing_host(self):
with self.network() as network:
network_id = network['network']['id']
segment = self.create_segment(network_id, 'physnet1', 50)
segments_db.update_segment_host_mapping(
self.ctx, 'host1', {segment['id']})
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
self.assertEqual({'host1'}, segment_hosts)
self.add_fake_chassis('host1', ['physnet2'])
self._sync_resources()
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
self.assertFalse(segment_hosts)
示例5: test_ovn_sb_sync_delete_stale_host
def test_ovn_sb_sync_delete_stale_host(self):
with self.network() as network:
network_id = network['network']['id']
segment = self.create_segment(network_id, 'physnet1', 50)
segments_db.update_segment_host_mapping(
self.ctx, 'host1', {segment['id']})
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
self.assertEqual({'host1'}, segment_hosts)
# Since there is no chassis in the sb DB, host1 is the stale host
# recorded in neutron DB. It should be deleted after sync.
self._sync_resources()
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
self.assertFalse(segment_hosts)
示例6: test_auto_schedule_one_network_one_segment_one_subnet
def test_auto_schedule_one_network_one_segment_one_subnet(self):
net_id = self._create_network()
seg_id = self._create_segment(net_id)
self._create_subnet(seg_id, net_id)
helpers.register_dhcp_agent(HOST_C)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_C, {seg_id})
scheduler = dhcp_agent_scheduler.ChanceScheduler()
observed_return_val = scheduler.auto_schedule_networks(
self.plugin, self.ctx, HOST_C)
self.assertTrue(observed_return_val)
agent1 = self.plugin.get_dhcp_agents_hosting_networks(
self.ctx, [net_id])
self.assertEqual(1, len(agent1))
self.assertEqual('host-c', agent1[0]['host'])
示例7: test_schedule_segment_two_agents_per_segment_one_hostable_agent
def test_schedule_segment_two_agents_per_segment_one_hostable_agent(self):
cfg.CONF.set_override('dhcp_agents_per_network', 2)
net_id = self._create_network()
seg_id = self._create_segment(net_id)
helpers.register_dhcp_agent(HOST_C)
helpers.register_dhcp_agent(HOST_D)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_C, {seg_id})
net = self.plugin.get_network(self.ctx, net_id)
seg = self.segments_plugin.get_segment(self.ctx, seg_id)
net['candidate_hosts'] = seg['hosts']
agents = self.plugin.network_scheduler.schedule(
self.plugin, self.ctx, net)
self.assertEqual(1, len(agents))
self.assertEqual(HOST_C, agents[0].host)
示例8: test_schedule_segment_two_agents_per_segment
def test_schedule_segment_two_agents_per_segment(self):
cfg.CONF.set_override('dhcp_agents_per_network', 2)
net_id = self._create_network()
seg_id = self._create_segment(net_id)
helpers.register_dhcp_agent(HOST_C)
helpers.register_dhcp_agent(HOST_D)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_C, {seg_id})
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_D, {seg_id})
net = self._get_network_with_candidate_hosts(net_id, seg_id)
agents = self.plugin.network_scheduler.schedule(
self.plugin, self.ctx, net)
self.assertEqual(2, len(agents))
self.assertIn(agents[0].host, [HOST_C, HOST_D])
self.assertIn(agents[1].host, [HOST_C, HOST_D])
示例9: test_schedule_segment_many_hostable_agents
def test_schedule_segment_many_hostable_agents(self):
net_id = self._create_network()
seg_id = self._create_segment(net_id)
helpers.register_dhcp_agent(HOST_C)
helpers.register_dhcp_agent(HOST_D)
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_C, {seg_id})
segments_service_db.update_segment_host_mapping(
self.ctx, HOST_D, {seg_id})
net = self.plugin.get_network(self.ctx, net_id)
seg = self.segments_plugin.get_segment(self.ctx, seg_id)
net['candidate_hosts'] = seg['hosts']
agents = self.plugin.network_scheduler.schedule(
self.plugin, self.ctx, net)
self.assertEqual(1, len(agents))
self.assertIn(agents[0].host, [HOST_C, HOST_D])
示例10: test_update_segment_host_mapping
def test_update_segment_host_mapping(self):
ctx = context.get_admin_context()
host = 'host1'
physnets = ['phys_net1']
with self.network() as network:
network = network['network']
segment = self._test_create_segment(
network_id=network['id'], physical_network='phys_net1',
segmentation_id=200, network_type=p_constants.TYPE_VLAN)['segment']
self._test_create_segment(
network_id=network['id'], physical_network='phys_net2',
segmentation_id=201, network_type=p_constants.TYPE_VLAN)['segment']
segments = db.get_segments_with_phys_nets(ctx, physnets)
segment_ids = {segment['id'] for segment in segments}
db.update_segment_host_mapping(ctx, host, segment_ids)
segments_host_db = self._get_segments_for_host(host)
self.assertEqual(1, len(segments_host_db))
self.assertEqual(segment['id'],
segments_host_db[segment['id']]['segment_id'])
self.assertEqual(host, segments_host_db[segment['id']]['host'])
示例11: test_ovn_sb_sync
def test_ovn_sb_sync(self):
with self.network() as network:
network_id = network['network']['id']
seg1 = self.create_segment(network_id, 'physnet1', 50)
self.create_segment(network_id, 'physnet2', 51)
segments_db.update_segment_host_mapping(
self.ctx, 'host1', {seg1['id']})
segments_db.update_segment_host_mapping(
self.ctx, 'host2', {seg1['id']})
segments_db.update_segment_host_mapping(
self.ctx, 'host3', {seg1['id']})
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
self.assertEqual({'host1', 'host2', 'host3'}, segment_hosts)
self.add_fake_chassis('host2', ['physnet2'])
self.add_fake_chassis('host3', ['physnet3'])
self.add_fake_chassis('host4', ['physnet1'])
self._sync_resources()
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
# host1 should be cleared since it is not in the chassis DB. host3
# should be cleared since there is no segment for mapping.
self.assertEqual({'host2', 'host4'}, segment_hosts)