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)
Exemplo 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_create_network_with_admin_defined_overlay_network_profile_name(self):
        """
        Test network create with admin defined VxLAN network profile
        name.

        """
        data = self.get_test_network_profile_dict(
            segment_type="vxlan", sub_type="enhanced", multicast_ip_range="224.1.1.1-224.1.1.10"
        )
        net_prof = self.network_profile(data)
        net_prof_name = net_prof["network_profile"]["name"]
        net_prof_id = net_prof["network_profile"]["id"]
        res = self._create_network(
            self.fmt,
            name="vxlan-net",
            admin_state_up=True,
            arg_list=("n1kv:profile",),
            **{n1kv_const.N1KV_PROFILE: net_prof_name}
        )
        self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
        network = self.deserialize(self.fmt, res)
        net_np = n1kv_db.get_network_binding(network["network"]["id"])
        self.assertEqual(net_prof_id, network["network"][n1kv_const.N1KV_PROFILE])
        self.assertEqual(net_np["network_id"], network["network"]["id"])
        self.assertEqual(net_np["profile_id"], net_prof_id)
    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 test_create_network_with_admin_defined_overlay_network_profile_name(
            self):
        """
        Test network create with admin defined VxLAN network profile
        name.

        """
        data = self.get_test_network_profile_dict(
            segment_type='vxlan',
            sub_type='enhanced',
            multicast_ip_range="224.1.1.1-224.1.1.10")
        net_profile = self.create_assert_network_profile_success(data)
        net_prof_name = net_profile['network_profile']['name']
        net_prof_id = net_profile['network_profile']['id']

        res = self._create_network(self.fmt,
                                   name='vxlan-net',
                                   admin_state_up=True,
                                   arg_list=('n1kv:profile', ),
                                   **{n1kv_const.N1KV_PROFILE: net_prof_name})
        self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
        network = self.deserialize(self.fmt, res)
        net_np = n1kv_db.get_network_binding(network['network']['id'])
        self.assertEqual(net_prof_id,
                         network['network'][n1kv_const.N1KV_PROFILE])
        self.assertEqual(net_np['network_id'], network['network']['id'])
        self.assertEqual(net_np['profile_id'], net_prof_id)
 def create_network_postcommit(self, context):
     """Send network parameters to the VSM."""
     network = context.current
     segment = context.network_segments[0]
     network_type = segment['network_type']
     # NoOp for unsupported network types
     if not self._is_segment_valid_for_n1kv(segment['segmentation_id'],
                                            network_type):
         return
     session = context._plugin_context.session
     binding = n1kv_db.get_network_binding(network['id'], session)
     netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id, session)
     network[providernet.SEGMENTATION_ID] = binding.segmentation_id
     try:
         self.n1kvclient.create_network_segment(network, netp)
     except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
         raise ml2_exc.MechanismDriverError()
     LOG.info(
         _LI("Create network(postcommit) succeeded for network: "
             "%(network_id)s of type: %(network_type)s with segment "
             "id: %(segment_id)s"), {
                 "network_id": network['id'],
                 "network_type": network_type,
                 "segment_id": segment['segmentation_id']
             })
