Merge "Migrate "ethtool" to oslo.privsep"

This commit is contained in:
Zuul 2020-08-14 22:58:44 +00:00 committed by Gerrit Code Review
commit 8441737127
5 changed files with 23 additions and 29 deletions

View File

@ -10,7 +10,6 @@
# dhcp-agent
dnsmasq: CommandFilter, dnsmasq, root
ethtool: CommandFilter, ethtool, root
# dhcp-agent uses kill as well, that's handled by the generic KillFilter
# it looks like these are the only signals needed, per
# neutron/agent/linux/dhcp.py

View File

@ -12,7 +12,6 @@
arping: CommandFilter, arping, root
# l3_agent
ethtool: CommandFilter, ethtool, root
sysctl: CommandFilter, sysctl, root
route: CommandFilter, route, root
radvd: CommandFilter, radvd, root

View File

@ -24,12 +24,12 @@ from oslo_utils import excutils
from pyroute2.netlink import exceptions as pyroute2_exc
from neutron.agent.common import ovs_lib
from neutron.agent.linux import ethtool
from neutron.agent.linux import ip_lib
from neutron.common import utils
from neutron.conf.plugins.ml2.drivers import ovs_conf
from neutron.plugins.ml2.drivers.openvswitch.agent.common \
import constants as ovs_const
from neutron.privileged.agent.linux import ethtool
LOG = logging.getLogger(__name__)
@ -439,8 +439,8 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
# ovs-dpdk does not do checksum calculations for veth interface
# (bug 1832021)
if self.conf.OVS.datapath_type == ovs_const.OVS_DATAPATH_NETDEV:
ethtool.Ethtool.offload(ns_dev.name, rx=False, tx=False,
namespace=namespace)
ethtool.offload(ns_dev.name, rx=False, tx=False,
namespace=namespace)
root_dev.link.set_up()
def unplug(self, device_name, bridge=None, namespace=None, prefix=None):

View File

@ -1,4 +1,4 @@
# Copyright 2020 OpenStack Foundation
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -13,22 +13,19 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron.agent.linux import ip_lib
from oslo_concurrency import processutils
from neutron import privileged
COMMAND = 'ethtool'
class Ethtool(object):
COMMAND = 'ethtool'
@staticmethod
def _cmd(cmd, namespace, **kwargs):
ip_wrapper = ip_lib.IPWrapper(namespace)
return ip_wrapper.netns.execute(cmd, run_as_root=True, **kwargs)
@classmethod
def offload(cls, device, rx, tx, namespace=None):
rx = 'on' if rx else 'off'
tx = 'on' if tx else 'off'
cmd = ['--offload', device, 'rx', rx, 'tx', tx]
cmd = [cls.COMMAND] + cmd
cls._cmd(cmd, namespace)
@privileged.default.entrypoint
def offload(device, rx, tx, namespace=None):
cmd = []
if namespace:
cmd += ['ip', 'netns', 'exec', namespace]
rx = 'on' if rx else 'off'
tx = 'on' if tx else 'off'
cmd += [COMMAND, '--offload', device, 'rx', rx, 'tx', tx]
return processutils.execute(*cmd)

View File

@ -20,7 +20,6 @@ from oslo_utils import excutils
from pyroute2.netlink import exceptions as pyroute2_exc
from neutron.agent.common import ovs_lib
from neutron.agent.linux import ethtool
from neutron.agent.linux import interface
from neutron.agent.linux import ip_lib
from neutron.common import utils
@ -28,6 +27,7 @@ from neutron.conf.agent import common as config
from neutron.conf.plugins.ml2.drivers import ovs_conf
from neutron.plugins.ml2.drivers.openvswitch.agent.common \
import constants as ovs_const
from neutron.privileged.agent.linux import ethtool
from neutron.tests import base
@ -78,8 +78,8 @@ class TestBase(base.BaseTestCase):
self.conf = config.setup_conf()
ovs_conf.register_ovs_opts(self.conf)
config.register_interface_opts(self.conf)
self.eth_tool_p = mock.patch.object(ethtool, 'Ethtool')
self.eth_tool = self.eth_tool_p.start()
self.eth_offload_p = mock.patch.object(ethtool, 'offload')
self.eth_offload = self.eth_offload_p.start()
self.ip_dev_p = mock.patch.object(ip_lib, 'IPDevice')
self.ip_dev = self.ip_dev_p.start()
self.ip_p = mock.patch.object(ip_lib, 'IPWrapper')
@ -591,9 +591,8 @@ class TestOVSInterfaceDriverWithVeth(TestOVSInterfaceDriver):
self.ip.assert_has_calls(expected)
root_dev.assert_has_calls([mock.call.link.set_up()])
ns_dev.assert_has_calls([mock.call.link.set_up()])
self.eth_tool.assert_has_calls([mock.call.offload(
devname, rx=False,
tx=False, namespace=namespace)])
self.eth_offload.assert_has_calls(
[mock.call(devname, rx=False, tx=False, namespace=namespace)])
def test_plug_new(self):
# The purpose of test_plug_new in parent class(TestOVSInterfaceDriver)