def test_add_and_get_multiple_network_bindings_mix(self):
     with self.network() as network1:
         with self.network() as network2:
             TEST_NETWORK_ID1 = network1['network']['id']
             TEST_NETWORK_ID2 = network2['network']['id']
             self.assertRaises(c_exc.NetworkBindingNotFound,
                               n1kv_db.get_network_binding,
                               TEST_NETWORK_ID1)
             self.assertRaises(c_exc.NetworkBindingNotFound,
                               n1kv_db.get_network_binding,
                               TEST_NETWORK_ID2)
             p = _create_test_network_profile_if_not_there(self.session)
             p2 = _create_test_vxlan_network_profile_if_not_there(
                 self.session)
             n1kv_db.add_network_binding(TEST_NETWORK_ID1,
                                         p_const.TYPE_VXLAN, 1234, p2.id)
             binding = n1kv_db.get_network_binding(TEST_NETWORK_ID1)
             self.assertIsNotNone(binding)
             self.assertEqual(binding.network_id, TEST_NETWORK_ID1)
             self.assertEqual(binding.network_type, p_const.TYPE_VXLAN)
             n1kv_db.add_network_binding(TEST_NETWORK_ID2,
                                         p_const.TYPE_VLAN, 1235, p.id)
             binding = n1kv_db.get_network_binding(TEST_NETWORK_ID2)
             self.assertIsNotNone(binding)
             self.assertEqual(TEST_NETWORK_ID2, binding.network_id)
             self.assertEqual(p_const.TYPE_VLAN, binding.network_type)
             self.assertEqual(1235, binding.segmentation_id)
Ejemplo n.º 2
0
 def test_add_and_get_multiple_network_bindings_mix(self):
     with self.network() as network1:
         with self.network() as network2:
             TEST_NETWORK_ID1 = network1['network']['id']
             TEST_NETWORK_ID2 = network2['network']['id']
             self.assertRaises(c_exc.NetworkBindingNotFound,
                               n1kv_db.get_network_binding,
                               TEST_NETWORK_ID1)
             self.assertRaises(c_exc.NetworkBindingNotFound,
                               n1kv_db.get_network_binding,
                               TEST_NETWORK_ID2)
             p = _create_test_network_profile_if_not_there(self.session)
             p2 = _create_test_vxlan_network_profile_if_not_there(
                 self.session)
             n1kv_db.add_network_binding(
                 TEST_NETWORK_ID1, p_const.TYPE_VXLAN,
                 1234, p2.id)
             binding = n1kv_db.get_network_binding(TEST_NETWORK_ID1)
             self.assertIsNotNone(binding)
             self.assertEqual(binding.network_id, TEST_NETWORK_ID1)
             self.assertEqual(binding.network_type,
                              p_const.TYPE_VXLAN)
             n1kv_db.add_network_binding(
                 TEST_NETWORK_ID2, p_const.TYPE_VLAN,
                 1235, p.id)
             binding = n1kv_db.get_network_binding(TEST_NETWORK_ID2)
             self.assertIsNotNone(binding)
             self.assertEqual(TEST_NETWORK_ID2, binding.network_id)
             self.assertEqual(p_const.TYPE_VLAN,
                              binding.network_type)
             self.assertEqual(1235, binding.segmentation_id)
    def test_add_and_get_network_binding_vxlan(self):
        with self.network() as network:
            TEST_NETWORK_ID = network['network']['id']
            self.assertRaises(c_exc.NetworkBindingNotFound,
                              n1kv_db.get_network_binding, TEST_NETWORK_ID)

            p = _create_test_vxlan_network_profile_if_not_there(self.session)
            n1kv_db.add_network_binding(TEST_NETWORK_ID, p_const.TYPE_VXLAN,
                                        1234, p.id)
            binding = n1kv_db.get_network_binding(TEST_NETWORK_ID)
            self.assertIsNotNone(binding)
            self.assertEqual(TEST_NETWORK_ID, binding.network_id)
            self.assertEqual(p_const.TYPE_VXLAN, binding.network_type)
            self.assertEqual(1234, binding.segmentation_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
Ejemplo n.º 6
0
    def test_add_and_get_network_binding_vxlan(self):
        with self.network() as network:
            TEST_NETWORK_ID = network['network']['id']
            self.assertRaises(c_exc.NetworkBindingNotFound,
                              n1kv_db.get_network_binding,
                              TEST_NETWORK_ID)

            p = _create_test_vxlan_network_profile_if_not_there(self.session)
            n1kv_db.add_network_binding(
                TEST_NETWORK_ID, p_const.TYPE_VXLAN,
                1234, p.id)
            binding = n1kv_db.get_network_binding(TEST_NETWORK_ID)
            self.assertIsNotNone(binding)
            self.assertEqual(TEST_NETWORK_ID, binding.network_id)
            self.assertEqual(p_const.TYPE_VXLAN, binding.network_type)
            self.assertEqual(1234, binding.segmentation_id)
    def create_network_precommit(self, context):
        """Update network binding information."""
        network = context.current
        segment = context.network_segments[0]
        network_type = segment['network_type']
        session = context._plugin_context.session
        # NoOp for unsupported network types
        if not self._is_segment_valid_for_n1kv(segment['segmentation_id'],
                                               network_type):
            return
        # Retrieve the network profile for network binding
        try:
            netp = n1kv_db.get_network_profile_by_type(network_type, session)
        except n1kv_exc.NetworkProfileNotFound:
            raise ml2_exc.MechanismDriverError()

        kwargs = {"network_id": network['id'],
                  "network_type": network_type,
                  "db_session": session,
                  "segment_id": segment['segmentation_id'],
                  "netp_id": netp['id']}
        n1kv_db.add_network_binding(**kwargs)
 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
Ejemplo n.º 9
0
    def create_network_precommit(self, context):
        """Update network binding information."""
        network = context.current
        segment = context.network_segments[0]
        network_type = segment['network_type']
        session = context._plugin_context.session
        # NoOp for unsupported network types
        if not self._is_segment_valid_for_n1kv(segment['segmentation_id'],
                                               network_type):
            return
        # Retrieve the network profile for network binding
        try:
            netp = n1kv_db.get_network_profile_by_type(network_type, session)
        except n1kv_exc.NetworkProfileNotFound:
            raise ml2_exc.MechanismDriverError()

        kwargs = {
            "network_id": network['id'],
            "network_type": network_type,
            "db_session": session,
            "segment_id": segment['segmentation_id'],
            "netp_id": netp['id']
        }
        n1kv_db.add_network_binding(**kwargs)