Example #1
0
 def test_get_vlan_device_name(self, mocked_hash):
     # only the first six chars of the hash are being used in the algorithm
     hash_used = MOCKED_HASH[0:6]
     self.assertEqual('10charrrrr.1',
                      m_common.get_vlan_device_name('10charrrrr', "1"))
     self.assertEqual('11ch' + hash_used + '.1',
                      m_common.get_vlan_device_name('11charrrrrr', "1"))
     self.assertEqual('14ch' + hash_used + '.1',
                      m_common.get_vlan_device_name('14charrrrrrrrr', "1"))
     self.assertEqual('14ch' + hash_used + '.1111',
                      m_common.get_vlan_device_name('14charrrrrrrrr',
                                                    "1111"))
Example #2
0
 def test_get_vlan_device_name(self, mocked_hash):
     # only the first six chars of the hash are being used in the algorithm
     hash_used = MOCKED_HASH[0:6]
     self.assertEqual('10charrrrr.1',
                      m_common.get_vlan_device_name('10charrrrr', "1"))
     self.assertEqual('11ch' + hash_used + '.1',
                      m_common.get_vlan_device_name('11charrrrrr', "1"))
     self.assertEqual('14ch' + hash_used + '.1',
                      m_common.get_vlan_device_name('14charrrrrrrrr', "1"))
     self.assertEqual('14ch' + hash_used + '.1111',
                      m_common.get_vlan_device_name('14charrrrrrrrr',
                                                    "1111"))
Example #3
0
    def test_get_vlan_subinterface_name_advanced(self):
        """Ensure the same hash is used for long interface names.

        If the generated vlan device name would be too long, make sure that
        everything before the '.' is equal. This might be helpful when
        debugging problems.
        """

        max_device_name = "15charrrrrrrrrr"
        vlan_dev_name1 = m_common.get_vlan_device_name(max_device_name, "1")
        vlan_dev_name2 = m_common.get_vlan_device_name(max_device_name, "1111")
        self.assertEqual(
            vlan_dev_name1.partition(".")[0],
            vlan_dev_name2.partition(".")[0])
Example #4
0
    def test_get_vlan_subinterface_name_advanced(self):
        """Ensure the same hash is used for long interface names.

        If the generated vlan device name would be too long, make sure that
        everything before the '.' is equal. This might be helpful when
        debugging problems.
        """

        max_device_name = "15charrrrrrrrrr"
        vlan_dev_name1 = m_common.get_vlan_device_name(max_device_name,
                                                       "1")
        vlan_dev_name2 = m_common.get_vlan_device_name(max_device_name,
                                                       "1111")
        self.assertEqual(vlan_dev_name1.partition(".")[0],
                         vlan_dev_name2.partition(".")[0])
Example #5
0
    def try_to_bind_segment_for_agent(self, context, segment, agent):
        if self.check_segment_for_agent(segment, agent):
            vif_details_segment = self.vif_details
            mappings = self.get_mappings(agent)
            interface = mappings[segment['physical_network']]
            network_type = segment[api.NETWORK_TYPE]

            if network_type == p_constants.TYPE_VLAN:
                vlan_id = segment[api.SEGMENTATION_ID]
                macvtap_src = macvtap_common.get_vlan_device_name(
                    interface, vlan_id)
                vif_details_segment['vlan'] = vlan_id
            else:
                macvtap_src = interface

            if self._is_live_migration(context):
                # We can use the original port here, as during live migration
                # portbinding is done after the migration happened. Nova will
                # not do a reschedule of the instance migration if binding
                # fails, but just set the instance into error state.
                # Due to that we can  be sure that the original port is the
                # migration source port.
                orig_vif_details = context.original[portbindings.VIF_DETAILS]
                orig_source = orig_vif_details[
                    portbindings.VIF_DETAILS_MACVTAP_SOURCE]
                if orig_source != macvtap_src:
                    source_host = context.original[portbindings.HOST_ID]
                    target_host = agent['host']
                    LOG.error(
                        "Vif binding denied by mechanism driver. "
                        "MacVTap source device '%(target_dev)s' on "
                        "the migration target '%(target_host)s'is "
                        "not equal to device '%(source_dev)s' on "
                        "the migration source '%(source_host)s. "
                        "Make sure that the "
                        "interface mapping of macvtap "
                        "agent on both hosts is equal "
                        "for the physical network '%(physnet)s'!", {
                            'source_dev': orig_source,
                            'target_dev': macvtap_src,
                            'target_host': target_host,
                            'source_host': source_host,
                            'physnet': segment['physical_network']
                        })
                    return False

            vif_details_segment['physical_interface'] = interface
            vif_details_segment['macvtap_source'] = macvtap_src
            vif_details_segment['macvtap_mode'] = MACVTAP_MODE_BRIDGE
            LOG.debug("Macvtap vif_details added to context binding: %s",
                      vif_details_segment)
            context.set_binding(segment[api.ID], self.vif_type,
                                vif_details_segment)
            return True
        return False
