Skip to content

Commit

Permalink
tc: Merge pull request #1239 from svinota/1225-tc-del
Browse files Browse the repository at this point in the history
tc: test del, del-class, del-filter commands

Bug-Url: #1239
Bug-Url: #1225
  • Loading branch information
svinota authored Jan 9, 2025
2 parents 0348ce8 + 194408a commit e9ee628
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyroute2/iproute/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,9 +1872,10 @@ async def tc(self, command, kind=None, index=None, handle=None, **kwarg):
'replace-filter': (RTM_NEWTFILTER, 'replace'),
}

if command[:3] not in ('dum', 'get'):
if command[:3] in ('add', 'cha'):
if kind is None:
raise ValueError('must specify kind for non-dump commands')
raise ValueError('must specify kind for add/change commands')
if kind is not None:
kwarg['kind'] = kind
# 8<-----------------------------------------------
# compatibility section, to be cleaned up?
Expand Down
8 changes: 8 additions & 0 deletions pyroute2/requests/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def transform_handle(self, key, context, handle):
def set_handle(self, context, value):
return self.transform_handle('handle', context, value)

def set_root(self, context, value):
ret = {}
if value:
ret['parent'] = 0xFFFFFFFF
if 'handle' not in context:
ret['handle'] = 0x10000
return ret

def set_target(self, context, value):
return self.transform_handle('target', context, value)

Expand Down
32 changes: 32 additions & 0 deletions tests/test_core/test_ipr/test_tc_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,35 @@ async def test_tc_htb(async_ipr):
match_value='10000000',
match_mask='ff000000',
)

# complementary delete commands
await async_ipr.tc('del-filter', index=index, handle='0:0', parent='1:0')
assert not filter_exists(ifname=ifname, kind='u32', parent='1:0')

await async_ipr.tc('del-class', index=index, handle='1:20', parent='1:1')
assert not class_exists(
ifname=ifname, kind='htb', handle='1:20', parent='1:1'
)
assert class_exists(ifname=ifname, kind='htb', handle='1:10', parent='1:1')
assert class_exists(ifname=ifname, kind='htb', handle='1:1', root=True)

await async_ipr.tc('del-class', index=index, handle='1:10', parent='1:1')
assert not class_exists(
ifname=ifname, kind='htb', handle='1:20', parent='1:1'
)
assert not class_exists(
ifname=ifname, kind='htb', handle='1:10', parent='1:1'
)
assert class_exists(ifname=ifname, kind='htb', handle='1:1', root=True)

await async_ipr.tc('del-class', index=index, handle='1:1', parent='1:0')
assert not class_exists(
ifname=ifname, kind='htb', handle='1:20', parent='1:1'
)
assert not class_exists(
ifname=ifname, kind='htb', handle='1:10', parent='1:1'
)
assert not class_exists(ifname=ifname, kind='htb', handle='1:1', root=True)

await async_ipr.tc('del', index=index, handle=root_handle, root=True)
assert not qdisc_exists(ifname=ifname, handle=root_handle)

0 comments on commit e9ee628

Please sign in to comment.