def test_create_network_with_default_n1kv_vxlan_network_profile_id(
            self, restrict_network_profiles=False):
        """Test VxLAN network create without passing network profile id."""
        ml2_config.cfg.CONF.set_override('tenant_network_types',
                                         ['vxlan', 'vlan'], 'ml2')
        ml2_n1kv_config.cfg.CONF.set_override('restrict_network_profiles',
                                              restrict_network_profiles,
                                              'ml2_cisco_n1kv')
        np = n1kv_db.get_network_profile_by_name(
            n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)

        # assert that DB binding for the tenant and default VxLAN network
        # profile is absent
        self.assertRaises(n1kv_exc.ProfileTenantBindingNotFound,
                          n1kv_db.get_profile_binding, self._tenant_id, np.id)

        # test network create with non-admin tenant
        with self.network() as network:
            self.assertEqual(n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME,
                             np["name"])
            net_np = n1kv_db.get_network_binding(network['network']['id'])
            self.assertEqual(network['network']['id'], net_np['network_id'])
            self.assertEqual(np['id'], net_np['profile_id'])
            network_tenant_id = network['network']['tenant_id']
            self.assertEqual(self._tenant_id, network_tenant_id)

            # assert that API bindings also have tenant association
            # with the profile
            self.assert_profile_binding_exists(
                binding='network_profile_bindings',
                tenant_id=network_tenant_id,
                profile_id=np.id)
 def _get_network_collection_for_tenant(self, db_session, model, tenant_id):
     net_profile_ids = n1kv_db.get_profiles_for_tenant(
         db_session=db_session,
         tenant_id=tenant_id,
         profile_type=n1kv_const.NETWORK)
     # get default VLAN and VXLAN network profile objects
     default_vlan_profile = n1kv_db.get_network_profile_by_name(
         n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME)
     default_vxlan_profile = n1kv_db.get_network_profile_by_name(
         n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)
     # append IDs of default network profiles to the net_profile_ids list
     net_profile_ids.append(default_vlan_profile.id)
     net_profile_ids.append(default_vxlan_profile.id)
     network_profiles = (db_session.query(model).filter(model.id.in_(
         net_profile_ids)))
     return [self._make_network_profile_dict(p) for p in network_profiles]
예제 #3
0
 def _get_network_collection_for_tenant(self, db_session, model, tenant_id):
     net_profile_ids = n1kv_db.get_profiles_for_tenant(
         db_session=db_session,
         tenant_id=tenant_id,
         profile_type=n1kv_const.NETWORK)
     # get default VLAN and VXLAN network profile objects
     default_vlan_profile = n1kv_db.get_network_profile_by_name(
         n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME)
     default_vxlan_profile = n1kv_db.get_network_profile_by_name(
         n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)
     # append IDs of default network profiles to the net_profile_ids list
     net_profile_ids.append(default_vlan_profile.id)
     net_profile_ids.append(default_vxlan_profile.id)
     network_profiles = (db_session.query(model).filter(
         model.id.in_(net_profile_ids)))
     return [self._make_network_profile_dict(p) for p in network_profiles]
 def test_create_network_with_default_n1kv_vlan_network_profile_id(self):
     """Test VLAN network create without passing network profile id."""
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_name(n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME)
         self.assertEqual(n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME, np["name"])
         net_np = n1kv_db.get_network_binding(network["network"]["id"])
         self.assertEqual(network["network"]["id"], net_np["network_id"])
         self.assertEqual(net_np["profile_id"], np["id"])
 def test_create_network_with_default_n1kv_vxlan_network_profile_id(self):
     """Test VxLAN network create without passing network profile id."""
     ml2_config.cfg.CONF.set_override("tenant_network_types", ["vxlan", "vlan"], "ml2")
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_name(n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)
         self.assertEqual(n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME, np["name"])
         net_np = n1kv_db.get_network_binding(network["network"]["id"])
         self.assertEqual(network["network"]["id"], net_np["network_id"])
         self.assertEqual(net_np["profile_id"], np["id"])
예제 #6
0
 def test_create_network_with_default_n1kv_vlan_network_profile_id(self):
     """Test VLAN network create without passing network profile id."""
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_name(
             n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME)
         self.assertEqual(n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME,
                          np["name"])
         net_np = n1kv_db.get_network_binding(network['network']['id'])
         self.assertEqual(network['network']['id'], net_np['network_id'])
         self.assertEqual(net_np['profile_id'], np['id'])
