Cleanup the sriov_numvfs config scripts
Clean 1) /etc/udev/rules.d/70-tripleo-reset-sriov.rules 2) /sbin/ifup-local 3) /etc/sysconfig/allocate_vfs Create /etc/udev/rules.d/70-os-net-config-sriov.rules for legacy PFs Change-Id: I17c8ef03501de75f0e3f7fb6c06be3478b1b5863
This commit is contained in:
parent
392354f4ff
commit
fb296079eb
|
@ -36,6 +36,8 @@ from oslo_concurrency import processutils
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
_SYS_CLASS_NET = '/sys/class/net'
|
_SYS_CLASS_NET = '/sys/class/net'
|
||||||
_UDEV_RULE_FILE = '/etc/udev/rules.d/80-persistent-os-net-config.rules'
|
_UDEV_RULE_FILE = '/etc/udev/rules.d/80-persistent-os-net-config.rules'
|
||||||
|
_UDEV_LEGACY_RULE_FILE = '/etc/udev/rules.d/70-os-net-config-sriov.rules'
|
||||||
|
_IFUP_LOCAL_FILE = '/sbin/ifup-local'
|
||||||
MAX_RETRIES = 10
|
MAX_RETRIES = 10
|
||||||
PF_FUNC_RE = re.compile(r"\.(\d+)$", 0)
|
PF_FUNC_RE = re.compile(r"\.(\d+)$", 0)
|
||||||
# In order to keep VF representor name consistent specially after the upgrade
|
# In order to keep VF representor name consistent specially after the upgrade
|
||||||
|
@ -122,6 +124,27 @@ def restart_ovs_and_pfs_netdevs():
|
||||||
if_up_interface(item['name'])
|
if_up_interface(item['name'])
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_puppet_config():
|
||||||
|
file_contents = ""
|
||||||
|
if os.path.exists('/etc/udev/rules.d/70-tripleo-reset-sriov.rules'):
|
||||||
|
os.remove('/etc/udev/rules.d/70-tripleo-reset-sriov.rules')
|
||||||
|
if os.path.exists('/etc/sysconfig/allocate_vfs'):
|
||||||
|
os.remove('/etc/sysconfig/allocate_vfs')
|
||||||
|
if os.path.exists(_IFUP_LOCAL_FILE):
|
||||||
|
# Remove the invocation of allocate_vfs script generated by puppet
|
||||||
|
# After the removal of allocate_vfs, if the ifup-local file has just
|
||||||
|
# "#!/bin/bash" left, then remove the file as well.
|
||||||
|
with open(_IFUP_LOCAL_FILE) as oldfile:
|
||||||
|
for line in oldfile:
|
||||||
|
if "/etc/sysconfig/allocate_vfs" not in line:
|
||||||
|
file_contents = file_contents + line
|
||||||
|
if file_contents.strip() == "#!/bin/bash":
|
||||||
|
os.remove(_IFUP_LOCAL_FILE)
|
||||||
|
else:
|
||||||
|
with open(_IFUP_LOCAL_FILE, 'w') as newfile:
|
||||||
|
newfile.write(file_contents)
|
||||||
|
|
||||||
|
|
||||||
def configure_sriov_pf(execution_from_cli=False, restart_openvswitch=False):
|
def configure_sriov_pf(execution_from_cli=False, restart_openvswitch=False):
|
||||||
# Create a context for pyudev and observe udev events for network
|
# Create a context for pyudev and observe udev events for network
|
||||||
context = pyudev.Context()
|
context = pyudev.Context()
|
||||||
|
@ -134,9 +157,18 @@ def configure_sriov_pf(execution_from_cli=False, restart_openvswitch=False):
|
||||||
MLNX_UNBIND_FILE_PATH = "/sys/bus/pci/drivers/mlx5_core/unbind"
|
MLNX_UNBIND_FILE_PATH = "/sys/bus/pci/drivers/mlx5_core/unbind"
|
||||||
MLNX_VENDOR_ID = "0x15b3"
|
MLNX_VENDOR_ID = "0x15b3"
|
||||||
trigger_udev_rule = False
|
trigger_udev_rule = False
|
||||||
|
|
||||||
|
# Cleanup the previous config by puppet-tripleo
|
||||||
|
cleanup_puppet_config()
|
||||||
|
|
||||||
for item in sriov_map:
|
for item in sriov_map:
|
||||||
if item['device_type'] == 'pf':
|
if item['device_type'] == 'pf':
|
||||||
_pf_interface_up(item)
|
_pf_interface_up(item)
|
||||||
|
if item.get('link_mode') == "legacy":
|
||||||
|
# Add a udev rule to configure the VF's when PF's are
|
||||||
|
# released by a guest
|
||||||
|
add_udev_rule_for_legacy_sriov_pf(item['name'],
|
||||||
|
item['numvfs'])
|
||||||
try:
|
try:
|
||||||
sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, item['name'],
|
sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, item['name'],
|
||||||
"device/sriov_numvfs")
|
"device/sriov_numvfs")
|
||||||
|
@ -197,6 +229,23 @@ def configure_sriov_pf(execution_from_cli=False, restart_openvswitch=False):
|
||||||
restart_ovs_and_pfs_netdevs()
|
restart_ovs_and_pfs_netdevs()
|
||||||
|
|
||||||
|
|
||||||
|
def _write_numvfs(device_name, numvfs):
|
||||||
|
|
||||||
|
sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, device_name,
|
||||||
|
"device/sriov_numvfs")
|
||||||
|
curr_numvfs = get_numvfs(device_name)
|
||||||
|
if curr_numvfs != 0:
|
||||||
|
logger.info("Numvfs already configured for %s" % device_name)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
with open(sriov_numvfs_path, 'w') as f:
|
||||||
|
f.write("%d" % numvfs)
|
||||||
|
except IOError as exc:
|
||||||
|
msg = ("Unable to configure pf: %s with numvfs: %d\n%s"
|
||||||
|
% (device_name, numvfs, exc))
|
||||||
|
raise SRIOVNumvfsException(msg)
|
||||||
|
|
||||||
|
|
||||||
def _wait_for_vf_creation(pf_name, numvfs):
|
def _wait_for_vf_creation(pf_name, numvfs):
|
||||||
vf_count = 0
|
vf_count = 0
|
||||||
vf_list = []
|
vf_list = []
|
||||||
|
@ -254,6 +303,14 @@ def add_udev_rule_for_sriov_pf(pf_name):
|
||||||
return add_udev_rule(udev_data_line, _UDEV_RULE_FILE)
|
return add_udev_rule(udev_data_line, _UDEV_RULE_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
def add_udev_rule_for_legacy_sriov_pf(pf_name, numvfs):
|
||||||
|
logger.info("adding udev rules for %s" % (pf_name))
|
||||||
|
udev_line = 'KERNEL=="%s", '\
|
||||||
|
'RUN+="/bin/os-net-config-sriov -n %%k:%d"' \
|
||||||
|
% (pf_name, numvfs)
|
||||||
|
return add_udev_rule(udev_line, _UDEV_LEGACY_RULE_FILE)
|
||||||
|
|
||||||
|
|
||||||
def add_udev_rule_for_vf_representors(pf_name):
|
def add_udev_rule_for_vf_representors(pf_name):
|
||||||
phys_switch_id_path = os.path.join(_SYS_CLASS_NET, pf_name,
|
phys_switch_id_path = os.path.join(_SYS_CLASS_NET, pf_name,
|
||||||
"phys_switch_id")
|
"phys_switch_id")
|
||||||
|
@ -481,6 +538,13 @@ def parse_opts(argv):
|
||||||
help="Print verbose output.",
|
help="Print verbose output.",
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-n', '--numvfs',
|
||||||
|
dest="numvfs",
|
||||||
|
action='store',
|
||||||
|
help="Provide the numvfs for device in the format <device>:<numvfs>",
|
||||||
|
required=False)
|
||||||
|
|
||||||
opts = parser.parse_args(argv[1:])
|
opts = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
|
@ -503,10 +567,18 @@ def configure_logger(verbose=False, debug=False):
|
||||||
def main(argv=sys.argv):
|
def main(argv=sys.argv):
|
||||||
opts = parse_opts(argv)
|
opts = parse_opts(argv)
|
||||||
configure_logger(opts.verbose, opts.debug)
|
configure_logger(opts.verbose, opts.debug)
|
||||||
# Configure the PF's
|
|
||||||
configure_sriov_pf()
|
if opts.numvfs:
|
||||||
# Configure the VFs
|
if re.match("^\w+:\d+$", opts.numvfs):
|
||||||
configure_sriov_vf()
|
device_name, numvfs = opts.numvfs.split(':')
|
||||||
|
_write_numvfs(device_name, int(numvfs))
|
||||||
|
else:
|
||||||
|
logging.error("Invalid arguments for --numvfs %s" % opts.numvfs)
|
||||||
|
else:
|
||||||
|
# Configure the PF's
|
||||||
|
configure_sriov_pf()
|
||||||
|
# Configure the VFs
|
||||||
|
configure_sriov_vf()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue