Check that the return data from the cloud create function is a dictionary before attempting to pull values out.

This commit is contained in:
Gareth J. Greenaway 2023-04-28 17:55:26 -07:00 committed by Pedro Algarvio
parent 99deea7c2b
commit 34f2ed4b4e
3 changed files with 26 additions and 1 deletions

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

@ -0,0 +1 @@
Check that the return data from the cloud create function is a dictionary before attempting to pull values out.

View file

@ -1427,7 +1427,8 @@ class Cloud:
raise SaltCloudSystemExit("Failed to deploy VM")
continue
if self.opts.get("show_deploy_args", False) is False:
ret[name].pop("deploy_kwargs", None)
if isinstance(ret[name], dict):
ret[name].pop("deploy_kwargs", None)
except (SaltCloudSystemExit, SaltCloudConfigError) as exc:
if len(names) == 1:
raise

View file

@ -1,6 +1,7 @@
import pytest
from salt.cloud import Cloud
from salt.exceptions import SaltCloudSystemExit
from tests.support.mock import MagicMock, patch
@ -123,3 +124,25 @@ def test_vm_config_merger():
}
vm = Cloud.vm_config("test_vm", main, provider, profile, {})
assert expected == vm
def test_cloud_run_profile_create_returns_boolean(master_config):
master_config["profiles"] = {"test_profile": {"provider": "test_provider:saltify"}}
master_config["providers"] = {
"test_provider": {
"saltify": {"profiles": {"provider": "test_provider:saltify"}}
}
}
master_config["show_deploy_args"] = False
cloud = Cloud(master_config)
with patch.object(cloud, "create", return_value=True):
ret = cloud.run_profile("test_profile", ["test_vm"])
assert ret == {"test_vm": True}
cloud = Cloud(master_config)
with patch.object(cloud, "create", return_value=False):
with pytest.raises(SaltCloudSystemExit):
ret = cloud.run_profile("test_profile", ["test_vm"])
assert ret == {"test_vm": False}