Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions setup_ovs/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Copyright (C) 2021, RTE (http://www.rte-france.com)
# SPDX-License-Identifier: Apache-2.0

import functools
import os
import re
import shutil
import subprocess
import logging

Expand All @@ -17,6 +20,24 @@
dry_run = False


@functools.lru_cache(maxsize=None)
def find_command(logical_name, *candidates):
"""Locate a system command by trying candidate names/paths."""
for candidate in candidates:
if os.path.isabs(candidate):
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
logging.debug("Found %s at %s", logical_name, candidate)
return candidate
else:
resolved = shutil.which(candidate)
if resolved:
logging.debug("Found %s at %s (via PATH)", logical_name, resolved)
return resolved
raise FileNotFoundError(
"Could not find {}: looked for {}".format(logical_name, ", ".join(candidates))
)


def run_command(*cmd_args, **kargs):
"""
Shell runner helper
Expand Down
11 changes: 8 additions & 3 deletions setup_ovs/ovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ def clear_tap(config):
interface,
)

_DPDK_DEVBIND_CANDIDATES = (
"/usr/bin/dpdk-devbind.py",
"/usr/sbin/dpdk-devbind",
)


def _bind_dpdk_interfaces(dpdk_interfaces):
"""
Bind NIC in DPDK
"""
dpdk_devbind = helpers.find_command("dpdk-devbind", *_DPDK_DEVBIND_CANDIDATES)
for nic in dpdk_interfaces:
logging.info("Attach {} to DPDK".format(nic))
helpers.run_command(
"/usr/sbin/dpdk-devbind", "--force", "--bind=vfio-pci", nic
)
helpers.run_command(dpdk_devbind, "--force", "--bind=vfio-pci", nic)


def _create_bridges(config, dpdk_bridges):
Expand Down