Exemple #1
0
 def test_ovn_sb_sync_add_new_host(self):
     with self.network() as network:
         network_id = network['network']['id']
     self.create_segment(network_id, 'physnet1', 50)
     self.add_fake_chassis('host1', ['physnet1'])
     segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
     self.assertFalse(segment_hosts)
     self._sync_resources()
     segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
     self.assertEqual({'host1'}, segment_hosts)
 def test_ovn_sb_sync_add_new_host(self):
     with self.network() as network:
         network_id = network['network']['id']
     self.create_segment(network_id, 'physnet1', 50)
     self.add_fake_chassis('host1', ['physnet1'])
     segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
     self.assertFalse(segment_hosts)
     self._sync_resources()
     segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
     self.assertEqual({'host1'}, segment_hosts)
Exemple #3
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_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 sync_hostname_and_physical_networks(self, ctx):
        LOG.debug('OVN-SB Sync hostname and physical networks started')
        host_phynets_map = self.ovn_api.get_chassis_hostname_and_physnets()
        current_hosts = set(host_phynets_map)
        previous_hosts = segments_db.get_hosts_mapped_with_segments(ctx)

        stale_hosts = previous_hosts - current_hosts
        for host in stale_hosts:
            LOG.debug('Stale host %s found in Neutron, but not in OVN SB DB. '
                      'Clear its SegmentHostMapping in Neutron', host)
            self.ovn_driver.update_segment_host_mapping(host, [])

        new_hosts = current_hosts - previous_hosts
        for host in new_hosts:
            LOG.debug('New host %s found in OVN SB DB, but not in Neutron. '
                      'Add its SegmentHostMapping in Neutron', host)
            self.ovn_driver.update_segment_host_mapping(
                host, host_phynets_map[host])

        for host in current_hosts & previous_hosts:
            LOG.debug('Host %s found both in OVN SB DB and Neutron. '
                      'Trigger updating its SegmentHostMapping in Neutron, '
                      'to keep OVN SB DB and Neutron have consistent data',
                      host)
            self.ovn_driver.update_segment_host_mapping(
                host, host_phynets_map[host])

        LOG.debug('OVN-SB Sync hostname and physical networks finished')
Exemple #6
0
    def sync_hostname_and_physical_networks(self, ctx):
        LOG.debug('OVN-SB Sync hostname and physical networks started')
        host_phynets_map = self.ovn_api.get_chassis_hostname_and_physnets()
        current_hosts = set(host_phynets_map)
        previous_hosts = segments_db.get_hosts_mapped_with_segments(ctx)

        stale_hosts = previous_hosts - current_hosts
        for host in stale_hosts:
            LOG.debug(
                'Stale host %s found in Neutron, but not in OVN SB DB. '
                'Clear its SegmentHostMapping in Neutron', host)
            self.ovn_driver.update_segment_host_mapping(host, [])

        new_hosts = current_hosts - previous_hosts
        for host in new_hosts:
            LOG.debug(
                'New host %s found in OVN SB DB, but not in Neutron. '
                'Add its SegmentHostMapping in Neutron', host)
            self.ovn_driver.update_segment_host_mapping(
                host, host_phynets_map[host])

        for host in current_hosts & previous_hosts:
            LOG.debug(
                'Host %s found both in OVN SB DB and Neutron. '
                'Trigger updating its SegmentHostMapping in Neutron, '
                'to keep OVN SB DB and Neutron have consistent data', host)
            self.ovn_driver.update_segment_host_mapping(
                host, host_phynets_map[host])

        LOG.debug('OVN-SB Sync hostname and physical networks finished')
Exemple #7
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)
 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)