예제 #7
0
 def test_create_network_with_default_n1kv_vxlan_network_profile_id(self):
     """Test VxLAN network create without passing network profile id."""
     ml2_config.cfg.CONF.set_override('tenant_network_types',
                                      ['vxlan', 'vlan'], 'ml2')
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_name(
             n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)
         self.assertEqual(n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME,
                          np["name"])
         net_np = n1kv_db.get_network_binding(network['network']['id'])
         self.assertEqual(network['network']['id'], net_np['network_id'])
         self.assertEqual(net_np['profile_id'], np['id'])
 def process_create_network(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     prov_net_type = data.get(providernet.NETWORK_TYPE)
     net_prof_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id
     if not bc_attr.is_attr_set(net_prof_attr):
         if not bc_attr.is_attr_set(prov_net_type):
             network_type = cfg.CONF.ml2.tenant_network_types[0]
         else:
             network_type = prov_net_type
         if network_type == p_const.TYPE_VLAN:
             net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME
         elif network_type == p_const.TYPE_VXLAN:
             net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME
         else:
             # This network type is not supported with network profiles
             return
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(net_prof_attr):
                 net_prof_attr = n1kv_db.get_network_profile_by_name(
                     net_prof_attr, context.session)
             else:
                 net_prof_attr = n1kv_db.get_network_profile_by_uuid(
                     net_prof_attr, context.session)
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=net_prof_attr.id)
         except n1kv_exc.NetworkProfileNotFound:
             LOG.error(_LE("Network Profile %s does "
                           "not exist.") % net_prof_attr)
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and
                     net_prof_attr.name not in [
                         constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME,
                         constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]):
                 LOG.error(_LE("Network Profile %s is "
                               "not owned by this tenant.") %
                           net_prof_attr.name)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         segment_type = net_prof_attr.segment_type
         n1kv_db.add_network_binding(net_id, segment_type,
                                     0,
                                     net_prof_attr.id,
                                     context.session)
         data[providernet.NETWORK_TYPE] = segment_type
     result[constants.N1KV_PROFILE] = net_prof_attr.id
 def process_create_network(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     prov_net_type = data.get(bc.providernet.NETWORK_TYPE)
     net_prof_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id
     if not bc.is_attr_set(net_prof_attr):
         if not bc.is_attr_set(prov_net_type):
             network_type = cfg.CONF.ml2.tenant_network_types[0]
         else:
             network_type = prov_net_type
         if network_type == p_const.TYPE_VLAN:
             net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME
         elif network_type == p_const.TYPE_VXLAN:
             net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME
         else:
             # This network type is not supported with network profiles
             return
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(net_prof_attr):
                 net_prof_attr = n1kv_db.get_network_profile_by_name(
                     net_prof_attr, context.session)
             else:
                 net_prof_attr = n1kv_db.get_network_profile_by_uuid(
                     net_prof_attr, context.session)
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=net_prof_attr.id)
         except n1kv_exc.NetworkProfileNotFound:
             LOG.error("Network Profile %s does "
                       "not exist." % net_prof_attr)
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and
                     net_prof_attr.name not in [
                         constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME,
                         constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]):
                 LOG.error("Network Profile %s is "
                           "not owned by this tenant." %
                           net_prof_attr.name)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         segment_type = net_prof_attr.segment_type
         n1kv_db.add_network_binding(net_id, segment_type,
                                     0,
                                     net_prof_attr.id,
                                     context.session)
         data[bc.providernet.NETWORK_TYPE] = segment_type
     result[constants.N1KV_PROFILE] = net_prof_attr.id
 def _ensure_network_profiles_created_on_vsm(self):
     # Try to create logical networks and network profiles on the VSM if
     # they don't exist already.
     for netp_type in [p_const.TYPE_VLAN, p_const.TYPE_VXLAN]:
         try:
             netp = n1kv_db.get_network_profile_by_name(
                 self.netp_name[netp_type])
         except n1kv_exc.NetworkProfileNotFound:
             if netp_type == p_const.TYPE_VXLAN:
                 sub_type = n1kv_const.CLI_VXLAN_MODE_ENHANCED
             else:
                 sub_type = None
             # Create a network profile in Neutron DB
             netp = n1kv_db.add_network_profile(self.netp_name[netp_type],
                                                netp_type, sub_type)
             try:
                 # Create a network profile on the VSM
                 self.n1kvclient.create_network_segment_pool(netp)
             # Catch any exception here and cleanup if so
             except (n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError):
                 with excutils.save_and_reraise_exception():
                     n1kv_db.remove_network_profile(netp.id)
