Skip to content

Commit

Permalink
Merge pull request #16 from stackhpc/stackhpc.sriov
Browse files Browse the repository at this point in the history
Adding sriov role .
  • Loading branch information
grzegorzkoper authored Nov 24, 2023
2 parents 1042776 + cdcd3b6 commit 48bc248
Show file tree
Hide file tree
Showing 23 changed files with 455 additions and 2 deletions.
2 changes: 1 addition & 1 deletion roles/grubcmdline/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
- ansible_facts.os_family == "RedHat"
- ansible_facts.distribution_version is version('8.0', '<=')

- name: Generate new grub config (Ubuntu/Debian) # noqa: no-changed-when
- name: Generate new grub config (Ubuntu/Debian) # noqa: no-changed-when
ansible.builtin.command: /usr/sbin/update-grub
become: true
when: ansible_facts.os_family == "Debian"
Expand Down
2 changes: 1 addition & 1 deletion roles/iommu/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.include_role:
name: stackhpc.linux.grubcmdline
vars:
kernel_cmdline: # noqa: var-naming[no-role-prefix]
kernel_cmdline: # noqa: var-naming[no-role-prefix]
- intel_iommu=on
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix]
- ^intel_iommu=
Expand Down
54 changes: 54 additions & 0 deletions roles/sriov/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
stackhpc.sriov
==============

