Example #1
0
    def _make_test_profile(self,
                           name='default_network_profile',
                           segment_type=c_const.NETWORK_TYPE_VLAN,
                           segment_range='386-400'):
        """
        Create a profile record for testing purposes.

        :param name: string representing the name of the network profile to
                     create. Default argument value chosen to correspond to the
                     default name specified in config.py file.
        :param segment_type: string representing the type of network segment.
        :param segment_range: string representing the segment range for network
                              profile.
        """
        db_session = db.get_session()
        profile = {'name': name,
                   'segment_type': segment_type,
                   'tenant_id': self.tenant_id,
                   'segment_range': segment_range}
        if segment_type == c_const.NETWORK_TYPE_OVERLAY:
            profile['sub_type'] = 'unicast'
            profile['multicast_ip_range'] = '0.0.0.0'
            net_p = n1kv_db_v2.create_network_profile(db_session, profile)
            n1kv_db_v2.sync_vxlan_allocations(db_session, net_p)
        elif segment_type == c_const.NETWORK_TYPE_VLAN:
            profile['physical_network'] = PHYS_NET
            net_p = n1kv_db_v2.create_network_profile(db_session, profile)
            n1kv_db_v2.sync_vlan_allocations(db_session, net_p)
        return net_p
    def _make_test_profile(self,
                           name='default_network_profile',
                           segment_type=c_const.NETWORK_TYPE_VLAN,
                           segment_range='386-400'):
        """
        Create a profile record for testing purposes.

        :param name: string representing the name of the network profile to
                     create. Default argument value chosen to correspond to the
                     default name specified in config.py file.
        :param segment_type: string representing the type of network segment.
        :param segment_range: string representing the segment range for network
                              profile.
        """
        db_session = db.get_session()
        profile = {
            'name': name,
            'segment_type': segment_type,
            'tenant_id': self.tenant_id,
            'segment_range': segment_range
        }
        if segment_type == c_const.NETWORK_TYPE_OVERLAY:
            profile['sub_type'] = 'unicast'
            profile['multicast_ip_range'] = '0.0.0.0'
            net_p = n1kv_db_v2.create_network_profile(db_session, profile)
            n1kv_db_v2.sync_vxlan_allocations(db_session, net_p)
        elif segment_type == c_const.NETWORK_TYPE_VLAN:
            profile['physical_network'] = PHYS_NET
            net_p = n1kv_db_v2.create_network_profile(db_session, profile)
            n1kv_db_v2.sync_vlan_allocations(db_session, net_p)
        return net_p
Example #3
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     db.configure_db()
     self.session = db.get_session()
     self.net_p = _create_test_network_profile_if_not_there(self.session, TEST_NETWORK_PROFILE_VXLAN)
     n1kv_db_v2.sync_vxlan_allocations(self.session, self.net_p)
     self.addCleanup(db.clear_db)
Example #4
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     db.configure_db()
     self.session = db.get_session()
     self.net_p = _create_test_network_profile_if_not_there(
         self.session, TEST_NETWORK_PROFILE_VXLAN)
     n1kv_db_v2.sync_vxlan_allocations(self.session, self.net_p)
     self.addCleanup(db.clear_db)
Example #5
0
 def test_sync_vxlan_allocations_outside_segment_range(self):
     self.assertIsNone(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MIN - 1))
     self.assertIsNone(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MAX + 1))
     n1kv_db_v2.sync_vxlan_allocations(self.session, UPDATED_VXLAN_RANGES)
     self.assertIsNone(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MIN + 20 - 1))
     self.assertIsNone(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MAX + 20 + 1))
Example #6
0
 def test_sync_vxlan_allocations_outside_segment_range(self):
     self.assertIsNone(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                       VXLAN_MIN - 1))
     self.assertIsNone(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                       VXLAN_MAX + 1))
     n1kv_db_v2.sync_vxlan_allocations(self.session, UPDATED_VXLAN_RANGES)
     self.assertIsNone(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                       VXLAN_MIN + 20 - 1))
     self.assertIsNone(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                       VXLAN_MAX + 20 + 1))
    def create_network_profile(self, context, network_profile):
        """
        Create a network profile.

        Create a network profile, which represents a pool of networks
        belonging to one type (VLAN or VXLAN). On creation of network
        profile, we retrieve the admin tenant-id which we use to replace
        the previously stored fake tenant-id in tenant-profile bindings.
        :param context: neutron api request context
        :param network_profile: network profile dictionary
        :returns: network profile object
        """
        self._replace_fake_tenant_id_with_real(context)
        _network_profile = super(
            N1kvNeutronPluginV2, self).create_network_profile(context,
                                                              network_profile)
        seg_min, seg_max = self._get_segment_range(
            _network_profile['segment_range'])
        if _network_profile['segment_type'] == c_const.NETWORK_TYPE_VLAN:
            self._add_network_vlan_range(_network_profile['physical_network'],
                                         int(seg_min),
                                         int(seg_max))
            n1kv_db_v2.sync_vlan_allocations(context.session,
                                             self.network_vlan_ranges)
        elif _network_profile['segment_type'] == c_const.NETWORK_TYPE_VXLAN:
            self.vxlan_id_ranges = []
            self.vxlan_id_ranges.append((int(seg_min), int(seg_max)))
            n1kv_db_v2.sync_vxlan_allocations(context.session,
                                              self.vxlan_id_ranges)
        try:
            self._send_create_logical_network_request(_network_profile)
        except(cisco_exceptions.VSMError,
               cisco_exceptions.VSMConnectionFailed):
            super(N1kvNeutronPluginV2, self).delete_network_profile(
                context, _network_profile['id'])
        try:
            self._send_create_network_profile_request(context,
                                                      _network_profile)
        except(cisco_exceptions.VSMError,
               cisco_exceptions.VSMConnectionFailed):
            self._send_delete_logical_network_request(_network_profile)
            super(N1kvNeutronPluginV2, self).delete_network_profile(
                context, _network_profile['id'])
        else:
            return _network_profile
