Skip to content

Commit

Permalink
Fix salt-cloud get_cloud_config_value for list objects
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Jan 10, 2024
1 parent 73922a7 commit f342a4a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/65789.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix salt-cloud get_cloud_config_value for list objects
4 changes: 3 additions & 1 deletion salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
49 changes: 48 additions & 1 deletion tests/pytests/unit/cloud/test_cloud.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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": {
Expand All @@ -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

0 comments on commit f342a4a

Please sign in to comment.