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 setUp(self): super(VlanAllocationsTest, self).setUp() db.configure_db() self.session = db.get_session() self.net_p = _create_test_network_profile_if_not_there(self.session) n1kv_db_v2.sync_vlan_allocations(self.session, self.net_p) self.addCleanup(db.clear_db)
def _fake_add_dummy_profile_for_test(self, obj): """ Replacement for a function in the N1KV neutron plugin module. Since VSM is not available at the time of tests, we have no policy profiles. Hence we inject a dummy policy/network profile into the port/network object. """ dummy_profile_name = "dummy_profile" dummy_tenant_id = "test-tenant" db_session = db.get_session() if 'port' in obj: dummy_profile_id = "00000000-1111-1111-1111-000000000000" self._add_policy_profile(dummy_profile_name, dummy_profile_id, dummy_tenant_id) obj['port'][n1kv_profile.PROFILE_ID] = dummy_profile_id elif 'network' in obj: profile = {'name': 'dummy_profile', 'segment_type': 'vlan', 'physical_network': 'phsy1', 'segment_range': '3968-4047'} self.network_vlan_ranges = {profile[ 'physical_network']: [(3968, 4047)]} n1kv_db_v2.sync_vlan_allocations(db_session, self.network_vlan_ranges) np = n1kv_db_v2.create_network_profile(db_session, profile) obj['network'][n1kv_profile.PROFILE_ID] = np.id
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"): """ 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. """ db_session = db.get_session() profile = {"name": name, "segment_type": "vlan", "physical_network": "phsy1", "segment_range": "3968-4047"} self.network_vlan_ranges = {profile["physical_network"]: [(3968, 4047)]} n1kv_db_v2.sync_vlan_allocations(db_session, self.network_vlan_ranges) return n1kv_db_v2.create_network_profile(db_session, profile)
def test_sync_vlan_allocations_outside_segment_range(self): self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET, VLAN_MIN - 1) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET, VLAN_MAX + 1) n1kv_db_v2.sync_vlan_allocations(self.session, UPDATED_VLAN_RANGES) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET, VLAN_MIN + 20 - 1) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET, VLAN_MAX + 20 + 1) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET_2, VLAN_MIN + 40 - 1) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET_2, VLAN_MAX + 40 + 1) n1kv_db_v2.sync_vlan_allocations(self.session, VLAN_RANGES) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET_2, VLAN_MIN + 20) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET_2, VLAN_MIN + 20) self.assertRaises(c_exc.VlanIDNotFound, n1kv_db_v2.get_vlan_allocation, self.session, PHYS_NET_2, VLAN_MAX + 20)
def test_sync_vlan_allocations_unallocated_vlans(self): self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MIN).allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MIN + 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MAX - 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MAX).allocated) n1kv_db_v2.sync_vlan_allocations(self.session, UPDATED_VLAN_RANGES) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MIN + 20). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MIN + 20 + 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MAX + 20 - 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET, VLAN_MAX + 20). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET_2, VLAN_MIN + 40). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET_2, VLAN_MIN + 40 + 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET_2, VLAN_MAX + 40 - 1). allocated) self.assertFalse(n1kv_db_v2.get_vlan_allocation(self.session, PHYS_NET_2, VLAN_MAX + 40). allocated)
def _make_test_profile(self, name='default_network_profile'): """ 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. """ db_session = db.get_session() profile = {'name': name, 'segment_type': 'vlan', 'physical_network': 'phsy1', 'segment_range': '3968-4047'} self.network_vlan_ranges = {profile[ 'physical_network']: [(3968, 4047)]} n1kv_db_v2.sync_vlan_allocations(db_session, self.network_vlan_ranges) return n1kv_db_v2.create_network_profile(db_session, profile)
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
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
def _make_test_profile(self, name='default_network_profile', 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_range: string representing the segment range for network profile. """ db_session = db.get_session() profile = {'name': name, 'segment_type': 'vlan', 'physical_network': PHYS_NET, 'tenant_id': self.tenant_id, 'segment_range': segment_range} 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_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_range: string representing the segment range for network profile. """ db_session = db.get_session() profile = { "name": name, "segment_type": "vlan", "physical_network": PHYS_NET, "tenant_id": self.tenant_id, "segment_range": segment_range, } 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 setUp(self): super(VlanAllocationsTest, self).setUp() db.configure_db() self.session = db.get_session() n1kv_db_v2.sync_vlan_allocations(self.session, VLAN_RANGES)
def setUp(self): super(VlanAllocationsTest, self).setUp() n1kv_db_v2.initialize() self.session = db.get_session() n1kv_db_v2.sync_vlan_allocations(self.session, VLAN_RANGES)