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
This commit is contained in:
Rajesh Tailor 2020-09-02 18:15:28 +05:30
parent 121b289f7e
commit fbf77c0776
3 changed files with 71 additions and 7 deletions

View File

@ -4,17 +4,50 @@
#
# === 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 $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;
}
}
}

View File

@ -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`.

View File

@ -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 => '<SERVICE DEFAULT>')
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({