コード例 #1
0
ファイル: test_switch.py プロジェクト: greynolds123/neutron
 def test_create_and_get_port(self):
     lswitch, lport = self._create_switch_and_port()
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'])
     self.assertEqual(lport['uuid'], lport_res['uuid'])
     # Try again with relation
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'],
                                    relations='LogicalPortStatus')
     self.assertEqual(lport['uuid'], lport_res['uuid'])
コード例 #2
0
 def test_create_port_device_id_more_than_40_chars(self):
     dev_id = "this_is_a_very_long_device_id_with_lots_of_characters"
     lswitch, lport = self._create_switch_and_port(device_id=dev_id)
     lport_res = switchlib.get_port(self.fake_cluster, lswitch['uuid'],
                                    lport['uuid'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertNotEqual(len(dev_id), len(port_tags['vm_id']))
コード例 #3
0
 def test_plug_interface(self):
     lswitch, lport = self._create_switch_and_port()
     switchlib.plug_vif_interface(self.fake_cluster, lswitch['uuid'],
                                  lport['uuid'], 'VifAttachment', 'fake')
     lport_res = switchlib.get_port(self.fake_cluster, lswitch['uuid'],
                                    lport['uuid'])
     self.assertEqual(lport['uuid'], lport_res['uuid'])
コード例 #4
0
 def test_create_port_device_id_more_than_40_chars(self):
     dev_id = "this_is_a_very_long_device_id_with_lots_of_characters"
     lswitch, lport = self._create_switch_and_port(device_id=dev_id)
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertNotEqual(len(dev_id), len(port_tags['vm_id']))
コード例 #5
0
 def test_plug_interface(self):
     lswitch, lport = self._create_switch_and_port()
     switchlib.plug_vif_interface(self.fake_cluster, lswitch['uuid'],
                                  lport['uuid'], 'VifAttachment', 'fake')
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'])
     self.assertEqual(lport['uuid'], lport_res['uuid'])
コード例 #6
0
    def synchronize_port(self,
                         context,
                         neutron_port_data,
                         lswitchport=None,
                         ext_networks=None):
        """Synchronize a Neutron port with its NVP counterpart."""
        # Skip synchronization for ports on external networks
        if not ext_networks:
            ext_networks = [
                net['id']
                for net in context.session.query(models_v2.Network).join(
                    external_net_db.ExternalNetwork, (
                        models_v2.Network.id ==
                        external_net_db.ExternalNetwork.network_id))
            ]
        if neutron_port_data['network_id'] in ext_networks:
            with context.session.begin(subtransactions=True):
                neutron_port_data['status'] = constants.PORT_STATUS_ACTIVE
                return

        if not lswitchport:
            # Try to get port from nvp
            try:
                ls_uuid, lp_uuid = nsx_utils.get_nsx_switch_and_port_id(
                    context.session, self._cluster, neutron_port_data['id'])
                if lp_uuid:
                    lswitchport = switchlib.get_port(
                        self._cluster,
                        ls_uuid,
                        lp_uuid,
                        relations='LogicalPortStatus')
            except (exceptions.PortNotFoundOnNetwork):
                # NOTE(salv-orlando): We should be catching
                # NvpApiClient.ResourceNotFound here instead
                # of PortNotFoundOnNetwork when the id exists but
                # the logical switch port was not found
                LOG.warning(
                    _("Logical switch port for neutron port %s "
                      "not found on NVP."), neutron_port_data['id'])
                lswitchport = None
            else:
                # If lswitchport is not None, update the cache.
                # It could be none if the port was deleted from the backend
                if lswitchport:
                    self._nvp_cache.update_lswitchport(lswitchport)
        # Note(salv-orlando): It might worth adding a check to verify neutron
        # resource tag in nvp entity matches Neutron id.
        # By default assume things go wrong
        status = constants.PORT_STATUS_ERROR
        if lswitchport:
            lp_status = (lswitchport['_relations']['LogicalPortStatus']
                         ['link_status_up'])
            status = (lp_status and constants.PORT_STATUS_ACTIVE
                      or constants.PORT_STATUS_DOWN)
        # Update db object
        self._update_neutron_object(context, neutron_port_data, status)
コード例 #7
0
ファイル: router.py プロジェクト: yuhui7red/neutron
def delete_peer_router_lport(cluster, lr_uuid, ls_uuid, lp_uuid):
    nsx_port = get_port(cluster, ls_uuid, lp_uuid,
                        relations="LogicalPortAttachment")
    relations = nsx_port.get('_relations')
    if relations:
        att_data = relations.get('LogicalPortAttachment')
        if att_data:
            lrp_uuid = att_data.get('peer_port_uuid')
            if lrp_uuid:
                delete_router_lport(cluster, lr_uuid, lrp_uuid)
コード例 #8
0
def delete_peer_router_lport(cluster, lr_uuid, ls_uuid, lp_uuid):
    nsx_port = get_port(cluster,
                        ls_uuid,
                        lp_uuid,
                        relations="LogicalPortAttachment")
    relations = nsx_port.get('_relations')
    if relations:
        att_data = relations.get('LogicalPortAttachment')
        if att_data:
            lrp_uuid = att_data.get('peer_port_uuid')
            if lrp_uuid:
                delete_router_lport(cluster, lr_uuid, lrp_uuid)
コード例 #9
0
 def test_update_port(self):
     lswitch, lport = self._create_switch_and_port()
     switchlib.update_port(self.fake_cluster, lswitch['uuid'],
                           lport['uuid'], 'neutron_port_id', 'pippo2',
                           'new_name', 'device_id', False)
     lport_res = switchlib.get_port(self.fake_cluster, lswitch['uuid'],
                                    lport['uuid'])
     self.assertEqual(lport['uuid'], lport_res['uuid'])
     self.assertEqual('new_name', lport_res['display_name'])
     self.assertEqual('False', lport_res['admin_status_enabled'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertIn('os_tid', port_tags)
     self.assertIn('q_port_id', port_tags)
     self.assertIn('vm_id', port_tags)
コード例 #10
0
 def test_update_port(self):
     lswitch, lport = self._create_switch_and_port()
     switchlib.update_port(
         self.fake_cluster, lswitch['uuid'], lport['uuid'],
         'neutron_port_id', 'pippo2', 'new_name', 'device_id', False)
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'])
     self.assertEqual(lport['uuid'], lport_res['uuid'])
     self.assertEqual('new_name', lport_res['display_name'])
     self.assertEqual('False', lport_res['admin_status_enabled'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertIn('os_tid', port_tags)
     self.assertIn('q_port_id', port_tags)
     self.assertIn('vm_id', port_tags)
コード例 #11
0
ファイル: sync.py プロジェクト: yuhui7red/neutron
    def synchronize_port(self, context, neutron_port_data,
                         lswitchport=None, ext_networks=None):
        """Synchronize a Neutron port with its NVP counterpart."""
        # Skip synchronization for ports on external networks
        if not ext_networks:
            ext_networks = [net['id'] for net in context.session.query(
                models_v2.Network).join(
                    external_net_db.ExternalNetwork,
                    (models_v2.Network.id ==
                     external_net_db.ExternalNetwork.network_id))]
        if neutron_port_data['network_id'] in ext_networks:
            with context.session.begin(subtransactions=True):
                neutron_port_data['status'] = constants.PORT_STATUS_ACTIVE
                return

        if not lswitchport:
            # Try to get port from nvp
            try:
                ls_uuid, lp_uuid = nsx_utils.get_nsx_switch_and_port_id(
                    context.session, self._cluster, neutron_port_data['id'])
                if lp_uuid:
                    lswitchport = switchlib.get_port(
                        self._cluster, ls_uuid, lp_uuid,
                        relations='LogicalPortStatus')
            except (exceptions.PortNotFoundOnNetwork):
                # NOTE(salv-orlando): We should be catching
                # NvpApiClient.ResourceNotFound here instead
                # of PortNotFoundOnNetwork when the id exists but
                # the logical switch port was not found
                LOG.warning(_("Logical switch port for neutron port %s "
                              "not found on NVP."), neutron_port_data['id'])
                lswitchport = None
            else:
                # If lswitchport is not None, update the cache.
                # It could be none if the port was deleted from the backend
                if lswitchport:
                    self._nvp_cache.update_lswitchport(lswitchport)
        # Note(salv-orlando): It might worth adding a check to verify neutron
        # resource tag in nvp entity matches Neutron id.
        # By default assume things go wrong
        status = constants.PORT_STATUS_ERROR
        if lswitchport:
            lp_status = (lswitchport['_relations']
                         ['LogicalPortStatus']
                         ['link_status_up'])
            status = (lp_status and
                      constants.PORT_STATUS_ACTIVE
                      or constants.PORT_STATUS_DOWN)
        # Update db object
        self._update_neutron_object(context, neutron_port_data, status)
コード例 #12
0
 def test_create_port_device_id_less_than_40_chars(self):
     lswitch, lport = self._create_switch_and_port()
     lport_res = switchlib.get_port(self.fake_cluster, lswitch['uuid'],
                                    lport['uuid'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertEqual('device_id', port_tags['vm_id'])
コード例 #13
0
 def test_create_port_device_id_less_than_40_chars(self):
     lswitch, lport = self._create_switch_and_port()
     lport_res = switchlib.get_port(self.fake_cluster,
                                    lswitch['uuid'], lport['uuid'])
     port_tags = self._build_tag_dict(lport_res['tags'])
     self.assertEqual('device_id', port_tags['vm_id'])