Exemplo n.º 7
0
 def test_create_network_with_default_n1kv_network_profile_id(self):
     """Test network create without passing network profile id."""
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_type(p_const.TYPE_VLAN)
         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_network_profile_id(self):
     """Test network create without passing network profile id."""
     with self.network() as network:
         np = n1kv_db.get_network_profile_by_type(p_const.TYPE_VLAN)
         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_net_admin_defined_vlan_net_profile_name_unrestricted(self):
        """
        Test network create with admin created VLAN network profile name with
        unrestricted access to network profiles for tenants.

        """
        ml2_n1kv_config.cfg.CONF.set_override("restrict_network_profiles", False, "ml2_cisco_n1kv")
        data = self.get_test_network_profile_dict(segment_type="vlan")
        net_profile = self.create_assert_network_profile_success(data)
        net_prof_name = net_profile["network_profile"]["name"]
        net_prof_id = net_profile["network_profile"]["id"]
        # test net-create with non-admin and admin tenants
        tenant_id_list = ["non-admin-tenant", self.admin_tenant]
        for tenant_id in tenant_id_list:
            # assert that binding of this net-profile with ANY tenant
            # exists in unrestricted mode
            self.assert_profile_binding_exists(
                binding="network_profile_bindings", tenant_id=tenant_id, profile_id=net_prof_id
            )
            res = self._create_network(
                self.fmt,
                name="vlan-net",
                admin_state_up=True,
                arg_list=("n1kv:profile", "tenant_id"),
                set_context=True,
                **{n1kv_const.N1KV_PROFILE: net_prof_name, "tenant_id": tenant_id}
            )
            self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
            network = self.deserialize(self.fmt, res)
            net_np = n1kv_db.get_network_binding(network["network"]["id"])
            self.assertEqual(net_prof_id, network["network"][n1kv_const.N1KV_PROFILE])
            self.assertEqual(net_np["network_id"], network["network"]["id"])
            self.assertEqual(net_prof_id, net_np["profile_id"])
            self.assertEqual(tenant_id, network["network"]["tenant_id"])
 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"])
 def extend_network_dict(self, session, model, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     with session.begin(subtransactions=True):
         try:
             res = n1kv_db.get_network_binding(net_id, session)
             result[constants.N1KV_PROFILE] = res.profile_id
         except n1kv_exc.NetworkBindingNotFound:
             # Do nothing if the network binding is not found.
             pass
Exemplo n.º 13
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'])
 def extend_network_dict(self, session, model, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     with session.begin(subtransactions=True):
         try:
             res = n1kv_db.get_network_binding(net_id, session)
             result[constants.N1KV_PROFILE] = res.profile_id
         except n1kv_exc.NetworkBindingNotFound:
             # Do nothing if the network binding is not found.
             pass
Exemplo n.º 15
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 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)
Exemplo n.º 17
0
 def test_create_network_with_admin_defined_vlan_network_profile_id(self):
     """Test network create with admin defined VLAN network profile ID."""
     data = self.get_test_network_profile_dict(segment_type='vlan')
     net_prof = self.network_profile(data)
     net_prof_id = net_prof['network_profile']['id']
     res = self._create_network(self.fmt, name='vlan-net',
                                admin_state_up=True,
                                arg_list=('n1kv:profile',),
                                **{n1kv_const.N1KV_PROFILE: net_prof_id})
     self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
     network = self.deserialize(self.fmt, res)
     net_np = n1kv_db.get_network_binding(network['network']['id'])
     self.assertEqual(net_prof_id, network['network'][
         n1kv_const.N1KV_PROFILE])
     self.assertEqual(net_np['network_id'], network['network']['id'])
     self.assertEqual(net_np['profile_id'], net_prof_id)
Exemplo n.º 18
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)
Exemplo n.º 19
0
 def _sync_create_networks(self, combined_res_info, vsm_ip):
     """Sync networks by creating missing ones on VSM."""
     (vsm_net_uuids, neutron_nets) = combined_res_info
     for network in neutron_nets:
         if network['id'] not in vsm_net_uuids:
             network_profile = n1kv_db.get_network_profile_by_network(
                 network['id'])
             binding = n1kv_db.get_network_binding(network['id'])
             network[providernet.SEGMENTATION_ID] = binding.segmentation_id
             network[providernet.NETWORK_TYPE] = binding.network_type
             # create these networks on VSM
             try:
                 self.n1kvclient.create_network_segment(network,
                                                        network_profile,
                                                        vsm_ip=vsm_ip)
             except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
                 LOG.warning(_LW('Sync exception: Network create failed '
                                 'for %s.') % network['id'])
 def test_create_network_with_admin_defined_vlan_network_profile_id(self):
     """Test network create with admin defined VLAN network profile ID."""
     data = self.get_test_network_profile_dict(segment_type="vlan")
     net_prof = self.network_profile(data)
     net_prof_id = net_prof["network_profile"]["id"]
     res = self._create_network(
         self.fmt,
         name="vlan-net",
         admin_state_up=True,
         arg_list=("n1kv:profile",),
         **{n1kv_const.N1KV_PROFILE: net_prof_id}
     )
     self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
     network = self.deserialize(self.fmt, res)
     net_np = n1kv_db.get_network_binding(network["network"]["id"])
     self.assertEqual(net_prof_id, network["network"][n1kv_const.N1KV_PROFILE])
     self.assertEqual(net_np["network_id"], network["network"]["id"])
     self.assertEqual(net_np["profile_id"], net_prof_id)