Example #8
0
    def create_network_profile(self, context, network_profile):
        """
        Create a network profile.

        Create a network profile, which represents a pool of networks
        belonging to one type (VLAN or VXLAN). On creation of network
        profile, we retrieve the admin tenant-id which we use to replace
        the previously stored fake tenant-id in tenant-profile bindings.
        :param context: neutron api request context
        :param network_profile: network profile dictionary
        :returns: network profile object
        """
        self._replace_fake_tenant_id_with_real(context)
        _network_profile = super(N1kvNeutronPluginV2,
                                 self).create_network_profile(
                                     context, network_profile)
        seg_min, seg_max = self._get_segment_range(
            _network_profile['segment_range'])
        if _network_profile['segment_type'] == c_const.NETWORK_TYPE_VLAN:
            self._add_network_vlan_range(_network_profile['physical_network'],
                                         int(seg_min), int(seg_max))
            n1kv_db_v2.sync_vlan_allocations(context.session,
                                             self.network_vlan_ranges)
        elif _network_profile['segment_type'] == c_const.NETWORK_TYPE_VXLAN:
            self.vxlan_id_ranges = []
            self.vxlan_id_ranges.append((int(seg_min), int(seg_max)))
            n1kv_db_v2.sync_vxlan_allocations(context.session,
                                              self.vxlan_id_ranges)
        try:
            self._send_create_logical_network_request(_network_profile)
        except (cisco_exceptions.VSMError,
                cisco_exceptions.VSMConnectionFailed):
            super(N1kvNeutronPluginV2,
                  self).delete_network_profile(context, _network_profile['id'])
        try:
            self._send_create_network_profile_request(context,
                                                      _network_profile)
        except (cisco_exceptions.VSMError,
                cisco_exceptions.VSMConnectionFailed):
            self._send_delete_logical_network_request(_network_profile)
            super(N1kvNeutronPluginV2,
                  self).delete_network_profile(context, _network_profile['id'])
        else:
            return _network_profile
Example #9
0
 def test_sync_vxlan_allocations_unallocated_vxlans(self):
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MIN).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MIN + 1).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MAX - 1).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session, VXLAN_MAX).allocated)
     n1kv_db_v2.sync_vxlan_allocations(self.session, UPDATED_VXLAN_RANGES)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MIN + 20).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MIN + 20 + 1).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MAX + 20 - 1).allocated)
     self.assertFalse(
         n1kv_db_v2.get_vxlan_allocation(self.session,
                                         VXLAN_MAX + 20).allocated)
Example #10
0
 def test_sync_vxlan_allocations_unallocated_vxlans(self):
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MIN).allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MIN + 1).
                      allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MAX - 1).
                      allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MAX).allocated)
     n1kv_db_v2.sync_vxlan_allocations(self.session, UPDATED_VXLAN_RANGES)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MIN + 20).
                      allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MIN + 20 + 1).
                      allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MAX + 20 - 1).
                      allocated)
     self.assertFalse(n1kv_db_v2.get_vxlan_allocation(self.session,
                                                      VXLAN_MAX + 20).
                      allocated)
Example #11
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     n1kv_db_v2.initialize()
     self.session = db.get_session()
     n1kv_db_v2.sync_vxlan_allocations(self.session, VXLAN_RANGES)
Example #12
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     n1kv_db_v2.initialize()
     self.session = db.get_session()
     n1kv_db_v2.sync_vxlan_allocations(self.session, VXLAN_RANGES)
Example #13
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     db.configure_db()
     self.session = db.get_session()
     n1kv_db_v2.sync_vxlan_allocations(self.session, VXLAN_RANGES)
Example #14
0
 def setUp(self):
     super(VxlanAllocationsTest, self).setUp()
     db.configure_db()
     self.session = db.get_session()
     n1kv_db_v2.sync_vxlan_allocations(self.session, VXLAN_RANGES)