From 9ba567119e7899394eda49ea189b712c748e7682 Mon Sep 17 00:00:00 2001 From: Steven Webster Date: Wed, 23 Oct 2019 09:42:45 -0500 Subject: [PATCH] Traffic control fixes and refresh This commit fixes a couple of issues surrounding the main StarlingX traffic control script. The following has been changed: - The name of the script has been changed to remove the 'cgcs_' prefix - It was discovered that traffic controls were not being set on a multi-netted interface shared by aliased management and cluster-host interfaces. This is because aliased interfaces do not support a 'post-up' command in their network-script configuration file. Depends-On: https://review.opendev.org/691414 Partial-Bug: #1839386 Change-Id: I27c699415d80ff10f5eac162ae3a6be17ec59c7a Signed-off-by: Steven Webster --- .../controllerconfig/common/constants.py | 1 - .../sysinv/sysinv/sysinv/common/constants.py | 3 ++ .../sysinv/sysinv/sysinv/puppet/interface.py | 31 +++++++++------- .../sysinv/tests/puppet/test_interface.py | 37 +++++++++---------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/controllerconfig/controllerconfig/controllerconfig/common/constants.py b/controllerconfig/controllerconfig/controllerconfig/common/constants.py index 48a6f2318b..6f0059c7a8 100644 --- a/controllerconfig/controllerconfig/controllerconfig/common/constants.py +++ b/controllerconfig/controllerconfig/controllerconfig/common/constants.py @@ -32,7 +32,6 @@ INSTALLATION_FAILED_FILE = '/etc/platform/installation_failed' BACKUPS_PATH = '/opt/backups' INTERFACES_LOG_FILE = "/tmp/configure_interfaces.log" -TC_SETUP_SCRIPT = '/usr/local/bin/cgcs_tc_setup.sh' LINK_MTU_DEFAULT = "1500" diff --git a/sysinv/sysinv/sysinv/sysinv/common/constants.py b/sysinv/sysinv/sysinv/sysinv/common/constants.py index 0d75d2fc7b..acb25b8b7d 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/constants.py +++ b/sysinv/sysinv/sysinv/sysinv/common/constants.py @@ -1530,3 +1530,6 @@ DRIVER_MLX_CX4 = 'mlx5_core' MELLANOX_DRIVERS = [DRIVER_MLX_CX3, DRIVER_MLX_CX4] + +# Traffic control +TRAFFIC_CONTROL_SCRIPT = '/usr/local/bin/tc_setup.sh' diff --git a/sysinv/sysinv/sysinv/sysinv/puppet/interface.py b/sysinv/sysinv/sysinv/sysinv/puppet/interface.py index c13ce289c4..63bf85efca 100644 --- a/sysinv/sysinv/sysinv/sysinv/puppet/interface.py +++ b/sysinv/sysinv/sysinv/sysinv/puppet/interface.py @@ -668,19 +668,19 @@ def get_interface_address_method(context, iface, network_id=None): return DHCP_METHOD -def get_interface_traffic_classifier(context, iface, network_id=None): +def get_interface_traffic_classifier(context, iface): """ Get the interface traffic classifier command line (if any) """ - networktype = find_networktype_by_network_id(context, network_id) - if (networktype and - networktype == constants.NETWORK_TYPE_MGMT): - networkspeed = constants.LINK_SPEED_10G - ifname = get_interface_os_ifname(context, iface) - return '/usr/local/bin/cgcs_tc_setup.sh %s %s %s > /dev/null' \ - % (ifname, - networktype, - networkspeed) + for networktype in iface.networktypelist: + if (networktype == constants.NETWORK_TYPE_MGMT): + networkspeed = constants.LINK_SPEED_10G + ifname = get_interface_os_ifname(context, iface) + return '%s %s %s %s > /dev/null' \ + % (constants.TRAFFIC_CONTROL_SCRIPT, + ifname, + networktype, + networkspeed) return None @@ -1013,10 +1013,13 @@ def get_common_network_config(context, iface, config, network_id=None): """ LOG.debug("get_common_network_config %s %s network_id=%s" % (iface.ifname, iface.networktypelist, network_id)) - traffic_classifier = get_interface_traffic_classifier(context, iface, - network_id) - if traffic_classifier: - config['options']['post_up'] = traffic_classifier + + os_ifname = get_interface_os_ifname(context, iface) + if os_ifname == config['ifname']: + # post-up scripts do not work for aliases. + traffic_classifier = get_interface_traffic_classifier(context, iface) + if traffic_classifier: + config['options']['post_up'] = traffic_classifier method = get_interface_address_method(context, iface, network_id) if method == STATIC_METHOD: diff --git a/sysinv/sysinv/sysinv/sysinv/tests/puppet/test_interface.py b/sysinv/sysinv/sysinv/sysinv/tests/puppet/test_interface.py index ca3c651eeb..6c631d6276 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/puppet/test_interface.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/puppet/test_interface.py @@ -675,40 +675,35 @@ class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase): def test_get_interface_traffic_classifier_for_mgmt(self): self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM - self.iface['networktype'] = constants.NETWORK_TYPE_MGMT + self.iface['networktypelist'] = [constants.NETWORK_TYPE_MGMT] self.iface['networks'] = self._get_network_ids_by_type( constants.NETWORK_TYPE_MGMT) - network = self.dbapi.network_get_by_type( - constants.NETWORK_TYPE_MGMT) classifier = interface.get_interface_traffic_classifier( - self.context, self.iface, network.id) + self.context, self.iface) print(self.context) - expected = ('/usr/local/bin/cgcs_tc_setup.sh %s %s %s > /dev/null' % - (self.port['name'], constants.NETWORK_TYPE_MGMT, + expected = ('%s %s %s %s > /dev/null' % + (constants.TRAFFIC_CONTROL_SCRIPT, + self.port['name'], constants.NETWORK_TYPE_MGMT, constants.LINK_SPEED_10G)) self.assertEqual(classifier, expected) def test_get_interface_traffic_classifier_for_cluster_host(self): self.iface['ifname'] = 'cluster_host0' self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM - self.iface['networktype'] = constants.NETWORK_TYPE_CLUSTER_HOST + self.iface['networktypelist'] = [constants.NETWORK_TYPE_CLUSTER_HOST] self.iface['networks'] = self._get_network_ids_by_type( constants.NETWORK_TYPE_CLUSTER_HOST) - network = self.dbapi.network_get_by_type( - constants.NETWORK_TYPE_CLUSTER_HOST) classifier = interface.get_interface_traffic_classifier( - self.context, self.iface, network.id) + self.context, self.iface) self.assertIsNone(classifier) def test_get_interface_traffic_classifier_for_oam(self): self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM - self.iface['networktype'] = constants.NETWORK_TYPE_OAM + self.iface['networktypelist'] = [constants.NETWORK_TYPE_OAM] self.iface['networks'] = self._get_network_ids_by_type( constants.NETWORK_TYPE_OAM) - network = self.dbapi.network_get_by_type( - constants.NETWORK_TYPE_OAM) classifier = interface.get_interface_traffic_classifier( - self.context, self.iface, network.id) + self.context, self.iface) self.assertIsNone(classifier) def test_get_interface_traffic_classifier_for_none(self): @@ -998,7 +993,7 @@ class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase): def test_get_controller_ethernet_config_mgmt(self): self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM - self.iface['networktype'] = constants.NETWORK_TYPE_MGMT + self.iface['networktypelist'] = [constants.NETWORK_TYPE_MGMT] self.iface['networks'] = self._get_network_ids_by_type( constants.NETWORK_TYPE_MGMT) self._update_context() @@ -1010,8 +1005,9 @@ class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase): options = {'IPV6_AUTOCONF': 'no', 'LINKDELAY': '20', 'post_up': - '/usr/local/bin/cgcs_tc_setup.sh %s %s %s > /dev/null' % - (self.port['name'], constants.NETWORK_TYPE_MGMT, + '%s %s %s %s > /dev/null' % + (constants.TRAFFIC_CONTROL_SCRIPT, + self.port['name'], constants.NETWORK_TYPE_MGMT, constants.LINK_SPEED_10G)} expected = self._get_static_network_config( ifname=self.port['name'], mtu=1500, gateway='192.168.204.1', @@ -1130,7 +1126,7 @@ class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase): def test_get_worker_ethernet_config_mgmt(self): self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM - self.iface['networktype'] = constants.NETWORK_TYPE_MGMT + self.iface['networktypelist'] = [constants.NETWORK_TYPE_MGMT] self.iface['networks'] = self._get_network_ids_by_type( constants.NETWORK_TYPE_MGMT) self.host['personality'] = constants.WORKER @@ -1143,8 +1139,9 @@ class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase): options = {'IPV6_AUTOCONF': 'no', 'LINKDELAY': '20', 'post_up': - '/usr/local/bin/cgcs_tc_setup.sh %s %s %s > /dev/null' % - (self.port['name'], constants.NETWORK_TYPE_MGMT, + '%s %s %s %s > /dev/null' % + (constants.TRAFFIC_CONTROL_SCRIPT, + self.port['name'], constants.NETWORK_TYPE_MGMT, constants.LINK_SPEED_10G)} expected = self._get_network_config( ifname=self.port['name'], mtu=1500, options=options)