From 055d795440b4f3a1f5d245a0de94045efbb61ff1 Mon Sep 17 00:00:00 2001 From: Aleksandr Didenko Date: Wed, 2 Mar 2016 13:38:37 +0100 Subject: [PATCH] Add SR-IOV and IOMMU configuration check Check if SR-IOV and IOMMU are properly configured for using in virtual machines on compute nodes before trying to configure SR-IOV in Nova. Change-Id: Ide5dfc4779864442b0765e1101d67240398b2f18 Implements: blueprint support-sriov --- .../modular/netconfig/sriov_iommu_check.rb | 52 +++++++++++++++++++ .../modular/netconfig/tasks.yaml | 10 ++++ 2 files changed, 62 insertions(+) create mode 100644 deployment/puppet/osnailyfacter/modular/netconfig/sriov_iommu_check.rb diff --git a/deployment/puppet/osnailyfacter/modular/netconfig/sriov_iommu_check.rb b/deployment/puppet/osnailyfacter/modular/netconfig/sriov_iommu_check.rb new file mode 100644 index 0000000000..7f9ff34a5b --- /dev/null +++ b/deployment/puppet/osnailyfacter/modular/netconfig/sriov_iommu_check.rb @@ -0,0 +1,52 @@ +#!/usr/bin/env ruby +# +# This script checks thats SR-IOV and IOMMU are properly configured +# for using in virtual machines. +# +# Example of network scheme with SR-IOV enabled NIC +# +# network_scheme: +# transformations: +# - action: add-port +# name: em1 +# provider: sriov + +require 'hiera' + +ENV['LANG'] = 'C' +errors = 0 + +hiera = Hiera.new(:config => '/etc/hiera.yaml') +transformations = hiera.lookup( + 'network_scheme', {}, {}, + order_override = nil, + resolution_type = :hash + )['transformations'] + +unless transformations.is_a?(Array) + puts "ERROR: Network tranformations not found in Hiera" + exit 1 +end + +transformations.each do |t| + if t["action"] == "add-port" and t["provider"] == "sriov" + int = t["name"] + begin + if File.exist?("/sys/class/net/#{int}/device/sriov_totalvfs") and + File.readlink("/sys/class/net/#{int}/device/iommu_group") != + File.readlink("/sys/class/net/#{int}/device/virtfn0/iommu_group") and + Dir["/sys/class/net/#{int}/device/virtfn0/iommu_group/devices/*:*"].length == 1 + + puts "OK: SR-IOV and IOMMU are properly configured for #{int} interface" + else + puts "ERROR: SR-IOV and IOMMU are not properly configured for #{int} interface" + errors += 1 + end + rescue + puts "ERROR: Was not able to check SR-IOV and IOMMU for #{int} interface" + errors += 1 + end + end +end + +exit 1 unless errors == 0 diff --git a/deployment/puppet/osnailyfacter/modular/netconfig/tasks.yaml b/deployment/puppet/osnailyfacter/modular/netconfig/tasks.yaml index 6a2724c150..942bb348f8 100644 --- a/deployment/puppet/osnailyfacter/modular/netconfig/tasks.yaml +++ b/deployment/puppet/osnailyfacter/modular/netconfig/tasks.yaml @@ -27,6 +27,16 @@ timeout: 3600 cwd: / +- id: sriov_iommu_check + type: shell + version: 2.0.0 + groups: [compute] + requires: [netconfig] + required_for: [firewall, hosts] + parameters: + cmd: ruby /etc/puppet/modules/osnailyfacter/modular/netconfig/sriov_iommu_check.rb + timeout: 30 + - id: reserved_ports type: puppet version: 2.0.0