Example #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')
Example #2
0
 def _handle_lswitch_selection(self, cluster, network,
                               network_binding, max_ports,
                               allow_extra_lswitches):
     lswitches = nvplib.get_lswitches(cluster, network.id)
     try:
         # TODO find main_ls too!
         return [ls for ls in lswitches
                 if (ls['_relations']['LogicalSwitchStatus']
                     ['lport_count'] < max_ports)].pop(0)
     except IndexError:
         # Too bad, no switch available
         LOG.debug(_("No switch has available ports (%d checked)"),
                   len(lswitches))
     if allow_extra_lswitches:
         main_ls = [ls for ls in lswitches if ls['uuid'] == network.id]
         tag_dict = dict((x['scope'], x['tag']) for x in main_ls[0]['tags'])
         if 'multi_lswitch' not in tag_dict:
             nvplib.update_lswitch(cluster,
                                   main_ls[0]['uuid'],
                                   main_ls[0]['display_name'],
                                   network['tenant_id'],
                                   tags=[{'tag': 'True',
                                          'scope': 'multi_lswitch'}])
         selected_lswitch = nvplib.create_lswitch(
             cluster, network.tenant_id,
             "%s-ext-%s" % (network.name, len(lswitches)),
             network_binding.binding_type,
             network_binding.tz_uuid,
             network_binding.vlan_id,
             network.id)
         return selected_lswitch
     else:
         LOG.error(_("Maximum number of logical ports reached for "
                     "logical network %s"), network.id)
         raise nvp_exc.NvpNoMorePortsException(network=network.id)
Example #3
0
    def create_network(self, context, network):
        net_data = network['network'].copy()
        # Process the provider network extension
        self._handle_provider_create(context, net_data)
        # Replace ATTR_NOT_SPECIFIED with None before sending to NVP
        for attr, value in network['network'].iteritems():
            if value is attributes.ATTR_NOT_SPECIFIED:
                net_data[attr] = None
        # FIXME(arosen) implement admin_state_up = False in NVP
        if net_data['admin_state_up'] is False:
            LOG.warning(_("Network with admin_state_up=False are not yet "
                          "supported by this plugin. Ignoring setting for "
                          "network %s"), net_data.get('name', '<unknown>'))
        tenant_id = self._get_tenant_id_for_create(context, net_data)
        target_cluster = self._find_target_cluster(net_data)
        lswitch = nvplib.create_lswitch(target_cluster,
                                        tenant_id,
                                        net_data.get('name'),
                                        net_data.get(pnet.NETWORK_TYPE),
                                        net_data.get(pnet.PHYSICAL_NETWORK),
                                        net_data.get(pnet.SEGMENTATION_ID))
        network['network']['id'] = lswitch['uuid']

        with context.session.begin(subtransactions=True):
            new_net = super(NvpPluginV2, self).create_network(context,
                                                              network)
            if net_data.get(pnet.NETWORK_TYPE):
                net_binding = nicira_db.add_network_binding(
                    context.session, new_net['id'],
                    net_data.get(pnet.NETWORK_TYPE),
                    net_data.get(pnet.PHYSICAL_NETWORK),
                    net_data.get(pnet.SEGMENTATION_ID))
                self._extend_network_dict_provider(context, new_net,
                                                   net_binding)
        return new_net
Example #4
0
 def test_get_port_by_tag_not_found_returns_None(self):
     tenant_id = 'pippo'
     quantum_port_id = 'whatever'
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     lport = nvplib.get_port_by_quantum_tag(self.fake_cluster,
                                            lswitch['uuid'],
                                            quantum_port_id)
     self.assertIsNone(lport)
Example #5
0
 def test_get_port_by_tag_not_found_returns_None(self):
     tenant_id = 'pippo'
     quantum_port_id = 'whatever'
     lswitch = nvplib.create_lswitch(self.fake_cluster, tenant_id,
                                     'fake-switch')
     lport = nvplib.get_port_by_quantum_tag(self.fake_cluster,
                                            lswitch['uuid'],
                                            quantum_port_id)
     self.assertIsNone(lport)
Example #6
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'])
Example #7
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'])
Example #8
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')