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))
    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))
Пример #3
0
    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)
Пример #4
0
 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
0
 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)
 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)
 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)
Пример #8
0
 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)
Пример #9
0
 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)
 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'])
Пример #11
0
 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)
Пример #12
0
    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)
 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'])
Пример #14
0
 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)
 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])
Пример #16
0
 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])
Пример #17
0
 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])
 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])
Пример #19
0
 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'])
Пример #20
0
 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'])
Пример #21
0
 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)
Пример #22
0
 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)