Пример #1
0
    def unconfigure_tenant_networks(self, task):
        """Unconfigure tenant networks for a node.

        Nova takes care of port removal from tenant network, we unbind it
        here/now to avoid the possibility of the ironic port being bound to the
        tenant and cleaning networks at the same time.

        :param task: A TaskManager instance.
        :raises: NetworkError
        """
        node = task.node
        LOG.info('Unbinding instance ports from node %s', node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (
                port_like_obj.internal_info.get(common.TENANT_VIF_KEY)
                or port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue

            is_smart_nic = neutron.is_smartnic_port(port_like_obj)
            if is_smart_nic:
                client = neutron.get_client(context=task.context)
                link_info = port_like_obj.local_link_connection
                neutron.wait_for_host_agent(client, link_info['hostname'])

            neutron.unbind_neutron_port(vif_port_id, context=task.context)
Пример #2
0
 def test_unbind_neutron_port(self, mock_client):
     port_id = 'fake-port-id'
     body = {'port': {'binding:host_id': '', 'binding:profile': {}}}
     neutron.unbind_neutron_port(port_id)
     mock_client.assert_called_once_with()
     mock_client.return_value.update_port.assert_called_once_with(
         port_id, body)
Пример #3
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError: if unbind Neutron port failed.
        """

        # NOTE(vsaienko) We picking object to attach on vif-attach side.
        # Here we should only detach VIF and shouldn't duplicate/follow
        # attach rules, just walk over all objects and detach VIF.
        for port_like_obj in task.portgroups + task.ports:
            # FIXME(sambetts) Remove this when we no longer support a nova
            # driver that uses port.extra
            vif_port_id = port_like_obj.internal_info.get(
                TENANT_VIF_KEY, port_like_obj.extra.get("vif_port_id"))
            if vif_port_id == vif_id:
                int_info = port_like_obj.internal_info
                extra = port_like_obj.extra
                int_info.pop(TENANT_VIF_KEY, None)
                extra.pop('vif_port_id', None)
                port_like_obj.extra = extra
                port_like_obj.internal_info = int_info
                port_like_obj.save()
                # NOTE(vsaienko) allow to unplug VIFs from ACTIVE instance.
                if task.node.provision_state == states.ACTIVE:
                    neutron.unbind_neutron_port(vif_port_id)
                break
        else:
            raise exception.VifNotAttached(vif=vif_id, node=task.node.uuid)
Пример #4
0
    def unconfigure_tenant_networks(self, task):
        """Unconfigure tenant networks for a node.

        Nova takes care of port removal from tenant network, we unbind it
        here/now to avoid the possibility of the ironic port being bound to the
        tenant and cleaning networks at the same time.

        :param task: A TaskManager instance.
        :raises: NetworkError
        """
        node = task.node
        LOG.info('Unbinding instance ports from node %s', node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (
                port_like_obj.internal_info.get(common.TENANT_VIF_KEY)
                or port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue

            is_smart_nic = neutron.is_smartnic_port(port_like_obj)
            if is_smart_nic:
                client = neutron.get_client(context=task.context)
                link_info = port_like_obj.local_link_connection
                neutron.wait_for_host_agent(client, link_info['hostname'])

            neutron.unbind_neutron_port(vif_port_id, context=task.context)
Пример #5
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError: if unbind Neutron port failed.
        """

        # NOTE(vsaienko) We picking object to attach on vif-attach side.
        # Here we should only detach VIF and shouldn't duplicate/follow
        # attach rules, just walk over all objects and detach VIF.
        for port_like_obj in task.portgroups + task.ports:
            # FIXME(sambetts) Remove this when we no longer support a nova
            # driver that uses port.extra
            vif_port_id = port_like_obj.internal_info.get(
                TENANT_VIF_KEY, port_like_obj.extra.get("vif_port_id"))
            if vif_port_id == vif_id:
                int_info = port_like_obj.internal_info
                extra = port_like_obj.extra
                int_info.pop(TENANT_VIF_KEY, None)
                extra.pop('vif_port_id', None)
                port_like_obj.extra = extra
                port_like_obj.internal_info = int_info
                port_like_obj.save()
                # NOTE(vsaienko) allow to unplug VIFs from ACTIVE instance.
                if task.node.provision_state == states.ACTIVE:
                    neutron.unbind_neutron_port(vif_port_id)
                break
        else:
            raise exception.VifNotAttached(vif=vif_id, node=task.node.uuid)
Пример #6
0
 def test_unbind_neutron_port_client_passed(self, mock_client):
     port_id = 'fake-port-id'
     body = {'port': {'binding:host_id': '', 'binding:profile': {}}}
     neutron.unbind_neutron_port(port_id,
                                 mock_client(context=self.context),
                                 context=self.context)
     self.assertEqual(1, mock_client.call_count)
     mock_client.return_value.update_port.assert_called_once_with(
         port_id, body)
Пример #7
0
 def test_unbind_neutron_port(self, mock_client):
     port_id = 'fake-port-id'
     body = {
         'port': {
             'binding:host_id': '',
             'binding:profile': {}
         }
     }
     neutron.unbind_neutron_port(port_id)
     mock_client.assert_called_once_with()
     mock_client.return_value.update_port.assert_called_once_with(port_id,
                                                                  body)
Пример #8
0
 def test_unbind_neutron_port_not_found(self, mock_log, mock_client):
     port_id = 'fake-port-id'
     mock_client.return_value.update_port.side_effect = (
         neutron_client_exc.PortNotFoundClient())
     body = {'port': {'binding:host_id': '', 'binding:profile': {}}}
     neutron.unbind_neutron_port(port_id)
     mock_client.assert_called_once_with()
     mock_client.return_value.update_port.assert_called_once_with(
         port_id, body)
     mock_log.info.assert_called_once_with(
         'Port %s was not found while '
         'unbinding.', port_id)
Пример #9
0
    def _unbind_flat_ports(self, task):
        node = task.node
        LOG.info('Unbinding instance ports from node %s', node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (port_like_obj.internal_info.get(
                common.TENANT_VIF_KEY)
                           or port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue
            neutron.unbind_neutron_port(vif_port_id, context=task.context)
Пример #10
0
    def _unbind_flat_ports(self, task):
        node = task.node
        LOG.info('Unbinding instance ports from node %s', node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (
                port_like_obj.internal_info.get(common.TENANT_VIF_KEY) or
                port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue
            neutron.unbind_neutron_port(vif_port_id, context=task.context)
Пример #11
0
 def test_unbind_neutron_port_not_found(self, mock_log, mock_client):
     port_id = 'fake-port-id'
     mock_client.return_value.update_port.side_effect = (
         neutron_client_exc.PortNotFoundClient())
     body = {
         'port': {
             'binding:host_id': '',
             'binding:profile': {}
         }
     }
     neutron.unbind_neutron_port(port_id)
     mock_client.assert_called_once_with()
     mock_client.return_value.update_port.assert_called_once_with(port_id,
                                                                  body)
     mock_log.info.assert_called_once_with('Port %s was not found while '
                                           'unbinding.', port_id)
Пример #12
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError: if unbind Neutron port failed.
        """
        # NOTE(mgoddard): Lookup the port first to check that the VIF is
        # attached, and fail if not.
        port_like_obj = self._get_port_like_obj_by_vif_id(task, vif_id)

        self._clear_vif_from_port_like_obj(port_like_obj)

        # NOTE(vsaienko) allow to unplug VIFs from ACTIVE instance.
        if task.node.provision_state == states.ACTIVE:
            neutron.unbind_neutron_port(vif_id)
Пример #13
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError: if unbind Neutron port failed.
        """
        # NOTE(mgoddard): Lookup the port first to check that the VIF is
        # attached, and fail if not.
        port_like_obj = self._get_port_like_obj_by_vif_id(task, vif_id)

        self._clear_vif_from_port_like_obj(port_like_obj)

        # NOTE(vsaienko) allow to unplug VIFs from ACTIVE instance.
        if task.node.provision_state == states.ACTIVE:
            neutron.unbind_neutron_port(vif_id)
Пример #14
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError: if unbind Neutron port failed.
        """
        # NOTE(mgoddard): Lookup the port first to check that the VIF is
        # attached, and fail if not.
        port_like_obj = self._get_port_like_obj_by_vif_id(task, vif_id)

        self._clear_vif_from_port_like_obj(port_like_obj)

        # NOTE(vsaienko): allow to unplug VIFs from ACTIVE instance.
        # NOTE(TheJulia): Also ensure that we delete the vif when in
        # DELETING state.
        if task.node.provision_state in [states.ACTIVE, states.DELETING]:
            neutron.unbind_neutron_port(vif_id, context=task.context)
Пример #15
0
    def vif_detach(self, task, vif_id):
        """Detach a virtual network interface from a node

        :param task: A TaskManager instance.
        :param vif_id: A VIF ID to detach
        :raises: VifNotAttached if VIF not attached.
        :raises: NetworkError if unbind Neutron port failed.
        """
        # NOTE(mgoddard): Lookup the port first to check that the VIF is
        # attached, and fail if not.
        port_like_obj = self._get_port_like_obj_by_vif_id(task, vif_id)

        self._clear_vif_from_port_like_obj(port_like_obj)

        # NOTE(vsaienko): allow to unplug VIFs from ACTIVE instance.
        # NOTE(TheJulia): Also ensure that we delete the vif when in
        # DELETING state.
        if task.node.provision_state in [states.ACTIVE, states.DELETING]:
            neutron.unbind_neutron_port(vif_id, context=task.context)
Пример #16
0
 def test_unbind_neutron_port(self, mock_client):
     port_id = 'fake-port-id'
     body_unbind = {
         'port': {
             'binding:host_id': '',
             'binding:profile': {}
         }
     }
     body_reset_mac = {
         'port': {
             'mac_address': None
         }
     }
     update_calls = [
         mock.call(port_id, body_unbind),
         mock.call(port_id, body_reset_mac)
     ]
     neutron.unbind_neutron_port(port_id, context=self.context)
     mock_client.assert_called_once_with(context=self.context)
     mock_client.return_value.update_port.assert_has_calls(update_calls)
Пример #17
0
    def unconfigure_tenant_networks(self, task):
        """Unconfigure tenant networks for a node.

        Nova takes care of port removal from tenant network, we unbind it
        here/now to avoid the possibility of the ironic port being bound to the
        tenant and cleaning networks at the same time.

        :param task: A TaskManager instance.
        :raises: NetworkError
        """
        node = task.node
        LOG.info(_LI('Unbinding instance ports from node %s'), node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (port_like_obj.internal_info.get(
                common.TENANT_VIF_KEY)
                           or port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue
            neutron.unbind_neutron_port(vif_port_id)
Пример #18
0
    def unconfigure_tenant_networks(self, task):
        """Unconfigure tenant networks for a node.

        Nova takes care of port removal from tenant network, we unbind it
        here/now to avoid the possibility of the ironic port being bound to the
        tenant and cleaning networks at the same time.

        :param task: A TaskManager instance.
        :raises: NetworkError
        """
        node = task.node
        LOG.info('Unbinding instance ports from node %s', node.uuid)

        ports = [p for p in task.ports if not p.portgroup_id]
        portgroups = task.portgroups
        for port_like_obj in ports + portgroups:
            vif_port_id = (
                port_like_obj.internal_info.get(common.TENANT_VIF_KEY) or
                port_like_obj.extra.get('vif_port_id'))
            if not vif_port_id:
                continue
            neutron.unbind_neutron_port(vif_port_id)