aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-27 16:47:33 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-27 16:47:33 +0000
commitc07a248d10a4cd3c451983a9856eec590e2bfd3d (patch)
tree6bcb0507998c16e4e78f34ffa838c6ca5c377a4a
parentdaf594dd65a8a22bf8aaaf4d56df5ff965a15749 (diff)
parent88e2120ee8905bb66eb56e37d8910c0e63faebf6 (diff)
Merge "Improve OVS-DPDK setup process"
-rw-r--r--yardstick/benchmark/contexts/standalone/ovs_dpdk.py44
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py47
2 files changed, 58 insertions, 33 deletions
diff --git a/yardstick/benchmark/contexts/standalone/ovs_dpdk.py b/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
index 23b167f83..ee0eb9e0d 100644
--- a/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
+++ b/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
@@ -48,8 +48,8 @@ class OvsDpdkContext(Context):
}
DEFAULT_OVS = '2.6.0'
- PKILL_TEMPLATE = "pkill %s %s"
CMD_TIMEOUT = 30
+ DEFAULT_USER_PATH = '/usr/local'
def __init__(self):
self.file_path = None
@@ -91,34 +91,32 @@ class OvsDpdkContext(Context):
LOG.debug("Networks: %r", self.networks)
def setup_ovs(self):
- vpath = self.ovs_properties.get("vpath", "/usr/local")
- xargs_kill_cmd = self.PKILL_TEMPLATE % ('-9', 'ovs')
-
+ """Initialize OVS-DPDK"""
+ vpath = self.ovs_properties.get('vpath', self.DEFAULT_USER_PATH)
create_from = os.path.join(vpath, 'etc/openvswitch/conf.db')
create_to = os.path.join(vpath, 'share/openvswitch/vswitch.ovsschema')
cmd_list = [
- "chmod 0666 /dev/vfio/*",
- "chmod a+x /dev/vfio",
- "pkill -9 ovs",
- xargs_kill_cmd,
- "killall -r 'ovs*'",
- "mkdir -p {0}/etc/openvswitch".format(vpath),
- "mkdir -p {0}/var/run/openvswitch".format(vpath),
- "rm {0}/etc/openvswitch/conf.db".format(vpath),
- "ovsdb-tool create {0} {1}".format(create_from, create_to),
- "modprobe vfio-pci",
- "chmod a+x /dev/vfio",
- "chmod 0666 /dev/vfio/*",
+ 'killall -r "ovs.*" -q | true',
+ 'mkdir -p {0}/etc/openvswitch'.format(vpath),
+ 'mkdir -p {0}/var/run/openvswitch'.format(vpath),
+ 'rm {0}/etc/openvswitch/conf.db | true'.format(vpath),
+ 'ovsdb-tool create {0} {1}'.format(create_from, create_to),
+ 'modprobe vfio-pci',
+ 'chmod a+x /dev/vfio',
+ 'chmod 0666 /dev/vfio/*',
]
- for cmd in cmd_list:
- self.connection.execute(cmd)
- bind_cmd = "{dpdk_devbind} --force -b {driver} {port}"
- phy_driver = "vfio-pci"
+
+ bind_cmd = '%s --force -b vfio-pci {port}' % self.dpdk_devbind
for port in self.networks.values():
- vpci = port.get("phy_port")
- self.connection.execute(bind_cmd.format(
- dpdk_devbind=self.dpdk_devbind, driver=phy_driver, port=vpci))
+ cmd_list.append(bind_cmd.format(port=port.get('phy_port')))
+
+ for cmd in cmd_list:
+ LOG.info(cmd)
+ exit_status, _, stderr = self.connection.execute(
+ cmd, timeout=self.CMD_TIMEOUT)
+ if exit_status:
+ raise exceptions.OVSSetupError(command=cmd, error=stderr)
def start_ovs_serverswitch(self):
vpath = self.ovs_properties.get("vpath")
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
index cc4747708..3ca0b9b8a 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -32,7 +32,6 @@ class OvsDpdkContextTestCase(unittest.TestCase):
NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml"
NETWORKS = {
- 'mgmt': {'cidr': '152.16.100.10/24'},
'private_0': {
'phy_port': "0000:05:00.0",
'vpci': "0000:00:07.0",
@@ -87,15 +86,43 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.assertIsNone(self.ovs_dpdk.init(ATTRS))
def test_setup_ovs(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "a", ""))
- ssh.return_value = ssh_mock
- self.ovs_dpdk.connection = ssh_mock
- self.ovs_dpdk.networks = self.NETWORKS
- self.ovs_dpdk.ovs_properties = {}
- self.assertIsNone(self.ovs_dpdk.setup_ovs())
+ fake_path = '/fake_path'
+ fake_dpdk_nic_bind = 'dpdk_tool.py'
+ self.ovs_dpdk.ovs_properties = {'vpath': fake_path}
+ self.ovs_dpdk.dpdk_devbind = fake_dpdk_nic_bind
+ self.ovs_dpdk.networks = self.NETWORKS
+ self.ovs_dpdk.connection = mock.Mock()
+ self.ovs_dpdk.connection.execute = mock.Mock(return_value=(0, 0, 0))
+ create_from = fake_path + '/etc/openvswitch/conf.db'
+ create_to = fake_path + '/share/openvswitch/vswitch.ovsschema'
+ cmd_list = [
+ 'killall -r "ovs.*" -q | true',
+ 'mkdir -p {0}/etc/openvswitch'.format(fake_path),
+ 'mkdir -p {0}/var/run/openvswitch'.format(fake_path),
+ 'rm {0}/etc/openvswitch/conf.db | true'.format(fake_path),
+ 'ovsdb-tool create {0} {1}'.format(create_from, create_to),
+ 'modprobe vfio-pci',
+ 'chmod a+x /dev/vfio',
+ 'chmod 0666 /dev/vfio/*',
+ '{0} --force -b vfio-pci {1}'.format(fake_dpdk_nic_bind,
+ self.ovs_dpdk.networks['private_0']['phy_port']),
+ '{0} --force -b vfio-pci {1}'.format(fake_dpdk_nic_bind,
+ self.ovs_dpdk.networks['public_0']['phy_port'])
+ ]
+ calls = [mock.call(cmd, timeout=self.ovs_dpdk.CMD_TIMEOUT)
+ for cmd in cmd_list]
+
+ self.ovs_dpdk.setup_ovs()
+ self.ovs_dpdk.connection.execute.assert_has_calls(calls,
+ any_order=True)
+
+ def test_setup_ovs_exception(self):
+ self.ovs_dpdk.networks = self.NETWORKS
+ self.ovs_dpdk.connection = mock.Mock()
+ self.ovs_dpdk.connection.execute = mock.Mock(return_value=(1, 0, 0))
+
+ with self.assertRaises(exceptions.OVSSetupError):
+ self.ovs_dpdk.setup_ovs()
def test_start_ovs_serverswitch(self):
with mock.patch("yardstick.ssh.SSH") as ssh: