Fix salt-cloud get_cloud_config_value for list objects

This commit is contained in:
Zhiwei Liang 2024-01-10 14:30:35 -05:00 committed by Daniel Wozniak
parent 857c840762
commit f01483ff92
3 changed files with 52 additions and 2 deletions

1
changelog/65789.fixed.md Normal file
View file

@ -0,0 +1 @@
Fix salt-cloud get_cloud_config_value for list objects

View file

@ -3248,7 +3248,9 @@ def get_cloud_config_value(name, vm_, opts, default=None, search_global=True):
# Let's get the value from the profile, if present
if "profile" in vm_ and vm_["profile"] is not None:
if name in opts["profiles"][vm_["profile"]]:
if isinstance(value, dict):
if isinstance(value, dict) and isinstance(
opts["profiles"][vm_["profile"]][name], dict
):
value.update(opts["profiles"][vm_["profile"]][name].copy())
else:
value = deepcopy(opts["profiles"][vm_["profile"]][name])

View file

@ -1,6 +1,7 @@
import pytest
from salt.cloud import Cloud
from salt.config import get_cloud_config_value
from salt.exceptions import SaltCloudSystemExit
from tests.support.mock import MagicMock, patch
@ -194,7 +195,6 @@ def test_vm_config_merger_nooverridevalue():
@pytest.mark.skip_on_fips_enabled_platform
def test_cloud_run_profile_create_returns_boolean(master_config):
master_config["profiles"] = {"test_profile": {"provider": "test_provider:saltify"}}
master_config["providers"] = {
"test_provider": {
@ -213,3 +213,50 @@ def test_cloud_run_profile_create_returns_boolean(master_config):
with pytest.raises(SaltCloudSystemExit):
ret = cloud.run_profile("test_profile", ["test_vm"])
assert ret == {"test_vm": False}
@pytest.mark.parametrize(
"value",
[
[{"key1": "value1"}, {"key1": "value1", "key2": "value2"}],
["a", "b"],
[1, 2, 4],
{"key1": "value1", "key2": 123},
"some text",
1234,
],
)
def test_get_cloud_config_value(value):
value_name = "test_value_name"
opts = {
"providers": {
"my-cool-cloud-provider": {
"cool-cloud": {
"driver": "cool-cloud",
"profiles": {
"my-cool-cloud-profile": {
"provider": "my-cool-cloud-provider:cool-cloud",
value_name: value,
"profile": "my-cool-cloud-profile",
}
},
}
}
},
"profiles": {
"my-cool-cloud-profile": {
"provider": "my-cool-cloud-provider:cool-cloud",
value_name: value,
"profile": "my-cool-cloud-profile",
}
},
"profile": "my-cool-cloud-profile",
}
vm_ = {
value_name: value,
"profile": "my-cool-cloud-profile",
"driver": "cool-cloud",
}
result = get_cloud_config_value(value_name, vm_, opts)
assert result == value