Exemplo n.º 21
0
 def _sync_create_networks(self, combined_res_info, vsm_ip):
     """Sync networks by creating missing ones on VSM."""
     (vsm_net_uuids, neutron_nets) = combined_res_info
     for network in neutron_nets:
         if network['id'] not in vsm_net_uuids:
             network_profile = n1kv_db.get_network_profile_by_network(
                 network['id'])
             binding = n1kv_db.get_network_binding(network['id'])
             network[providernet.SEGMENTATION_ID] = binding.segmentation_id
             network[providernet.NETWORK_TYPE] = binding.network_type
             # create these networks on VSM
             try:
                 self.n1kvclient.create_network_segment(network,
                                                        network_profile,
                                                        vsm_ip=vsm_ip)
             except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
                 LOG.warning(_LW('Sync exception: Network create failed '
                                 'for %s.') % network['id'])
Exemplo n.º 22
0
    def _sync_bridge_domains(self, combined_res_info, vsm_ip):
        """
        Sync bridge domains by creating/deleting them on the VSM.

        :param combined_res_info: a two tuple storing the list of VSM BDs
                                  and the list of neutron networks
        :param vsm_ip: IP of the VSM being synced
        """
        # create missing BDs on VSM
        (vsm_bds, neutron_vxlan_nets) = combined_res_info
        need_bd_sync = False
        for network in neutron_vxlan_nets:
            bd_name = network['id'] + n1kv_const.BRIDGE_DOMAIN_SUFFIX
            if bd_name not in vsm_bds:
                binding = n1kv_db.get_network_binding(network['id'])
                netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id)
                network[providernet.SEGMENTATION_ID] = binding.segmentation_id
                network[providernet.NETWORK_TYPE] = binding.network_type
                # create this BD on VSM
                try:
                    self.n1kvclient.create_bridge_domain(network,
                                                         netp,
                                                         vsm_ip=vsm_ip)
                except (n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError):
                    LOG.warning(
                        _LW('Sync Exception: Bridge domain creation '
                            'failed for %s.') % bd_name)
                    need_bd_sync = True
        # delete extraneous BDs from VSM
        neutron_bds = {
            net_id + n1kv_const.BRIDGE_DOMAIN_SUFFIX
            for net_id in self._get_uuids(n1kv_const.NETWORKS,
                                          neutron_vxlan_nets)
        }
        for bd in vsm_bds - neutron_bds:
            try:
                # delete this BD from VSM
                self.n1kvclient.delete_bridge_domain(bd, vsm_ip=vsm_ip)
            except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
                LOG.warning(
                    _LW('Sync Exception: Bridge domain deletion '
                        'failed for %s.') % bd)
                need_bd_sync = True
        self.sync_bds[vsm_ip] = need_bd_sync
Exemplo n.º 23
0
    def _sync_bridge_domains(self, combined_res_info, vsm_ip):
        """
        Sync bridge domains by creating/deleting them on the VSM.

        :param combined_res_info: a two tuple storing the list of VSM BDs
                                  and the list of neutron networks
        :param vsm_ip: IP of the VSM being synced
        """
        # create missing BDs on VSM
        (vsm_bds, neutron_vxlan_nets) = combined_res_info
        need_bd_sync = False
        for network in neutron_vxlan_nets:
            bd_name = network['id'] + n1kv_const.BRIDGE_DOMAIN_SUFFIX
            if bd_name not in vsm_bds:
                binding = n1kv_db.get_network_binding(network['id'])
                netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id)
                network[providernet.SEGMENTATION_ID] = binding.segmentation_id
                network[providernet.NETWORK_TYPE] = binding.network_type
                # create this BD on VSM
                try:
                    self.n1kvclient.create_bridge_domain(network,
                                                         netp,
                                                         vsm_ip=vsm_ip)
                except(n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError):
                    LOG.warning(_LW('Sync Exception: Bridge domain creation '
                                    'failed for %s.') % bd_name)
                    need_bd_sync = True
        # delete extraneous BDs from VSM
        neutron_bds = {net_id + n1kv_const.BRIDGE_DOMAIN_SUFFIX for net_id in
                       self._get_uuids(n1kv_const.NETWORKS,
                                       neutron_vxlan_nets)}
        for bd in vsm_bds - neutron_bds:
            try:
                # delete this BD from VSM
                self.n1kvclient.delete_bridge_domain(bd, vsm_ip=vsm_ip)
            except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
                LOG.warning(_LW('Sync Exception: Bridge domain deletion '
                                'failed for %s.') % bd)
                need_bd_sync = True
        self.sync_bds[vsm_ip] = need_bd_sync
    def test_create_net_admin_defined_vlan_net_profile_name_unrestricted(self):
        """
        Test network create with admin created VLAN network profile name with
        unrestricted access to network profiles for tenants.

        """
        ml2_n1kv_config.cfg.CONF.set_override('restrict_network_profiles',
                                              False, 'ml2_cisco_n1kv')
        data = self.get_test_network_profile_dict(segment_type='vlan')
        net_profile = self.create_assert_network_profile_success(data)
        net_prof_name = net_profile['network_profile']['name']
        net_prof_id = net_profile['network_profile']['id']
        # test net-create with non-admin and admin tenants
        tenant_id_list = ['non-admin-tenant', self.admin_tenant]
        for tenant_id in tenant_id_list:
            # assert that binding of this net-profile with ANY tenant
            # exists in unrestricted mode
            self.assert_profile_binding_exists(
                binding='network_profile_bindings',
                tenant_id=tenant_id,
                profile_id=net_prof_id)
            res = self._create_network(self.fmt,
                                       name='vlan-net',
                                       admin_state_up=True,
                                       arg_list=('n1kv:profile', 'tenant_id'),
                                       set_context=True,
                                       **{
                                           n1kv_const.N1KV_PROFILE:
                                           net_prof_name,
                                           'tenant_id': tenant_id
                                       })
            self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
            network = self.deserialize(self.fmt, res)
            net_np = n1kv_db.get_network_binding(network['network']['id'])
            self.assertEqual(net_prof_id,
                             network['network'][n1kv_const.N1KV_PROFILE])
            self.assertEqual(net_np['network_id'], network['network']['id'])
            self.assertEqual(net_prof_id, net_np['profile_id'])
            self.assertEqual(tenant_id, network['network']['tenant_id'])
