commit d9cd5ad37d48910ffbc8dd8e21e48911bb2085f4 Author: Rajesh Tailor Date: Wed Sep 2 18:15:28 2020 +0530 Add new parameter `vgpu_types_device_addresses_mapping` To support multiple vgpu types configuration, add new parameter `vgpu_types_device_addresses_mapping` where vgpu-type is key and list of device_addresses are value. Also deprecate `enabled_vgpu_types` parameter and instead use newly added parameter. Change-Id: I2e66a68ad831e2d25a757793babaf31277c11eb2 (cherry picked from commit fbf77c0776f2aac341dc7a54a6a82243681d6354) diff --git a/manifests/compute/vgpu.pp b/manifests/compute/vgpu.pp index 2da7bb3..9ccea4a 100644 --- a/manifests/compute/vgpu.pp +++ b/manifests/compute/vgpu.pp @@ -4,17 +4,55 @@ # # === Parameters: # -# [*enabled_vgpu_types*] +# [*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 {} +# +# DEPRECATED PARAMETERS +# +# [*enabled_vgpu_types*] # (optional) Specify which specific GPU type(s) the instances can get -# Defaults to $::os_service_default -# Example: 'nvidia-35' or ['nvidia-35', 'nvidia-36'] +# Defaults to undef +# class nova::compute::vgpu( - $enabled_vgpu_types = $::os_service_default + $vgpu_types_device_addresses_mapping = {}, + # DEPRECATED PARAMETERS + $enabled_vgpu_types = undef, ) { include nova::deps - nova_config { - 'devices/enabled_vgpu_types': value => join(any2array($enabled_vgpu_types), ','); + if $enabled_vgpu_types { + warning('enabled_vgpu_types is deprecated, instead use vgpu_types_device_addresses_mapping parameter.') + + if !empty($vgpu_types_device_addresses_mapping) { + warning('vgpu_types_device_addresses_mapping is ignored, when both enabled_vgpu_types \ +and vgpu_types_device_addresses_mapping are defined.') + } + } + + if $enabled_vgpu_types != undef and !empty($enabled_vgpu_types) { + nova_config { + 'devices/enabled_vgpu_types': value => join(any2array($enabled_vgpu_types), ','); + } + } elsif !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 { + 'devices/enabled_vgpu_types': ensure => absent; + } } } diff --git a/releasenotes/notes/vgpu-devices-mapping-7553b329d58fa8c4.yaml b/releasenotes/notes/vgpu-devices-mapping-7553b329d58fa8c4.yaml new file mode 100644 index 0000000..c35d99c --- /dev/null +++ b/releasenotes/notes/vgpu-devices-mapping-7553b329d58fa8c4.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + Add parameter `vgpu_types_device_addresses_mapping` to provide mapping + for multiple vgpu devices and corresponding device addresses. +deprecations: + - | + Deprecate parameter `enabled_vgpu_types` which was used for providing + list of vgpu devices and instead use `vgpu_types_device_addresses_mapping`. diff --git a/spec/classes/nova_compute_vgpu_spec.rb b/spec/classes/nova_compute_vgpu_spec.rb index de6f276..224cf19 100644 --- a/spec/classes/nova_compute_vgpu_spec.rb +++ b/spec/classes/nova_compute_vgpu_spec.rb @@ -5,7 +5,7 @@ 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(:value => '') + is_expected.to contain_nova_config('devices/enabled_vgpu_types').with_ensure('absent') end end @@ -22,6 +22,15 @@ describe 'nova::compute::vgpu' do end end + context 'with vgpu types and device addresses mapping' do + let :params do + { + :vgpu_types_device_addresses_mapping => { "nvidia-35" => [] }, + } + end + it { is_expected.to contain_nova_config('devices/enabled_vgpu_types').with_value('nvidia-35') } + end + context 'with multiple vgpu devices' do let :params do { @@ -35,6 +44,19 @@ describe 'nova::compute::vgpu' do ) end end + + context 'with multiple vgpu types and corresponding device addresses mapping' do + let :params do + { + :vgpu_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_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') } + end end on_supported_os({