Example #6
0
    def try_to_bind_segment_for_agent(self, context, segment, agent):
        if self.check_segment_for_agent(segment, agent):
            vif_details_segment = self.vif_details
            mappings = self.get_mappings(agent)
            interface = mappings[segment['physical_network']]
            network_type = segment[api.NETWORK_TYPE]

            if network_type == constants.TYPE_VLAN:
                vlan_id = segment[api.SEGMENTATION_ID]
                macvtap_src = macvtap_common.get_vlan_device_name(interface,
                                                                  vlan_id)
                vif_details_segment['vlan'] = vlan_id
            else:
                macvtap_src = interface

            if self._is_live_migration(context):
                # We can use the original port here, as during live migration
                # portbinding is done after the migration happened. Nova will
                # not do a reschedule of the instance migration if binding
                # fails, but just set the instance into error state.
                # Due to that we can  be sure that the original port is the
                # migration source port.
                orig_vif_details = context.original[portbindings.VIF_DETAILS]
                orig_source = orig_vif_details[
                    portbindings.VIF_DETAILS_MACVTAP_SOURCE]
                if orig_source != macvtap_src:
                    source_host = context.original[portbindings.HOST_ID]
                    target_host = agent['host']
                    LOG.error("Vif binding denied by mechanism driver. "
                              "MacVTap source device '%(target_dev)s' on "
                              "the migration target '%(target_host)s'is "
                              "not equal to device '%(source_dev)s' on "
                              "the migration source '%(source_host)s. "
                              "Make sure that the "
                              "interface mapping of macvtap "
                              "agent on both hosts is equal "
                              "for the physical network '%(physnet)s'!",
                              {'source_dev': orig_source,
                               'target_dev': macvtap_src,
                               'target_host': target_host,
                               'source_host': source_host,
                               'physnet': segment['physical_network']})
                    return False

            vif_details_segment['physical_interface'] = interface
            vif_details_segment['macvtap_source'] = macvtap_src
            vif_details_segment['macvtap_mode'] = MACVTAP_MODE_BRIDGE
            LOG.debug("Macvtap vif_details added to context binding: %s",
                      vif_details_segment)
            context.set_binding(segment[api.ID], self.vif_type,
                                vif_details_segment)
            return True
        return False
    def network_delete(self, context, **kwargs):
        LOG.debug("network_delete received")
        network_id = kwargs.get("network_id")

        if network_id not in self.network_map:
            LOG.error(_LE("Network %s is not available."), network_id)
            return

        segment = self.network_map.get(network_id)
        if segment and segment.network_type == p_constants.TYPE_VLAN:
            if_mappings = self.agent.mgr.interface_mappings
            vlan_device_name = macvtap_common.get_vlan_device_name(
                if_mappings[segment.physical_network], str(segment.segmentation_id)
            )
            ip_dev = ip_lib.IPDevice(vlan_device_name)
            if ip_dev.exists():
                LOG.debug("Delete %s", ip_dev.name)
                ip_dev.link.delete()
            else:
                LOG.debug("Cannot delete vlan device %s; it does not exist", vlan_device_name)
    def network_delete(self, context, **kwargs):
        LOG.debug("network_delete received")
        network_id = kwargs.get('network_id')

        if network_id not in self.network_map:
            LOG.error("Network %s is not available.", network_id)
            return

        segment = self.network_map.get(network_id)
        if segment and segment.network_type == constants.TYPE_VLAN:
            if_mappings = self.agent.mgr.interface_mappings
            vlan_device_name = macvtap_common.get_vlan_device_name(
                if_mappings[segment.physical_network],
                str(segment.segmentation_id))
            ip_dev = ip_lib.IPDevice(vlan_device_name)
            if ip_dev.exists():
                LOG.debug("Delete %s", ip_dev.name)
                ip_dev.link.delete()
            else:
                LOG.debug("Cannot delete vlan device %s; it does not exist",
                          vlan_device_name)
Example #9
0
    def try_to_bind_segment_for_agent(self, context, segment, agent):
        if self.check_segment_for_agent(segment, agent):
            vif_details_segment = self.vif_details
            mappings = self.get_mappings(agent)
            interface = mappings[segment["physical_network"]]
            network_type = segment[api.NETWORK_TYPE]

            if network_type == p_constants.TYPE_VLAN:
                vlan_id = segment[api.SEGMENTATION_ID]
                macvtap_src = macvtap_common.get_vlan_device_name(interface, vlan_id)
                vif_details_segment["vlan"] = vlan_id
            else:
                macvtap_src = interface

            vif_details_segment["physical_interface"] = interface
            vif_details_segment["macvtap_source"] = macvtap_src
            vif_details_segment["macvtap_mode"] = MACVTAP_MODE_BRIDGE
            LOG.debug("Macvtap vif_details added to context binding: %s", vif_details_segment)
            context.set_binding(segment[api.ID], self.vif_type, vif_details_segment)
            return True
        return False
Example #10
0
    def try_to_bind_segment_for_agent(self, context, segment, agent):
        if self.check_segment_for_agent(segment, agent):
            vif_details_segment = self.vif_details
            mappings = self.get_mappings(agent)
            interface = mappings[segment['physical_network']]
            network_type = segment[api.NETWORK_TYPE]

            if network_type == p_constants.TYPE_VLAN:
                vlan_id = segment[api.SEGMENTATION_ID]
                macvtap_src = macvtap_common.get_vlan_device_name(
                    interface, vlan_id)
                vif_details_segment['vlan'] = vlan_id
            else:
                macvtap_src = interface

            vif_details_segment['physical_interface'] = interface
            vif_details_segment['macvtap_source'] = macvtap_src
            vif_details_segment['macvtap_mode'] = MACVTAP_MODE_BRIDGE
            LOG.debug("Macvtap vif_details added to context binding: %s",
                      vif_details_segment)
            context.set_binding(segment[api.ID], self.vif_type,
                                vif_details_segment)
            return True
        return False