예제 #1
0
    def test_crt_p2p_cna_single(self, mock_get_partitions,
                                mock_find_or_create_vswitch,
                                mock_find_free_vlan, mock_cna_bld):
        """Tests the crt_p2p_cna with the mgmt lpar and a dev_name."""
        # Mock out the data
        mock_vswitch = mock.Mock(related_href='vswitch_href')
        mock_find_or_create_vswitch.return_value = mock_vswitch
        mock_find_free_vlan.return_value = 2050

        # Mock the get of the VIOSes
        mock_vio1 = mock.Mock(uuid='mgmt_lpar_uuid')
        mock_vio2 = mock.Mock(uuid='vios_uuid2')
        mock_get_partitions.return_value = [mock_vio1, mock_vio2]

        mock_cna = mock.MagicMock()
        mock_trunk1 = mock.MagicMock(pvid=2050)
        mock_trunk1.create.return_value = mock_trunk1
        mock_cna_bld.side_effect = [mock_trunk1, mock_cna]

        # Invoke the create
        client_adpt, trunk_adpts = cna.crt_p2p_cna(self.adpt,
                                                   None,
                                                   'lpar_uuid',
                                                   ['mgmt_lpar_uuid'],
                                                   mock_vswitch,
                                                   crt_vswitch=True,
                                                   mac_addr='aabbccddeeff',
                                                   dev_name='tap-12345')

        # Make sure the client and trunk were 'built'
        mock_cna_bld.assert_any_call(self.adpt,
                                     2050,
                                     'vswitch_href',
                                     mac_addr='aabbccddeeff',
                                     slot_num=None)
        mock_cna_bld.assert_any_call(self.adpt,
                                     2050,
                                     'vswitch_href',
                                     trunk_pri=1,
                                     dev_name='tap-12345',
                                     ovs_bridge=None,
                                     ovs_ext_ids=None,
                                     configured_mtu=None)

        # Make sure they were then created
        self.assertIsNotNone(client_adpt)
        self.assertEqual(1, len(trunk_adpts))
        mock_cna.create.assert_called_once_with(parent_type=pvm_lpar.LPAR,
                                                parent_uuid='lpar_uuid')
        mock_trunk1.create.assert_called_once_with(parent=mock_vio1)
예제 #2
0
    def test_crt_p2p_cna(
            self, mock_get_partitions, mock_find_or_create_vswitch,
            mock_find_free_vlan, mock_cna_bld):
        """Tests the crt_p2p_cna."""
        # Mock out the data
        mock_vswitch = mock.Mock(related_href='vswitch_href')
        mock_find_or_create_vswitch.return_value = mock_vswitch
        mock_find_free_vlan.return_value = 2050

        # Mock the get of the VIOSes
        mock_vio1 = mock.Mock(uuid='src_io_host_uuid')
        mock_vio2 = mock.Mock(uuid='vios_uuid2')
        mock_get_partitions.return_value = [mock_vio1, mock_vio2]

        mock_cna = mock.MagicMock()
        mock_trunk1, mock_trunk2 = mock.MagicMock(pvid=2050), mock.MagicMock()
        mock_trunk1.create.return_value = mock_trunk1
        mock_cna_bld.side_effect = [mock_trunk1, mock_trunk2, mock_cna]

        # Invoke the create
        mock_ext_ids = {'test': 'value', 'test2': 'value2'}
        client_adpt, trunk_adpts = cna.crt_p2p_cna(
            self.adpt, None, 'lpar_uuid',
            ['src_io_host_uuid', 'vios_uuid2'], mock_vswitch, crt_vswitch=True,
            slot_num=1, mac_addr='aabbccddeeff', ovs_bridge='br-ex',
            ovs_ext_ids=mock_ext_ids, configured_mtu=1450)

        # Make sure the client and trunk were 'built'
        mock_cna_bld.assert_any_call(self.adpt, 2050, 'vswitch_href',
                                     slot_num=1, mac_addr='aabbccddeeff')
        mock_cna_bld.assert_any_call(
            self.adpt, 2050, 'vswitch_href', trunk_pri=1, dev_name=None,
            ovs_bridge='br-ex', ovs_ext_ids=mock_ext_ids, configured_mtu=1450)
        mock_cna_bld.assert_any_call(
            self.adpt, 2050, 'vswitch_href', trunk_pri=2, dev_name=None,
            ovs_bridge='br-ex', ovs_ext_ids=mock_ext_ids, configured_mtu=1450)

        # Make sure they were then created
        self.assertIsNotNone(client_adpt)
        self.assertEqual(2, len(trunk_adpts))
        mock_cna.create.assert_called_once_with(
            parent_type=pvm_lpar.LPAR, parent_uuid='lpar_uuid')
        mock_trunk1.create.assert_called_once_with(parent=mock_vio1)
        mock_trunk2.create.assert_called_once_with(parent=mock_vio2)