Exemplo n.º 25
0
    def _sync_create_networks(self, combined_res_info, vsm_ip):
        """
        Sync networks by creating missing ones on VSM.

        :param combined_res_info: tuple containing VSM and neutron information
        :param vsm_ip: string representing the IP address of the VSM
        """
        (vsm_net_uuids, neutron_nets) = combined_res_info
        for network in neutron_nets:
            if network['id'] not in vsm_net_uuids:
                network_profile = n1kv_db.get_network_profile_by_network(
                    network['id'])
                binding = n1kv_db.get_network_binding(network['id'])
                network[providernet.SEGMENTATION_ID] = binding.segmentation_id
                network[providernet.NETWORK_TYPE] = binding.network_type
                # create these networks on VSM
                try:
                    self.n1kvclient.create_network_segment(network,
                                                           network_profile,
                                                           vsm_ip)
                except n1kv_exc.VSMError as e:
                    LOG.warning(_LW('Sync Exception: Network creation on VSM '
                                'failed: %s'), e.message)
Exemplo n.º 26
0
    def _sync_create_networks(self, combined_res_info, vsm_ip):
        """
        Sync networks by creating missing ones on VSM.

        :param combined_res_info: tuple containing VSM and neutron information
        :param vsm_ip: string representing the IP address of the VSM
        """
        (vsm_net_uuids, neutron_nets) = combined_res_info
        for network in neutron_nets:
            if network['id'] not in vsm_net_uuids:
                network_profile = n1kv_db.get_network_profile_by_network(
                    network['id'])
                binding = n1kv_db.get_network_binding(network['id'])
                network[providernet.SEGMENTATION_ID] = binding.segmentation_id
                network[providernet.NETWORK_TYPE] = binding.network_type
                # create these networks on VSM
                try:
                    self.n1kvclient.create_network_segment(
                        network, network_profile, vsm_ip)
                except n1kv_exc.VSMError as e:
                    LOG.warning(
                        _LW('Sync Exception: Network creation on VSM '
                            'failed: %s'), e.message)
    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
            )
Exemplo n.º 28
0
 def create_network_postcommit(self, context):
     """Send network parameters to the VSM."""
     network = context.current
     segment = context.network_segments[0]
     network_type = segment['network_type']
     # NoOp for unsupported network types
     if not self._is_segment_valid_for_n1kv(segment['segmentation_id'],
                                            network_type):
         return
     session = context._plugin_context.session
     binding = n1kv_db.get_network_binding(network['id'], session)
     netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id, session)
     network[providernet.SEGMENTATION_ID] = binding.segmentation_id
     try:
         self.n1kvclient.create_network_segment(network, netp)
     except(n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed):
         raise ml2_exc.MechanismDriverError()
     LOG.info(_LI("Create network(postcommit) succeeded for network: "
                  "%(network_id)s of type: %(network_type)s with segment "
                  "id: %(segment_id)s"),
              {"network_id": network['id'],
               "network_type": network_type,
               "segment_id": segment['segmentation_id']})