Ensure API calls for subnets are in URL length limit
Fix situation when with pagination enabled, neutronclient failed to read subnets information due to too long URI. Change-Id: I53240c536d77a95510b5c83b81e21782f29d886a Closes-Bug: 1775922
This commit is contained in:
parent
f0640571d1
commit
0aefe1ccba
neutronclient
@ -44,6 +44,9 @@ class ListNetwork(neutronV20.ListCommand):
|
|||||||
# Length of a query filter on subnet id
|
# Length of a query filter on subnet id
|
||||||
# id=<uuid>& (with len(uuid)=36)
|
# id=<uuid>& (with len(uuid)=36)
|
||||||
subnet_id_filter_len = 40
|
subnet_id_filter_len = 40
|
||||||
|
# Length of a marker in pagination
|
||||||
|
# &marker=<uuid> (with len(uuid)=36)
|
||||||
|
marker_len = 44
|
||||||
resource = 'network'
|
resource = 'network'
|
||||||
_formatters = {'subnets': _format_subnets, }
|
_formatters = {'subnets': _format_subnets, }
|
||||||
list_columns = ['id', 'name', 'subnets']
|
list_columns = ['id', 'name', 'subnets']
|
||||||
@ -115,6 +118,8 @@ class ListNetwork(neutronV20.ListCommand):
|
|||||||
subnet_count = len(subnet_ids)
|
subnet_count = len(subnet_ids)
|
||||||
max_size = ((self.subnet_id_filter_len * subnet_count) -
|
max_size = ((self.subnet_id_filter_len * subnet_count) -
|
||||||
uri_len_exc.excess)
|
uri_len_exc.excess)
|
||||||
|
if self.pagination_support:
|
||||||
|
max_size -= self.marker_len
|
||||||
chunk_size = max_size // self.subnet_id_filter_len
|
chunk_size = max_size // self.subnet_id_filter_len
|
||||||
subnets = []
|
subnets = []
|
||||||
for i in range(0, subnet_count, chunk_size):
|
for i in range(0, subnet_count, chunk_size):
|
||||||
|
@ -653,8 +653,12 @@ class CLITestV20ExtendListNetworkJSON(test_cli20.CLITestV20Base):
|
|||||||
data = [{'id': 'netid%d' % i, 'name': 'net%d' % i,
|
data = [{'id': 'netid%d' % i, 'name': 'net%d' % i,
|
||||||
'subnets': ['mysubid%d' % i]}
|
'subnets': ['mysubid%d' % i]}
|
||||||
for i in range(10)]
|
for i in range(10)]
|
||||||
filters1, response1 = self._build_test_data(data[:len(data) - 1])
|
# Since in pagination we add &marker=<uuid> (44 symbols), total change
|
||||||
filters2, response2 = self._build_test_data(data[len(data) - 1:])
|
# is 45 symbols. Single subnet takes 40 symbols (id=<uuid>&).
|
||||||
|
# Because of it marker will take more space than single subnet filter,
|
||||||
|
# and we expect neutron to send last 2 subnets in separate response.
|
||||||
|
filters1, response1 = self._build_test_data(data[:len(data) - 2])
|
||||||
|
filters2, response2 = self._build_test_data(data[len(data) - 2:])
|
||||||
path = getattr(self.client, 'subnets_path')
|
path = getattr(self.client, 'subnets_path')
|
||||||
cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
|
cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
|
||||||
with mock.patch.object(cmd, "get_client",
|
with mock.patch.object(cmd, "get_client",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user