예제 #3
0
    def plug(self, vif, slot_num, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Extends the Lio implementation.  Will make sure that the trunk device
        has the appropriate metadata (ex. port id) set on it so that the
        Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """
        if not new_vif:
            return None

        lpar_uuid = vm.get_pvm_uuid(self.instance)
        mgmt_uuid = pvm_par.get_mgmt_partition(self.adapter).uuid

        # There will only be one trunk wrap, as we have created with just
        # the mgmt lpar.  Next step is to connect to the OVS.
        mtu = vif['network'].get_meta('mtu')
        dev_name = _get_trunk_dev_name(vif)

        meta_attrs = PvmMetaAttrs(vif, self.instance)

        # Create the trunk and client adapter.
        return pvm_cna.crt_p2p_cna(self.adapter,
                                   self.host_uuid,
                                   lpar_uuid, [mgmt_uuid],
                                   CONF.powervm.pvm_vswitch_for_novalink_io,
                                   crt_vswitch=True,
                                   mac_addr=vif['address'],
                                   dev_name=dev_name,
                                   slot_num=slot_num,
                                   ovs_bridge=vif['network']['bridge'],
                                   ovs_ext_ids=str(meta_attrs),
                                   configured_mtu=mtu)[0]
예제 #4
0
    def plug(self, vif, slot_num, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Creates a 'peer to peer' connection between the Management partition
        hosting the Linux I/O and the client VM.  There will be one trunk
        adapter for a given client adapter.

        The device will be 'up' on the mgmt partition.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """
        dev_name = self.get_trunk_dev_name(vif)

        if new_vif:
            # Create the trunk and client adapter.
            lpar_uuid = vm.get_pvm_uuid(self.instance)
            mgmt_uuid = pvm_par.get_this_partition(self.adapter).uuid
            cna_w = pvm_cna.crt_p2p_cna(
                self.adapter,
                self.host_uuid,
                lpar_uuid, [mgmt_uuid],
                CONF.powervm.pvm_vswitch_for_novalink_io,
                crt_vswitch=True,
                mac_addr=vif['address'],
                dev_name=dev_name,
                slot_num=slot_num)[0]
        else:
            cna_w = None

        # Make sure to just run the up just in case.
        utils.execute('ip', 'link', 'set', dev_name, 'up', run_as_root=True)

        return cna_w
예제 #5
0
    def plug(self, vif, slot_num):
        """Plugs a virtual interface (network) into a VM.

        Creates a 'peer to peer' connection between the Management partition
        hosting the Linux I/O and the client VM.  There will be one trunk
        adapter for a given client adapter.

        The device will be 'up' on the mgmt partition.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        """
        # Create the trunk and client adapter.
        lpar_uuid = vm.get_pvm_uuid(self.instance)
        mgmt_uuid = pvm_par.get_this_partition(self.adapter).uuid
        dev_name = self.get_trunk_dev_name(vif)
        cna_w, trunk_wraps = pvm_cna.crt_p2p_cna(
            self.adapter, self.host_uuid, lpar_uuid, [mgmt_uuid],
            CONF.powervm.pvm_vswitch_for_novalink_io, crt_vswitch=True,
            mac_addr=vif['address'], dev_name=dev_name, slot_num=slot_num)

        utils.execute('ip', 'link', 'set', dev_name, 'up', run_as_root=True)

        return cna_w
예제 #6
0
    def plug(self, vif, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Creates a 'peer to peer' connection between the Management partition
        hosting the Linux I/O and the client VM.  There will be one trunk
        adapter for a given client adapter.

        The device will be 'up' on the mgmt partition.

        Will make sure that the trunk device has the appropriate metadata (e.g.
        port id) set on it so that the Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """

        # Create the trunk and client adapter.
        lpar_uuid = vm.get_pvm_uuid(self.instance)
        mgmt_uuid = pvm_par.get_this_partition(self.adapter).uuid

        mtu = vif['network'].get_meta('mtu')
        if 'devname' in vif:
            dev_name = vif['devname']
        else:
            dev_name = ("nic" + vif['id'])[:network_model.NIC_NAME_LEN]

        meta_attrs = ','.join([
            'iface-id=%s' % (vif.get('ovs_interfaceid') or vif['id']),
            'iface-status=active',
            'attached-mac=%s' % vif['address'],
            'vm-uuid=%s' % self.instance.uuid
        ])

        if new_vif:
            return pvm_cna.crt_p2p_cna(self.adapter,
                                       None,
                                       lpar_uuid, [mgmt_uuid],
                                       NOVALINK_VSWITCH,
                                       crt_vswitch=True,
                                       mac_addr=vif['address'],
                                       dev_name=dev_name,
                                       ovs_bridge=vif['network']['bridge'],
                                       ovs_ext_ids=meta_attrs,
                                       configured_mtu=mtu)[0]
        else:
            # Bug : https://bugs.launchpad.net/nova-powervm/+bug/1731548
            # When a host is rebooted, something is discarding tap devices for
            # VMs deployed with OVS vif. To prevent VMs losing network
            # connectivity, this is fixed by recreating the tap devices during
            # init of the nova compute service, which will call vif plug with
            # new_vif==False.

            # Find the CNA for this vif.
            # TODO(esberglu) improve performance by caching VIOS wrapper(s) and
            # CNA lists (in case >1 vif per VM).
            cna_w_list = vm.get_cnas(self.adapter, self.instance)
            cna_w = self._find_cna_for_vif(cna_w_list, vif)
            if not cna_w:
                LOG.warning(
                    'Unable to plug VIF with mac %s for instance. The '
                    'VIF was not found on the instance.',
                    vif['address'],
                    instance=self.instance)
                return None

            # Find the corresponding trunk adapter
            trunks = pvm_cna.find_trunks(self.adapter, cna_w)
            for trunk in trunks:
                # Set MTU, OVS external ids, and OVS bridge metadata
                trunk.configured_mtu = mtu
                trunk.ovs_ext_ids = meta_attrs
                trunk.ovs_bridge = vif['network']['bridge']
                # Updating the trunk adapter will cause NovaLink to reassociate
                # the tap device.
                trunk.update()
예제 #7
0
파일: vif.py 프로젝트: arbrandes/nova
    def plug(self, vif, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Creates a 'peer to peer' connection between the Management partition
        hosting the Linux I/O and the client VM.  There will be one trunk
        adapter for a given client adapter.

        The device will be 'up' on the mgmt partition.

        Will make sure that the trunk device has the appropriate metadata (e.g.
        port id) set on it so that the Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """

        # Create the trunk and client adapter.
        lpar_uuid = vm.get_pvm_uuid(self.instance)
        mgmt_uuid = pvm_par.get_this_partition(self.adapter).uuid

        mtu = vif['network'].get_meta('mtu')
        if 'devname' in vif:
            dev_name = vif['devname']
        else:
            dev_name = ("nic" + vif['id'])[:network_model.NIC_NAME_LEN]

        meta_attrs = ','.join([
                     'iface-id=%s' % (vif.get('ovs_interfaceid') or vif['id']),
                     'iface-status=active',
                     'attached-mac=%s' % vif['address'],
                     'vm-uuid=%s' % self.instance.uuid])

        if new_vif:
            return pvm_cna.crt_p2p_cna(
                self.adapter, None, lpar_uuid, [mgmt_uuid], NOVALINK_VSWITCH,
                crt_vswitch=True, mac_addr=vif['address'], dev_name=dev_name,
                ovs_bridge=vif['network']['bridge'],
                ovs_ext_ids=meta_attrs, configured_mtu=mtu)[0]
        else:
            # Bug : https://bugs.launchpad.net/nova-powervm/+bug/1731548
            # When a host is rebooted, something is discarding tap devices for
            # VMs deployed with OVS vif. To prevent VMs losing network
            # connectivity, this is fixed by recreating the tap devices during
            # init of the nova compute service, which will call vif plug with
            # new_vif==False.

            # Find the CNA for this vif.
            # TODO(esberglu) improve performance by caching VIOS wrapper(s) and
            # CNA lists (in case >1 vif per VM).
            cna_w_list = vm.get_cnas(self.adapter, self.instance)
            cna_w = self._find_cna_for_vif(cna_w_list, vif)
            if not cna_w:
                LOG.warning('Unable to plug VIF with mac %s for instance. The '
                            'VIF was not found on the instance.',
                            vif['address'], instance=self.instance)
                return None

            # Find the corresponding trunk adapter
            trunks = pvm_cna.find_trunks(self.adapter, cna_w)
            for trunk in trunks:
                # Set MTU, OVS external ids, and OVS bridge metadata
                trunk.configured_mtu = mtu
                trunk.ovs_ext_ids = meta_attrs
                trunk.ovs_bridge = vif['network']['bridge']
                # Updating the trunk adapter will cause NovaLink to reassociate
                # the tap device.
                trunk.update()
예제 #8
0
    def plug(self, vif, slot_num, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Extends the Lio implementation.  Will make sure that the trunk device
        has the appropriate metadata (ex. port id) set on it so that the
        Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """
        lpar_uuid = vm.get_pvm_uuid(self.instance)
        mgmt_uuid = pvm_par.get_mgmt_partition(self.adapter).uuid

        # There will only be one trunk wrap, as we have created with just
        # the mgmt lpar.  Next step is to connect to the OVS.
        mtu = vif['network'].get_meta('mtu')
        dev_name = _get_trunk_dev_name(vif)

        meta_attrs = PvmMetaAttrs(vif, self.instance)

        if new_vif:
            # Create the trunk and client adapter.
            return pvm_cna.crt_p2p_cna(
                self.adapter,
                self.host_uuid,
                lpar_uuid, [mgmt_uuid],
                CONF.powervm.pvm_vswitch_for_novalink_io,
                crt_vswitch=True,
                mac_addr=vif['address'],
                dev_name=dev_name,
                slot_num=slot_num,
                ovs_bridge=vif['network']['bridge'],
                ovs_ext_ids=str(meta_attrs),
                configured_mtu=mtu)[0]
        else:
            # Bug : https://bugs.launchpad.net/nova-powervm/+bug/1731548
            # When a host is rebooted, something is discarding tap devices for
            # VMs deployed with OVS vif. To prevent VMs losing network
            # connectivity, this is fixed by recreating the tap devices during
            # init of the nova compute service, which will call vif plug with
            # new_vif==False.

            # Find the CNA for this vif.
            # TODO(svenkat) improve performance by caching VIOS wrapper(s) and
            # CNA lists (in case >1 vif per VM).
            cna_w_list = vm.get_cnas(self.adapter, self.instance)
            cna_w = self._find_cna_for_vif(cna_w_list, vif)
            # Find the corresponding trunk adapter
            trunks = pvm_cna.find_trunks(self.adapter, cna_w)
            for trunk in trunks:
                # Set MTU, OVS external ids, and OVS bridge metadata
                # TODO(svenkat) set_parm_value calls should be replaced once
                # pypowervm supports setting these values directly.
                trunk.set_parm_value('ConfiguredMTU',
                                     mtu,
                                     attrib=pvm_c.ATTR_KSV160)
                trunk.set_parm_value('OvsPortExternalIds',
                                     meta_attrs,
                                     attrib=pvm_c.ATTR_KSV160)
                trunk.set_parm_value('OvsBridge',
                                     vif['network']['bridge'],
                                     attrib=pvm_c.ATTR_KSV160)
                # Updating the trunk adapter will cause NovaLink to reassociate
                # the tap device.
                trunk.update()