Exemplo n.º 1
0
 def test_plug_l2_gw_port_attachment(self):
     tenant_id = 'pippo'
     node_uuid = _uuid()
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     gw_id = self._create_gw_service(node_uuid, 'fake-gw')['uuid']
     lport = nvplib.create_lport(self.fake_cluster,
                                 lswitch['uuid'],
                                 tenant_id,
                                 _uuid(),
                                 'fake-gw-port',
                                 gw_id,
                                 True)
     json.loads(nvplib.plug_l2_gw_service(self.fake_cluster,
                                          lswitch['uuid'],
                                          lport['uuid'],
                                          gw_id))
     uri = nvplib._build_uri_path(nvplib.LSWITCHPORT_RESOURCE,
                                  lport['uuid'],
                                  lswitch['uuid'],
                                  is_attachment=True)
     resp_obj = json.loads(
         nvplib.do_single_request("GET", uri,
                                  cluster=self.fake_cluster))
     self.assertIn('LogicalPortAttachment', resp_obj)
     self.assertEqual(resp_obj['LogicalPortAttachment']['type'],
                      'L2GatewayAttachment')
Exemplo n.º 2
0
    def create_port(self, context, port):
        with context.session.begin(subtransactions=True):
            # First we allocate port in quantum database
            quantum_db = super(NvpPluginV2, self).create_port(context, port)
            # Update fields obtained from quantum db (eg: MAC address)
            port["port"].update(quantum_db)
            port_data = port['port']
            # Fetch the network and network binding from Quantum db
            network = self._get_network(context, port_data['network_id'])
            network_binding = nicira_db.get_network_binding(
                context.session, port_data['network_id'])
            max_ports = self.nvp_opts.max_lp_per_overlay_ls
            allow_extra_lswitches = False
            if (network_binding and
                network_binding.binding_type in (NetworkTypes.FLAT,
                                                 NetworkTypes.VLAN)):
                max_ports = self.nvp_opts.max_lp_per_bridged_ls
                allow_extra_lswitches = True
            try:
                q_net_id = port_data['network_id']
                cluster = self._find_target_cluster(port_data)
                selected_lswitch = self._handle_lswitch_selection(
                    cluster, network, network_binding, max_ports,
                    allow_extra_lswitches)
                lswitch_uuid = selected_lswitch['uuid']
                lport = nvplib.create_lport(cluster,
                                            lswitch_uuid,
                                            port_data['tenant_id'],
                                            port_data['id'],
                                            port_data['name'],
                                            port_data['device_id'],
                                            port_data['admin_state_up'],
                                            port_data['mac_address'],
                                            port_data['fixed_ips'])
                # Get NVP ls uuid for quantum network
                nvplib.plug_interface(cluster, selected_lswitch['uuid'],
                                      lport['uuid'], "VifAttachment",
                                      port_data['id'])
            except nvp_exc.NvpNoMorePortsException as e:
                LOG.error(_("Number of available ports for network %s "
                            "exhausted"), port_data['network_id'])
                raise e
            except Exception:
                # failed to create port in NVP delete port from quantum_db
                # FIXME (arosen) or the plugin_interface call failed in which
                # case we need to garbage collect the left over port in nvp.
                err_msg = _("An exception occured while plugging the interface"
                            " in NVP for port %s") % port_data['id']
                LOG.exception(err_msg)
                raise nvp_exc.NvpPluginException(err_desc=err_msg)

            LOG.debug(_("create_port completed on NVP for tenant "
                        "%(tenant_id)s: (%(id)s)"), port_data)

            return port_data
Exemplo n.º 3
0
 def test_get_port_by_tag(self):
     tenant_id = 'pippo'
     quantum_port_id = 'whatever'
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     lport = nvplib.create_lport(self.fake_cluster, lswitch['uuid'],
                                 tenant_id, quantum_port_id, 'name',
                                 'device_id', True)
     lport2 = nvplib.get_port_by_quantum_tag(self.fake_cluster,
                                             lswitch['uuid'],
                                             quantum_port_id)
     self.assertIsNotNone(lport2)
     self.assertEqual(lport['uuid'], lport2['uuid'])
Exemplo n.º 4
0
 def test_get_port_by_tag(self):
     tenant_id = 'pippo'
     quantum_port_id = 'whatever'
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     lport = nvplib.create_lport(self.fake_cluster, lswitch['uuid'],
                                 tenant_id, quantum_port_id,
                                 'name', 'device_id', True)
     lport2 = nvplib.get_port_by_quantum_tag(self.fake_cluster,
                                             lswitch['uuid'],
                                             quantum_port_id)
     self.assertIsNotNone(lport2)
     self.assertEqual(lport['uuid'], lport2['uuid'])