[![Build Status](https://travis-ci.com/stackhpc/ansible-role-sriov.svg?branch=master)](https://travis-ci.com/stackhpc/ansible-role-sriov)

Ansible role to enable SR-IOV on network devices.

Requirements
------------
None

Role Variables
--------------

See `defaults/main.yml`

Dependencies
------------

- `stackhpc.grubcmdline`

Example Playbook
----------------

```
- name: configure sr-iov
hosts: compute
vars:
sriov_devices:
- name: p4p1
numvfs: 63
- name: p3p1
numvfs: 8
# Don't add a udev rule to set numvfs. This can be useful if you use an alternative method
# to set the number of virtual functions e.g some custom scripts to enable VFLAG, but want
# to use the role to set firmware parameters.
on_boot_configuration_enabled: false
tasks:
- include_role:
name: sriov
handlers:
- name: reboot
include_tasks: tasks/reboot.yml
```

License
-------

Apache2

Author Information
------------------

Will Szumski
34 changes: 34 additions & 0 deletions roles/sriov/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# List of NICs to configure
sriov_devices: []
sriov_workdir: "{{ ansible_facts.env.HOME }}/.sriov"

sriov_mft_url: https://www.mellanox.com/downloads/MFT/mft-4.23.0-104-x86_64-rpm.tgz

sriov_mft_tarball: "{{ sriov_mft_url | urlsplit('path') | basename }}"

sriov_os_pkgs:
- gcc
- rpm-build
# -E- Could not find lspci, you may need to install "pciutils" package
- pciutils
# NOTE(wszumski): Assumes running latest kernel. We could include package version with
# output of uname -r, but the packages aren't always available.
- kernel-devel
- make

sriov_restart_handler: reboot

sriov_numvfs: 8

sriov_udev_rule_path: /etc/udev/rules.d/70-sriov.rules

sriov_mellanox_vendor_ids:
- "0x15b3"

# Flag to skip installing any software dependencies. This may be useful if you
# are providing them by some other means.
sriov_install_enabled: true

# Set iommu=pt on the kernel cmdline
sriov_iommu_pt_enabled: true
1 change: 1 addition & 0 deletions roles/sriov/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
14 changes: 14 additions & 0 deletions roles/sriov/molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
22 changes: 22 additions & 0 deletions roles/sriov/molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ pip install 'molecule[docker]'
12 changes: 12 additions & 0 deletions roles/sriov/molecule/default/files/uname
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# MFT compile depends on detection of kernel version and architecture

if [ $1 = "-m" ]; then
echo "x86_64"
else
for f in /usr/src/kernels/*; do
echo $(basename $f)
break
done
fi
33 changes: 33 additions & 0 deletions roles/sriov/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: centos7-docker
image: mplachter/docker-centos7-molecule
command: /usr/sbin/init
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
provisioner:
name: ansible
ansible_args:
- --skip-tags=skip_when_testing
options:
become: true
lint:
name: ansible-lint
options:
R: true
scenario:
name: default
verifier:
name: testinfra
directory: ../tests
options:
verbose: true
lint:
name: flake8
10 changes: 10 additions & 0 deletions roles/sriov/molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Converge
hosts: all
roles:
- role: sriov
handlers:
- name: Simulate reboot
listen: reboot
ansible.builtin.debug:
msg: Simulating reboot
17 changes: 17 additions & 0 deletions roles/sriov/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Install kernel packages and replace uname
hosts: all
tasks:
- name: Install kernel packages
ansible.builtin.package:
name:
- kernel
- kernel-devel
state: present
- name: Replace uname to fix detection of kernel and architecture in docker
ansible.builtin.copy:
src: files/uname
dest: /bin/uname
owner: root
group: root
mode: "0755"
3 changes: 3 additions & 0 deletions roles/sriov/molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- src: git+https://github.com/stackhpc/ansible-role-grubcmdline
name: stackhpc.grubcmdline
11 changes: 11 additions & 0 deletions roles/sriov/molecule/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_stub(host):
# TODO: add some tests
pass
23 changes: 23 additions & 0 deletions roles/sriov/molecule/vagrant/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*******
Vagrant driver installation guide
*******

Requirements
============

* Vagrant
* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ pip install 'molecule[vagrant]'
31 changes: 31 additions & 0 deletions roles/sriov/molecule/vagrant/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
dependency:
name: galaxy
driver:
name: vagrant
provider:
name: virtualbox
lint:
name: yamllint
platforms:
- name: bento-centos-7-vagrant
box: bento/centos-7
cpus: 1
memory: 1024
provisioner:
name: ansible
options:
become: true
lint:
name: ansible-lint
options:
R: true
scenario:
name: vagrant
verifier:
name: testinfra
directory: ../tests
options:
verbose: true
lint:
name: flake8
5 changes: 5 additions & 0 deletions roles/sriov/molecule/vagrant/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: sriov
9 changes: 9 additions & 0 deletions roles/sriov/molecule/vagrant/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install python for Ansible
ansible.builtin.raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
become: true
changed_when: false
6 changes: 6 additions & 0 deletions roles/sriov/tasks/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Include config tasks
ansible.builtin.include_tasks: config.yml

- name: Include mellanox tasks
ansible.builtin.include_tasks: mellanox.yml
40 changes: 40 additions & 0 deletions roles/sriov/tasks/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
- name: Persist sriov_numvfs with udev rule
ansible.builtin.blockinfile:
path: "{{ sriov_udev_rule_path }}"
block: |
{% for device in sriov_devices %}
{% if device.on_boot_configuration_enabled | default(true) | bool %}
SUBSYSTEM=="net", ACTION=="add", KERNEL=="{{ device.name }}", RUN+="/usr/bin/sh -c 'echo {{ device.numvfs | default(sriov_numvfs) }} > /sys/class/net/{{ device.name }}/device/sriov_numvfs'"
{% endif %}
{% endfor %}
marker_begin: BEGIN SRIOV
mode: "0644"
owner: root
group: root
create: true
become: true
notify: "{{ sriov_restart_handler }}"

- name: Add iommu to kernel command line (Intel)
ansible.builtin.include_role:
name: stackhpc.grubcmdline
tags: skip_when_testing
vars:
kernel_cmdline: # noqa var-naming[no-role-prefix]
- intel_iommu=on
kernel_cmdline_remove: # noqa var-naming[no-role-prefix]
- ^intel_iommu=
kernel_restart_handler: "{{ sriov_restart_handler }}"
when: "'Intel' in ansible_facts.processor.0"

- name: Set iommu=pt
ansible.builtin.include_role:
name: stackhpc.grubcmdline
tags: skip_when_testing
vars:
kernel_cmdline: # noqa var-naming[no-role-prefix]
- iommu=pt
kernel_cmdline_remove: # noqa var-naming[no-role-prefix]
- ^iommu=
kernel_restart_handler: "{{ sriov_restart_handler }}"
3 changes: 3 additions & 0 deletions roles/sriov/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Include action tasks
ansible.builtin._include: "{{ sriov_action | default('all') }}.yml"
Loading

0 comments on commit 48bc248

Please sign in to comment.