Skip to content

Commit

Permalink
tc: fix get_qdiscs(index=...)
Browse files Browse the repository at this point in the history
The old version could filter qdiscs by the interface index, fix that
in the new API.

Bug-Url: #1225
  • Loading branch information
svinota committed Jan 10, 2025
1 parent cea3c06 commit 319f4ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyroute2/iproute/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ async def get_qdiscs(self, index=None):
A compatibility method, == .tc("dump")
'''
return await self.tc('dump')
return await self.tc('dump', index=index)

async def get_filters(self, index=0, handle=0, parent=0):
'''
Expand Down
4 changes: 3 additions & 1 deletion tests/test_core/pr2test/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ def filter_exists(


def qdisc_exists(
ifname, handle, default=None, netns=None, timeout=1, retry=0.2
ifname, handle, default=None, rate=None, netns=None, timeout=1, retry=0.2
):
filters = [ip_object_filter(query='.handle', value=handle)]
if default is not None:
filters.append(
ip_object_filter(query='.options.default', value=default)
)
if rate is not None:
filters.append(ip_object_filter(query='.options.rate', value=rate))
return wait_for_ip_object(
['tc', '-json', 'qdisc', 'show', 'dev', ifname],
filters,
Expand Down
27 changes: 23 additions & 4 deletions tests/test_core/test_ipr/test_tc_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,35 @@ async def util_link_add(async_ipr):
ifname = async_ipr.register_temporary_ifname()
await async_ipr.link('add', ifname=ifname, kind='dummy', state='up')
assert interface_exists(ifname)
return ifname
(link,) = await async_ipr.link('get', ifname=ifname)
index = link['index']
return ifname, index


@pytest.mark.asyncio
async def test_tc_get_qdiscs(async_ipr):
root_handle = '1:'
ifname, index = await util_link_add(async_ipr)
await async_ipr.tc(
'add',
'tbf',
index=index,
handle=root_handle,
rate=256,
burst=256,
latency=1,
)
assert qdisc_exists(ifname=ifname, handle=root_handle, rate=256)
assert len([x async for x in await async_ipr.get_qdiscs(index=index)]) == 1
await async_ipr.tc('del', index=index, handle=root_handle, root=True)
assert not qdisc_exists(ifname=ifname, handle=root_handle, rate=256)


@pytest.mark.asyncio
async def test_tc_htb(async_ipr):
root_handle = '1:'
root_options_default = '0x200000'
ifname = await util_link_add(async_ipr)
(link,) = await async_ipr.link('get', ifname=ifname)
index = link['index']
ifname, index = await util_link_add(async_ipr)
await async_ipr.tc(
'add',
'htb',
Expand Down

0 comments on commit 319f4ba

Please sign in to comment.