pci: Drop support for "broken" json

JSON does not allow usage of single quotes and require double quotes.
We have been converting single quotes to support such invalid usage but
that was deprecated a long ago[1].

This also simplifies the logic to handle aliases. Using undef results
in the value set to service default fact.

[1] 1cd349f893

Change-Id: If1328531f33a9fe778091ce38b5c1f8072b473b8
This commit is contained in:
Takashi Kajinami 2023-11-03 22:58:18 +09:00
parent 09d19b9d52
commit f8bde51891
5 changed files with 7 additions and 17 deletions

View File

@ -18,14 +18,7 @@ Puppet::Functions.create_function(:to_array_of_json_strings) do
list = args[0]
if list.class == String
begin
begin
list = JSON.load(list)
rescue JSON::ParserError
# If parsing failed it could be a legacy format that uses single quotes.
# NB This will corrupt valid JSON data, e.g {"foo": "\'"} => {"foo": "\""}
list = JSON.load(list.gsub("'","\""))
Puppet.warning("#{args[0]} is not valid JSON. Support for this format is deprecated and may be removed in future.")
end
list = JSON.load(list)
rescue JSON::ParserError
raise Puppet::ParseError, "Syntax error: #{args[0]} is not valid"
end

View File

@ -21,13 +21,12 @@ class nova::compute::pci(
) {
include nova::deps
if $passthrough and
!is_service_default($passthrough) and
!empty($passthrough) {
if !is_service_default($passthrough) and !empty($passthrough) {
$passthrough_real = to_array_of_json_strings($passthrough)
} else {
$passthrough_real = $facts['os_service_default']
}
nova_config {
'pci/device_spec': value => $passthrough_real;
'pci/report_in_placement': value => $report_in_placement;

View File

@ -16,9 +16,7 @@ class nova::pci(
) {
include nova::deps
if $aliases and
!is_service_default($aliases) and
!empty($aliases) {
if !is_service_default($aliases) and !empty($aliases) {
$aliases_real = to_array_of_json_strings($aliases)
} else {
$aliases_real = $facts['os_service_default']

View File

@ -45,7 +45,7 @@ describe 'nova::compute::pci' do
end
end
context 'with passthrough JSON encoded string (deprecated)' do
context 'with passthrough JSON encoded string' do
let :params do
{
:passthrough => "[{\"vendor_id\":\"8086\",\"product_id\":\"0126\"},{\"vendor_id\":\"9096\",\"product_id\":\"1520\",\"physical_network\":\"physnet1\"}]",

View File

@ -32,7 +32,7 @@ describe 'nova::pci' do
end
end
context 'with aliases JSON encoded string (deprecated)' do
context 'with aliases JSON encoded string' do
let :params do
{
:aliases => "[{\"vendor_id\":\"8086\",\"product_id\":\"0126\",\"name\":\"graphic_card\"},{\"vendor_id\":\"9096\",\"product_id\":\"1520\",\"name\":\"network_card\"}]",
@ -81,4 +81,4 @@ describe 'nova::pci' do
it_configures 'nova-pci'
end
end
end
end