예제 #11
0
 def _ensure_network_profiles_created_on_vsm(self):
     # Try to create logical networks and network profiles on the VSM if
     # they don't exist already.
     for netp_type in [p_const.TYPE_VLAN, p_const.TYPE_VXLAN]:
         try:
             netp = n1kv_db.get_network_profile_by_name(
                 self.netp_name[netp_type])
         except n1kv_exc.NetworkProfileNotFound:
             if netp_type == p_const.TYPE_VXLAN:
                 sub_type = n1kv_const.CLI_VXLAN_MODE_ENHANCED
             else:
                 sub_type = None
             # Create a network profile in Neutron DB
             netp = n1kv_db.add_network_profile(self.netp_name[netp_type],
                                                netp_type, sub_type)
             try:
                 # Create a network profile on the VSM
                 self.n1kvclient.create_network_segment_pool(netp)
             # Catch any exception here and cleanup if so
             except (n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError):
                 with excutils.save_and_reraise_exception():
                     n1kv_db.remove_network_profile(netp.id)
 def process_create_network(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     prov_net_type = data.get(providernet.NETWORK_TYPE)
     net_prof_attr = data.get(constants.N1KV_PROFILE)
     if not attributes.is_attr_set(net_prof_attr):
         if not attributes.is_attr_set(prov_net_type):
             network_type = cfg.CONF.ml2.tenant_network_types[0]
         else:
             network_type = prov_net_type
         if network_type == p_const.TYPE_VLAN:
             net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME
         elif network_type == p_const.TYPE_VXLAN:
             net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME
         else:
             # This network type is not supported with network profiles
             return
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(net_prof_attr):
                 net_prof_attr = n1kv_db.get_network_profile_by_name(
                     net_prof_attr, context.session)
             else:
                 net_prof_attr = n1kv_db.get_network_profile_by_uuid(
                     net_prof_attr, context.session)
             # TODO(sopatwar) Handle restrict_network_profiles = True
             # Add logic to check for network profile :: tenant binding
         except n1kv_exc.NetworkProfileNotFound:
             LOG.error(_LE("Network Profile %(profile)s does "
                           "not exist."), {"profile":
                            net_prof_attr})
             raise ml2_exc.ExtensionDriverError()
         segment_type = net_prof_attr.segment_type
         n1kv_db.add_network_binding(net_id, segment_type,
                                     0,
                                     net_prof_attr.id,
                                     context.session)
         data[providernet.NETWORK_TYPE] = segment_type
     result[constants.N1KV_PROFILE] = net_prof_attr.id
    def test_create_network_with_default_n1kv_vlan_network_profile_id(self, restrict_network_profiles=False):
        """Test VLAN network create without passing network profile id."""
        ml2_n1kv_config.cfg.CONF.set_override("restrict_network_profiles", restrict_network_profiles, "ml2_cisco_n1kv")
        np = n1kv_db.get_network_profile_by_name(n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME)

        # assert that DB binding for the tenant and default VLAN network
        # profile is absent
        self.assertRaises(n1kv_exc.ProfileTenantBindingNotFound, n1kv_db.get_profile_binding, self._tenant_id, np.id)

        # test network creation with non-admin tenant
        with self.network() as network:
            self.assertEqual(n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME, np["name"])
            net_np = n1kv_db.get_network_binding(network["network"]["id"])
            self.assertEqual(network["network"]["id"], net_np["network_id"])
            self.assertEqual(np["id"], net_np["profile_id"])
            network_tenant_id = network["network"]["tenant_id"]
            self.assertEqual(self._tenant_id, network_tenant_id)

            # assert that API bindings have tenant association
            # with the profile
            self.assert_profile_binding_exists(
                binding="network_profile_bindings", tenant_id=network_tenant_id, profile_id=np.id
            )