thombashi / tcconfig

A tc command wrapper. Make it easy to set up traffic control of network bandwidth/latency/packet-loss/packet-corruption/etc. to a network-interface/Docker-container(veth).
https://tcconfig.rtfd.io/
MIT License
790 stars 84 forks source link

--tc-command option fails with tcshow_out assert error #187

Closed soyacz closed 2 months ago

soyacz commented 2 months ago

Describe the bug

When trying to use --tc-command option it fails with:

root@258368f00a7d:/# tcset eth1 --loss 1% --tc-command --debug
DEBUG    | subprocrunner._subprocess_runner:__debug_print_command:373 - dryrun: 
lsmod
DEBUG    | tcconfig.tcset:main:347 - sch_netem module not found
DEBUG    | simplesqlite.core:connect:280 - connect to a SQLite database: path=':memory:', mode=w
DEBUG    | simplesqlite.core:create_table:1324 - CREATE TABLE IF NOT EXISTS 'filter' (device TEXT NOT NULL, "filter_id" TEXT, flowid TEXT, protocol TEXT, priority INTEGER, "src_network" TEXT, "dst_network" TEXT, "src_port" INTEGER, "dst_port" INTEGER, classid TEXT, handle INTEGER)
DEBUG    | simplesqlite.core:create_table:1324 - CREATE TABLE IF NOT EXISTS 'qdisc' (device TEXT NOT NULL, "direct_qlen" INTEGER, parent TEXT, handle TEXT, delay TEXT, "delay_distro" TEXT, loss TEXT, duplicate TEXT, corrupt TEXT, reorder TEXT, rate TEXT)
DEBUG    | tcconfig._common:logging_context:27 - |---- start: _make_qdisc -----
DEBUG    | subprocrunner._subprocess_runner:__debug_print_command:373 - dryrun: 
/sbin/tc qdisc add dev eth1 root handle 16f1: htb default 1
DEBUG    | subprocrunner._subprocess_runner:__debug_print_command:373 - dryrun: 
/sbin/tc class add dev eth1 parent 16f1: classid 16f1:1 htb rate 32000000.0kbit
DEBUG    | tcconfig._common:logging_context:31 - ----- complete: _make_qdisc ----|
DEBUG    | tcconfig._common:logging_context:27 - |---- start: _add_rate -----
DEBUG    | tcconfig.shaper.htb:_get_qdisc_minor_id:42 - __get_unique_qdisc_minor_id: 79
DEBUG    | subprocrunner._subprocess_runner:__debug_print_command:373 - dryrun: 
/sbin/tc class add dev eth1 parent 16f1: classid 16f1:79 htb rate 32000000.0Kbit ceil 32000000.0Kbit
DEBUG    | tcconfig._common:logging_context:31 - ----- complete: _add_rate ----|
DEBUG    | tcconfig._common:logging_context:27 - |---- start: _set_netem -----
DEBUG    | subprocrunner._subprocess_runner:__debug_print_command:373 - dryrun: 
/sbin/tc qdisc show dev eth1
DEBUG    | tcconfig._common:logging_context:31 - ----- complete: _set_netem ----|
Traceback (most recent call last):
  File "/usr/local/bin/tcset", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/tcconfig/tcset.py", line 356, in main
    return TcSetMain(options).run()
  File "/usr/local/lib/python3.10/site-packages/tcconfig/tcset.py", line 272, in run
    return_code_list.append(tc.set_shaping_rule())
  File "/usr/local/lib/python3.10/site-packages/tcconfig/traffic_control.py", line 288, in set_shaping_rule
    return self.__shaper.set_shaping()
  File "/usr/local/lib/python3.10/site-packages/tcconfig/shaper/htb.py", line 215, in set_shaping
    self._set_netem()
  File "/usr/local/lib/python3.10/site-packages/tcconfig/shaper/_interface.py", line 69, in _set_netem
    f"{self._get_netem_qdisc_major_id(self._tc_obj.qdisc_major_id):x}:"
  File "/usr/local/lib/python3.10/site-packages/tcconfig/shaper/htb.py", line 48, in _get_netem_qdisc_major_id
    self.__netem_major_id = self.__get_unique_netem_major_id()
  File "/usr/local/lib/python3.10/site-packages/tcconfig/shaper/htb.py", line 288, in __get_unique_netem_major_id
    exist_netem_major_ids = self.__extract_exist_netem_major_ids()
  File "/usr/local/lib/python3.10/site-packages/tcconfig/shaper/htb.py", line 272, in __extract_exist_netem_major_ids
    assert tcshow_out
AssertionError

It started to happen in 0.28.1 (version 0.28.0 is ok).

Expected behavior

Returns commands

To Reproduce

Steps to reproduce the behavior:

  1. run tcset eth1 --loss 1% --tc-command

Environments

Please execute the following command and past the output:

|    Module    |            Version             |
| ------------ | ------------------------------ |
| uname        | Linux 6.5.0-44-generic         |
| Python       | CPython 3.10.12                |
| platform     | Debian GNU/Linux 11 (bullseye) |
| tcconfig     | 0.28.1                         |
| docker       | 7.1.0                          |
| SimpleSQLite | 1.5.2                          |

and complete the following information:

thombashi commented 2 months ago

@soyacz Thank you for your report. The problem has been fixed at tcconfig 0.29.0. Please try to upgrade the package.