Exemplo n.º 5
0
 def test_plug_l2_gw_port_attachment(self):
     tenant_id = 'pippo'
     node_uuid = _uuid()
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     gw_id = self._create_gw_service(node_uuid, 'fake-gw')['uuid']
     lport = nvplib.create_lport(self.fake_cluster, lswitch['uuid'],
                                 tenant_id, _uuid(), 'fake-gw-port', gw_id,
                                 True)
     json.loads(
         nvplib.plug_l2_gw_service(self.fake_cluster, lswitch['uuid'],
                                   lport['uuid'], gw_id))
     uri = nvplib._build_uri_path(nvplib.LSWITCHPORT_RESOURCE,
                                  lport['uuid'],
                                  lswitch['uuid'],
                                  is_attachment=True)
     resp_obj = json.loads(
         nvplib.do_single_request("GET", uri, cluster=self.fake_cluster))
     self.assertIn('LogicalPortAttachment', resp_obj)
     self.assertEqual(resp_obj['LogicalPortAttachment']['type'],
                      'L2GatewayAttachment')
Exemplo n.º 6
0
    def create_port(self, context, port):
        # If PORTSECURITY is not the default value ATTR_NOT_SPECIFIED
        # then we pass the port to the policy engine. The reason why we don't
        # pass the value to the policy engine when the port is
        # ATTR_NOT_SPECIFIED is for the case where a port is created on a
        # shared network that is not owned by the tenant.
        # TODO(arosen) fix policy engine to do this for us automatically.
        if attributes.is_attr_set(port['port'].get(psec.PORTSECURITY)):
            self._enforce_set_auth(context, port,
                                   self.port_security_enabled_create)
        port_data = port['port']
        with context.session.begin(subtransactions=True):
            # First we allocate port in quantum database
            quantum_db = super(NvpPluginV2, self).create_port(context, port)
            # Update fields obtained from quantum db (eg: MAC address)
            port["port"].update(quantum_db)

            # port security extension checks
            (port_security, has_ip) = self._determine_port_security_and_has_ip(
                context, port_data)
            port_data[psec.PORTSECURITY] = port_security
            self._process_port_security_create(context, port_data)
            # provider networking extension checks
            # Fetch the network and network binding from Quantum db
            network = self._get_network(context, port_data['network_id'])
            network_binding = nicira_db.get_network_binding(
                context.session, port_data['network_id'])
            max_ports = self.nvp_opts.max_lp_per_overlay_ls
            allow_extra_lswitches = False
            if (network_binding and
                network_binding.binding_type in (NetworkTypes.FLAT,
                                                 NetworkTypes.VLAN)):
                max_ports = self.nvp_opts.max_lp_per_bridged_ls
                allow_extra_lswitches = True
            try:
                q_net_id = port_data['network_id']
                cluster = self._find_target_cluster(port_data)
                selected_lswitch = self._handle_lswitch_selection(
                    cluster, network, network_binding, max_ports,
                    allow_extra_lswitches)
                lswitch_uuid = selected_lswitch['uuid']
                lport = nvplib.create_lport(cluster,
                                            lswitch_uuid,
                                            port_data['tenant_id'],
                                            port_data['id'],
                                            port_data['name'],
                                            port_data['device_id'],
                                            port_data['admin_state_up'],
                                            port_data['mac_address'],
                                            port_data['fixed_ips'],
                                            port_data[psec.PORTSECURITY])
                # Get NVP ls uuid for quantum network
                nvplib.plug_interface(cluster, selected_lswitch['uuid'],
                                      lport['uuid'], "VifAttachment",
                                      port_data['id'])
            except nvp_exc.NvpNoMorePortsException as e:
                LOG.error(_("Number of available ports for network %s "
                            "exhausted"), port_data['network_id'])
                raise e
            except Exception:
                # failed to create port in NVP delete port from quantum_db
                # FIXME (arosen) or the plugin_interface call failed in which
                # case we need to garbage collect the left over port in nvp.
                err_msg = _("An exception occured while plugging the interface"
                            " in NVP for port %s") % port_data['id']
                LOG.exception(err_msg)
                raise nvp_exc.NvpPluginException(err_desc=err_msg)

            LOG.debug(_("create_port completed on NVP for tenant "
                        "%(tenant_id)s: (%(id)s)"), port_data)

            self._extend_port_port_security_dict(context, port_data)
        return port_data