def test_is_gateway_chassis(self): chassis = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={ 'external_ids': {'ovn-cms-options': 'enable-chassis-as-gw'}}) non_gw_chassis_0 = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={ 'external_ids': {'ovn-cms-options': ''}}) non_gw_chassis_1 = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={}) non_gw_chassis_2 = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={ 'external_ids': {}}) self.assertTrue(utils.is_gateway_chassis(chassis)) self.assertFalse(utils.is_gateway_chassis(non_gw_chassis_0)) self.assertFalse(utils.is_gateway_chassis(non_gw_chassis_1)) self.assertFalse(utils.is_gateway_chassis(non_gw_chassis_2))
def handle_ha_chassis_group_changes(self, event, row, old): """Handle HA Chassis Group changes. This method handles the inclusion and removal of Chassis to/from the default HA Chassis Group. """ if not self.driver._ovn_client.is_external_ports_supported(): return # NOTE(lucasgomes): If the external_ids column wasn't updated # (meaning, Chassis "gateway" status didn't change) just returns if not hasattr(old, 'external_ids') and event == self.ROW_UPDATE: return is_gw_chassis = utils.is_gateway_chassis(row) # If the Chassis being created is not a gateway, ignore it if not is_gw_chassis and event == self.ROW_CREATE: return if event == self.ROW_UPDATE: is_old_gw = utils.is_gateway_chassis(old) if is_gw_chassis and is_old_gw: return elif not is_gw_chassis and is_old_gw: # Chassis is not a gateway anymore, treat it as deletion event = self.ROW_DELETE elif is_gw_chassis and not is_old_gw: # Chassis is now a gateway, treat it as creation event = self.ROW_CREATE if event == self.ROW_CREATE: default_group = self.driver._nb_ovn.ha_chassis_group_get( ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME).execute( check_error=True) # Find what's the lowest priority number current in the group # and add the new chassis as the new lowest min_priority = min( [ch.priority for ch in default_group.ha_chassis], default=ovn_const.HA_CHASSIS_GROUP_HIGHEST_PRIORITY) self.driver._nb_ovn.ha_chassis_group_add_chassis( ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME, row.name, priority=min_priority - 1).execute(check_error=True) elif event == self.ROW_DELETE: self.driver._nb_ovn.ha_chassis_group_del_chassis( ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME, row.name, if_exists=True).execute(check_error=True)
def match_fn(self, event, row, old): if event != self.ROW_UPDATE: return True # NOTE(lucasgomes): If the external_ids column wasn't updated # (meaning, Chassis "gateway" status didn't change) just returns if not hasattr(old, 'external_ids') and event == self.ROW_UPDATE: return False if (old.external_ids.get('ovn-bridge-mappings') != row.external_ids.get('ovn-bridge-mappings')): return True # Check if either the Gateway status or Availability Zones has # changed in the Chassis is_gw = utils.is_gateway_chassis(row) is_gw_old = utils.is_gateway_chassis(old) azs = utils.get_chassis_availability_zones(row) old_azs = utils.get_chassis_availability_zones(old) if is_gw != is_gw_old or azs != old_azs: return True return False
def handle_ha_chassis_group_changes(self, event, row, old): """Handle HA Chassis Group changes. This method handles the inclusion and removal of Chassis to/from the default HA Chassis Group. """ if not self.driver._ovn_client.is_external_ports_supported(): return is_gw_chassis = utils.is_gateway_chassis(row) # If the Chassis being created is not a gateway, ignore it if not is_gw_chassis and event == self.ROW_CREATE: return azs = utils.get_chassis_availability_zones(row) if event == self.ROW_UPDATE: is_old_gw = utils.is_gateway_chassis(old) if is_gw_chassis and is_old_gw: old_azs = utils.get_chassis_availability_zones(old) # If there are no differences in the AZs, return if azs == old_azs: return # Find out the HA Chassis Groups that were affected by # the update (to add and/or remove the updated Chassis) ha_ch_add = self._get_ha_chassis_groups_within_azs( azs - old_azs) ha_ch_del = self._get_ha_chassis_groups_within_azs( old_azs - azs) with self.driver.nb_ovn.transaction(check_error=True) as txn: for hcg in ha_ch_add: min_priority = self._get_min_priority_in_hcg(hcg) txn.add( self.driver.nb_ovn.ha_chassis_group_add_chassis( hcg.name, row.name, priority=min_priority)) for hcg in ha_ch_del: txn.add( self.driver.nb_ovn.ha_chassis_group_del_chassis( hcg.name, row.name, if_exists=True)) return elif not is_gw_chassis and is_old_gw: # Chassis is not a gateway anymore, treat it as deletion event = self.ROW_DELETE elif is_gw_chassis and not is_old_gw: # Chassis is now a gateway, treat it as creation event = self.ROW_CREATE if event == self.ROW_CREATE: ha_chassis_list = self._get_ha_chassis_groups_within_azs(azs) with self.driver.nb_ovn.transaction(check_error=True) as txn: for hcg in ha_chassis_list: min_priority = self._get_min_priority_in_hcg(hcg) txn.add(self.driver.nb_ovn.ha_chassis_group_add_chassis( hcg.name, row.name, priority=min_priority)) elif event == self.ROW_DELETE: ha_chassis_list = self._get_ha_chassis_groups_within_azs(azs) with self.driver.nb_ovn.transaction(check_error=True) as txn: for hcg in ha_chassis_list: txn.add(self.driver.nb_ovn.ha_chassis_group_del_chassis( hcg.name, row.name, if_exists=True))