From cfc5c8706b5afd4ce41736d850741f9ca84de024 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 22:16:05 +0900 Subject: [PATCH 1/8] Rename variables --- tcconfig/traffic_control.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tcconfig/traffic_control.py b/tcconfig/traffic_control.py index 50eda120..0e3c87f2 100644 --- a/tcconfig/traffic_control.py +++ b/tcconfig/traffic_control.py @@ -268,7 +268,7 @@ def __validate_netem_parameter(self): self.__validate_packet_loss_rate() self.__validate_corruption_rate() - param_list = [ + netem_param_value_list = [ self.bandwidth_rate, self.latency_ms, self.packet_loss_rate, @@ -276,8 +276,9 @@ def __validate_netem_parameter(self): ] if all([ - not FloatType(value).is_type() or value == 0 - for value in param_list + not FloatType( + netem_param_value).is_type() or netem_param_value == 0 + for netem_param_value in netem_param_value_list ]): raise ValueError("there is no valid net emulation parameter") From 492d5f1ac4f05b723a71e788342e5d8545038f92 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 22:46:32 +0900 Subject: [PATCH 2/8] Move version number to an independent file --- tcconfig/__init__.py | 2 +- tcconfig/_const.py | 7 +++++++ tcconfig/tcdel.py | 4 ++-- tcconfig/tcset.py | 4 ++-- tcconfig/tcshow.py | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 tcconfig/_const.py diff --git a/tcconfig/__init__.py b/tcconfig/__init__.py index bbba94d0..733d849a 100644 --- a/tcconfig/__init__.py +++ b/tcconfig/__init__.py @@ -4,4 +4,4 @@ .. codeauthor:: Tsuyoshi Hombashi """ -VERSION = "0.7.0-alpha-3" +from ._const import VERSION diff --git a/tcconfig/_const.py b/tcconfig/_const.py new file mode 100644 index 00000000..bbba94d0 --- /dev/null +++ b/tcconfig/_const.py @@ -0,0 +1,7 @@ +# encoding: utf-8 + +""" +.. codeauthor:: Tsuyoshi Hombashi +""" + +VERSION = "0.7.0-alpha-3" diff --git a/tcconfig/tcdel.py b/tcconfig/tcdel.py index c9596b0d..e13e9948 100644 --- a/tcconfig/tcdel.py +++ b/tcconfig/tcdel.py @@ -11,10 +11,10 @@ import logbook import subprocrunner -import tcconfig from .traffic_control import TrafficControl from ._argparse_wrapper import ArgparseWrapper from ._common import verify_network_interface +from ._const import VERSION from ._error import NetworkInterfaceNotFoundError from ._logger import ( LOG_FORMAT_STRING, @@ -28,7 +28,7 @@ def parse_option(): - parser = ArgparseWrapper(tcconfig.VERSION) + parser = ArgparseWrapper(VERSION) group = parser.parser.add_argument_group("Traffic Control") group.add_argument( diff --git a/tcconfig/tcset.py b/tcconfig/tcset.py index b3b2a365..a232d899 100644 --- a/tcconfig/tcset.py +++ b/tcconfig/tcset.py @@ -14,10 +14,10 @@ import six import subprocrunner -import tcconfig from .traffic_control import TrafficControl from ._argparse_wrapper import ArgparseWrapper from ._common import ANYWHERE_NETWORK +from ._const import VERSION from ._error import ModuleNotFoundError from ._error import NetworkInterfaceNotFoundError from ._logger import ( @@ -33,7 +33,7 @@ def parse_option(): - parser = ArgparseWrapper(tcconfig.VERSION) + parser = ArgparseWrapper(VERSION) group = parser.parser.add_mutually_exclusive_group(required=True) group.add_argument( diff --git a/tcconfig/tcshow.py b/tcconfig/tcshow.py index 9e1d5f7b..0f71fe35 100644 --- a/tcconfig/tcshow.py +++ b/tcconfig/tcshow.py @@ -16,11 +16,11 @@ import subprocrunner from subprocrunner import SubprocessRunner -import tcconfig from .parser import TcFilterParser from .parser import TcQdiscParser from ._argparse_wrapper import ArgparseWrapper from ._common import verify_network_interface +from ._const import VERSION from ._error import NetworkInterfaceNotFoundError from ._iptables import IptablesMangleController from ._logger import ( @@ -36,7 +36,7 @@ def parse_option(): - parser = ArgparseWrapper(tcconfig.VERSION) + parser = ArgparseWrapper(VERSION) group = parser.parser.add_argument_group("Traffic Control") group.add_argument( From 09efd8ad89d54526a6a824cf4c76c8438e622baf Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 22:52:36 +0900 Subject: [PATCH 3/8] Move a const --- tcconfig/_common.py | 4 +--- tcconfig/_const.py | 6 ++++++ tcconfig/_iptables.py | 2 +- tcconfig/shaper/tbf.py | 2 +- tcconfig/tcset.py | 6 ++++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tcconfig/_common.py b/tcconfig/_common.py index 0b1b327a..d794b8b1 100644 --- a/tcconfig/_common.py +++ b/tcconfig/_common.py @@ -11,13 +11,11 @@ import logbook import six +from ._const import ANYWHERE_NETWORK from ._error import NetworkInterfaceNotFoundError from ._logger import logger -ANYWHERE_NETWORK = "0.0.0.0/0" - - @contextlib.contextmanager def logging_context(name): logger.debug("|---- {:s}: {:s} -----".format("start", name)) diff --git a/tcconfig/_const.py b/tcconfig/_const.py index bbba94d0..f5a337dd 100644 --- a/tcconfig/_const.py +++ b/tcconfig/_const.py @@ -4,4 +4,10 @@ .. codeauthor:: Tsuyoshi Hombashi """ +from __future__ import absolute_import +from __future__ import unicode_literals + + VERSION = "0.7.0-alpha-3" + +ANYWHERE_NETWORK = "0.0.0.0/0" diff --git a/tcconfig/_iptables.py b/tcconfig/_iptables.py index 927402b9..20893637 100644 --- a/tcconfig/_iptables.py +++ b/tcconfig/_iptables.py @@ -11,7 +11,7 @@ from dataproperty import IntegerType from subprocrunner import SubprocessRunner -from ._common import ANYWHERE_NETWORK +from ._const import ANYWHERE_NETWORK from ._common import sanitize_network from ._split_line_list import split_line_list diff --git a/tcconfig/shaper/tbf.py b/tcconfig/shaper/tbf.py index c3de55b4..053ef6ee 100644 --- a/tcconfig/shaper/tbf.py +++ b/tcconfig/shaper/tbf.py @@ -11,10 +11,10 @@ from subprocrunner import SubprocessRunner from .._common import ( - ANYWHERE_NETWORK, logging_context, run_command_helper, ) +from .._const import ANYWHERE_NETWORK from .._error import EmptyParameterError from .._traffic_direction import TrafficDirection from ._interface import AbstractShaper diff --git a/tcconfig/tcset.py b/tcconfig/tcset.py index a232d899..d5ff1234 100644 --- a/tcconfig/tcset.py +++ b/tcconfig/tcset.py @@ -16,8 +16,10 @@ from .traffic_control import TrafficControl from ._argparse_wrapper import ArgparseWrapper -from ._common import ANYWHERE_NETWORK -from ._const import VERSION +from ._const import ( + VERSION, + ANYWHERE_NETWORK, +) from ._error import ModuleNotFoundError from ._error import NetworkInterfaceNotFoundError from ._logger import ( From 69db1761d2359e06a5fca45e8031099061f91ebb Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 22:56:29 +0900 Subject: [PATCH 4/8] Modify import declarations --- tcconfig/tcset.py | 6 ++++-- tcconfig/tcshow.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tcconfig/tcset.py b/tcconfig/tcset.py index d5ff1234..c623d245 100644 --- a/tcconfig/tcset.py +++ b/tcconfig/tcset.py @@ -20,8 +20,10 @@ VERSION, ANYWHERE_NETWORK, ) -from ._error import ModuleNotFoundError -from ._error import NetworkInterfaceNotFoundError +from ._error import ( + ModuleNotFoundError, + NetworkInterfaceNotFoundError, +) from ._logger import ( LOG_FORMAT_STRING, logger, diff --git a/tcconfig/tcshow.py b/tcconfig/tcshow.py index 0f71fe35..2b47aa85 100644 --- a/tcconfig/tcshow.py +++ b/tcconfig/tcshow.py @@ -16,8 +16,10 @@ import subprocrunner from subprocrunner import SubprocessRunner -from .parser import TcFilterParser -from .parser import TcQdiscParser +from .parser import ( + TcFilterParser, + TcQdiscParserm, +) from ._argparse_wrapper import ArgparseWrapper from ._common import verify_network_interface from ._const import VERSION From feddd76cd67876d8f432e9bb6949ea0f03453497 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 23:08:39 +0900 Subject: [PATCH 5/8] Fix the case that shaping rules not applied properly When using htb algorithm and not using network/port options. --- tcconfig/shaper/_interface.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tcconfig/shaper/_interface.py b/tcconfig/shaper/_interface.py index cb68f387..3f5dd84d 100644 --- a/tcconfig/shaper/_interface.py +++ b/tcconfig/shaper/_interface.py @@ -13,6 +13,7 @@ from subprocrunner import SubprocessRunner from .._common import run_command_helper +from .._const import ANYWHERE_NETWORK from .._iptables import ( IptablesMangleController, IptablesMangleMark @@ -112,18 +113,17 @@ def add_filter(self): command_list.append( "handle {:d} fw".format(self._get_unique_mangle_mark_id())) else: - if all([ - dataproperty.is_empty_string(self._tc_obj.network), - self._tc_obj.port is None, - ]): - logger.debug("no filter to be added.") - return 0 - - command_list.append("u32") - if dataproperty.is_not_empty_string(self._tc_obj.network): - command_list.append("match ip {:s} {:s}".format( - self._get_network_direction_str(), - self._tc_obj.network)) + if dataproperty.is_empty_string(self._tc_obj.network): + network = ANYWHERE_NETWORK + else: + network = self._tc_obj.network + + command_list.extend([ + "u32", + "match ip {:s} {:s}".format( + self._get_network_direction_str(), network), + ]) + if self._tc_obj.port is not None: command_list.append( "match ip dport {:d} 0xffff".format(self._tc_obj.port)) From 8cc85ae25d24b22083f7d8d262715da91450e6b3 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 23:13:33 +0900 Subject: [PATCH 6/8] Update setup.py --- setup.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup.py b/setup.py index 62afb5d1..b8624e67 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,9 @@ +# encoding: utf-8 + +""" +.. codeauthor:: Tsuyoshi Hombashi +""" + import os.path import setuptools import sys @@ -44,7 +50,10 @@ classifiers=[ "Development Status :: 4 - Beta", "Environment :: Console", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", "Intended Audience :: System Administrators", + "Intended Audience :: Telecommunications Industry", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", "Operating System :: POSIX :: Linux", @@ -56,6 +65,7 @@ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: System :: Networking", + "Topic :: System :: Systems Administration", ], entry_points={ "console_scripts": [ From 213e6d6d26cab0c09cd052ac48b3e37ce1594b2f Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 23:16:34 +0900 Subject: [PATCH 7/8] Fix typo --- tcconfig/tcshow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcconfig/tcshow.py b/tcconfig/tcshow.py index 2b47aa85..5f5e0e9e 100644 --- a/tcconfig/tcshow.py +++ b/tcconfig/tcshow.py @@ -18,7 +18,7 @@ from .parser import ( TcFilterParser, - TcQdiscParserm, + TcQdiscParser, ) from ._argparse_wrapper import ArgparseWrapper from ._common import verify_network_interface From c598358057e2fc9ff5b114935d450b869bc65e00 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Tue, 17 Jan 2017 23:19:35 +0900 Subject: [PATCH 8/8] Bump version to 0.7.0-alpha-4 --- tcconfig/_const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcconfig/_const.py b/tcconfig/_const.py index f5a337dd..629f9471 100644 --- a/tcconfig/_const.py +++ b/tcconfig/_const.py @@ -8,6 +8,6 @@ from __future__ import unicode_literals -VERSION = "0.7.0-alpha-3" +VERSION = "0.7.0-alpha-4" ANYWHERE_NETWORK = "0.0.0.0/0"