From 84a12d8b37ed0fbf23f4c2a8585b05c17b8f550a Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 22 Sep 2021 22:19:20 +0900 Subject: [PATCH] Rename vgpu options to mdev ... following the renaming in nova[1]. [1] ff4d0d002a35022df1cb71029ad82ad8f3b327df Change-Id: I166691118deaabc89d4bf351d2022ce7b72b26b0 --- manifests/compute.pp | 2 + manifests/compute/mdev.pp | 55 +++++++++++++++++++ manifests/compute/vgpu.pp | 32 +++-------- .../notes/generic-mdevs-627ccb29320cd442.yaml | 5 ++ spec/classes/nova_compute_mdev_spec.rb | 47 ++++++++++++++++ spec/classes/nova_compute_vgpu_spec.rb | 14 ++--- 6 files changed, 124 insertions(+), 31 deletions(-) create mode 100644 manifests/compute/mdev.pp create mode 100644 releasenotes/notes/generic-mdevs-627ccb29320cd442.yaml create mode 100644 spec/classes/nova_compute_mdev_spec.rb diff --git a/manifests/compute.pp b/manifests/compute.pp index d04e7c3d0..21868971f 100644 --- a/manifests/compute.pp +++ b/manifests/compute.pp @@ -378,6 +378,8 @@ class nova::compute ( } include nova::compute::pci + # TODO(tkajinam): Replace this by nova::compute::mdev when we remove + # nova::compute::vgpu include nova::compute::vgpu if ($vnc_enabled and $spice_enabled) { diff --git a/manifests/compute/mdev.pp b/manifests/compute/mdev.pp new file mode 100644 index 000000000..ace076aef --- /dev/null +++ b/manifests/compute/mdev.pp @@ -0,0 +1,55 @@ +# Class nova::compute::mdev +# +# Configures nova compute mdev options +# +# === Parameters: +# +# [*mdev_types_device_addresses_mapping*] +# (optional) Map of mdev type(s) the instances can get as key and list of +# corresponding device addresses as value. +# Defaults to {} +# +class nova::compute::mdev( + $mdev_types_device_addresses_mapping = {}, +) { + include nova::deps + + # TODO(tkajinam): Remove this when we remove nova::compute::vgpu + $mdev_types_device_addresses_mapping_real = pick( + $::nova::compute::vgpu::vgpu_types_device_addresses_mapping, + $mdev_types_device_addresses_mapping) + + if !empty($mdev_types_device_addresses_mapping_real) { + validate_legacy(Hash, 'validate_hash', $mdev_types_device_addresses_mapping_real) + $mdev_types_real = keys($mdev_types_device_addresses_mapping_real) + nova_config { + 'devices/enabled_mdev_types': value => join(any2array($mdev_types_real), ','); + } + + # TODO(tkajinam): Remove this when we remove nova::compute::vgpu + nova_config { + 'devices/enabled_vgpu_types': ensure => absent; + } + + $mdev_types_device_addresses_mapping_real.each |$mdev_type, $device_addresses| { + if !empty($device_addresses) { + nova_config { + "mdev_${mdev_type}/device_addresses": value => join(any2array($device_addresses), ','); + } + + # TODO(tkajinam): Remove this when we remove nova::compute::vgpu + nova_config { + "vgpu_${mdev_type}/device_addresses": ensure => absent; + } + } else { + nova_config { + "mdev_${mdev_type}/device_addresses": ensure => absent; + } + } + } + } else { + nova_config { + 'devices/enabled_mdev_types': ensure => absent; + } + } +} diff --git a/manifests/compute/vgpu.pp b/manifests/compute/vgpu.pp index feb646aa2..4ea36bd24 100644 --- a/manifests/compute/vgpu.pp +++ b/manifests/compute/vgpu.pp @@ -1,5 +1,6 @@ # Class nova::compute::vgpu # +# DEPRECATED !! # Configures nova compute vgpu options # # === Parameters: @@ -7,34 +8,17 @@ # [*vgpu_types_device_addresses_mapping*] # (optional) Map of vgpu type(s) the instances can get as key and list of # corresponding device addresses as value. -# Defaults to {} +# Defaults to undef # class nova::compute::vgpu( - $vgpu_types_device_addresses_mapping = {}, + $vgpu_types_device_addresses_mapping = undef, ) { include nova::deps - if !empty($vgpu_types_device_addresses_mapping) { - validate_legacy(Hash, 'validate_hash', $vgpu_types_device_addresses_mapping) - $vgpu_types_real = keys($vgpu_types_device_addresses_mapping) - nova_config { - 'devices/enabled_vgpu_types': value => join(any2array($vgpu_types_real), ','); - } - - $vgpu_types_device_addresses_mapping.each |$vgpu_type, $device_addresses| { - if !empty($device_addresses) { - nova_config { - "vgpu_${vgpu_type}/device_addresses": value => join(any2array($device_addresses), ','); - } - } else { - nova_config { - "vgpu_${vgpu_type}/device_addresses": ensure => absent; - } - } - } - } else { - nova_config { - 'devices/enabled_vgpu_types': ensure => absent; - } + if $vgpu_types_device_addresses_mapping != undef or ! defined(Class[nova::compute]) { + # NOTE(tkajinam): If the nova::compute class is not yet included then it is + # likely this class is included explicitly. + warning('The nova::compute::vgpu class is deprecated. Use the nova::compute::mdev class instead') } + include nova::compute::mdev } diff --git a/releasenotes/notes/generic-mdevs-627ccb29320cd442.yaml b/releasenotes/notes/generic-mdevs-627ccb29320cd442.yaml new file mode 100644 index 000000000..4aea7d7e6 --- /dev/null +++ b/releasenotes/notes/generic-mdevs-627ccb29320cd442.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - | + The ``nova::compute::vgpu`` class has been deprecated in favor of the new + ``nova::compute::mdev`` class. diff --git a/spec/classes/nova_compute_mdev_spec.rb b/spec/classes/nova_compute_mdev_spec.rb new file mode 100644 index 000000000..c17039e75 --- /dev/null +++ b/spec/classes/nova_compute_mdev_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe 'nova::compute::mdev' do + + shared_examples_for 'nova-compute-mdev' do + context 'with default parameters' do + it 'clears mdev devices' do + is_expected.to contain_nova_config('devices/enabled_mdev_types').with_ensure('absent') + end + end + + context 'with mdev types and device addresses mapping' do + let :params do + { + :mdev_types_device_addresses_mapping => { "nvidia-35" => [] }, + } + end + it { is_expected.to contain_nova_config('devices/enabled_mdev_types').with_value('nvidia-35') } + it { is_expected.to contain_nova_config('mdev_nvidia-35/device_addresses').with_ensure('absent') } + end + + context 'with multiple mdev types and corresponding device addresses mapping' do + let :params do + { + :mdev_types_device_addresses_mapping => { "nvidia-35" => ['0000:84:00.0', '0000:85:00.0'], + "nvidia-36" => ['0000:86:00.0'] } + } + end + + it { is_expected.to contain_nova_config('devices/enabled_mdev_types').with_value('nvidia-35,nvidia-36') } + it { is_expected.to contain_nova_config('mdev_nvidia-35/device_addresses').with_value('0000:84:00.0,0000:85:00.0') } + it { is_expected.to contain_nova_config('mdev_nvidia-36/device_addresses').with_value('0000:86:00.0') } + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_configures 'nova-compute-mdev' + end + end +end diff --git a/spec/classes/nova_compute_vgpu_spec.rb b/spec/classes/nova_compute_vgpu_spec.rb index f28d7c3e8..1352c3203 100644 --- a/spec/classes/nova_compute_vgpu_spec.rb +++ b/spec/classes/nova_compute_vgpu_spec.rb @@ -5,18 +5,18 @@ describe 'nova::compute::vgpu' do shared_examples_for 'nova-compute-vgpu' do context 'with default parameters' do it 'clears vgpu devices' do - is_expected.to contain_nova_config('devices/enabled_vgpu_types').with_ensure('absent') + is_expected.to contain_nova_config('devices/enabled_mdev_types').with_ensure('absent') end end context 'with vgpu types and device addresses mapping' do let :params do { - :vgpu_types_device_addresses_mapping => { "nvidia-35" => [] }, + :vgpu_types_device_addresses_mapping => { "nvidia-35" => [] }, } end - it { is_expected.to contain_nova_config('devices/enabled_vgpu_types').with_value('nvidia-35') } - it { is_expected.to contain_nova_config('vgpu_nvidia-35/device_addresses').with_ensure('absent') } + it { is_expected.to contain_nova_config('devices/enabled_mdev_types').with_value('nvidia-35') } + it { is_expected.to contain_nova_config('mdev_nvidia-35/device_addresses').with_ensure('absent') } end context 'with multiple vgpu types and corresponding device addresses mapping' do @@ -27,9 +27,9 @@ describe 'nova::compute::vgpu' do } end - it { is_expected.to contain_nova_config('devices/enabled_vgpu_types').with_value('nvidia-35,nvidia-36') } - it { is_expected.to contain_nova_config('vgpu_nvidia-35/device_addresses').with_value('0000:84:00.0,0000:85:00.0') } - it { is_expected.to contain_nova_config('vgpu_nvidia-36/device_addresses').with_value('0000:86:00.0') } + it { is_expected.to contain_nova_config('devices/enabled_mdev_types').with_value('nvidia-35,nvidia-36') } + it { is_expected.to contain_nova_config('mdev_nvidia-35/device_addresses').with_value('0000:84:00.0,0000:85:00.0') } + it { is_expected.to contain_nova_config('mdev_nvidia-36/device_addresses').with_value('0000:86:00.0') } end end