示例#1
0
文件: test_utils.py 项目: thh/neutron
 def test_get_chassis_availability_zones_no_azs(self):
     chassis = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={
         'external_ids': {
             'ovn-cms-options': 'enable-chassis-as-gw'
         }
     })
     self.assertEqual(set(), utils.get_chassis_availability_zones(chassis))
示例#2
0
 def as_dict(self, alive):
     return {
         'binary':
         self.binary,
         'host':
         self.chassis.hostname,
         'heartbeat_timestamp':
         timeutils.utcnow(),
         'availability_zone':
         ', '.join(ovn_utils.get_chassis_availability_zones(self.chassis)),
         'topic':
         'n/a',
         'description':
         self.description,
         'configurations': {
             'chassis_name':
             self.chassis.name,
             'bridge-mappings':
             self.chassis.external_ids.get('ovn-bridge-mappings', '')
         },
         'start_flag':
         True,
         'agent_type':
         self.agent_type,
         'id':
         self.agent_id,
         'alive':
         alive,
         'admin_state_up':
         True
     }
示例#3
0
 def test_get_chassis_availability_zones_multiple_az(self):
     chassis = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={
         'external_ids': {
             'ovn-cms-options':
             'enable-chassis-as-gw,availability-zones=az0:az1 :az2:: :'}})
     self.assertEqual(
         {'az0', 'az1', 'az2'},
         utils.get_chassis_availability_zones(chassis))
示例#4
0
 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
示例#5
0
    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))
示例#6
0
 def get_chassis_and_azs(self):
     chassis_azs = {}
     for ch in self.chassis_list().execute(check_error=True):
         chassis_azs[ch.name] = utils.get_chassis_availability_zones(ch)
     return chassis_azs
示例#7
0
 def test_get_chassis_availability_zones_malformed(self):
     chassis = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={
         'external_ids': {'ovn-cms-options':
                          'enable-chassis-as-gw,availability-zones:az0'}})
     self.assertEqual(
         [], utils.get_chassis_availability_zones(chassis))