Merge pull request #51441 from Ch3LL/bp-51366

Backport #51366 into 2018.3.4
This commit is contained in:
Daniel Wozniak 2019-02-06 10:42:18 -07:00 committed by GitHub
commit 209ef32049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 7 deletions

View File

@ -1344,6 +1344,24 @@ class Cloud(object):
output['ret'] = action_out
return output
@staticmethod
def vm_config(name, main, provider, profile, overrides):
'''
Create vm config.
:param str name: The name of the vm
:param dict main: The main cloud config
:param dict provider: The provider config
:param dict profile: The profile config
:param dict overrides: The vm's config overrides
'''
vm = main.copy()
vm = salt.utils.dictupdate.update(vm, provider)
vm = salt.utils.dictupdate.update(vm, profile)
vm.update(overrides)
vm['name'] = name
return vm
def extras(self, extra_):
'''
Extra actions
@ -1430,12 +1448,13 @@ class Cloud(object):
ret[name] = {'Error': msg}
continue
vm_ = main_cloud_config.copy()
vm_.update(provider_details)
vm_.update(profile_details)
vm_.update(vm_overrides)
vm_['name'] = name
vm_ = self.vm_config(
name,
main_cloud_config,
provider_details,
profile_details,
vm_overrides,
)
if self.opts['parallel']:
process = multiprocessing.Process(
target=self.create,

View File

@ -267,9 +267,18 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
script_path = self.get_script_path(script)
if not os.path.isfile(script_path):
return False
popen_kwargs = popen_kwargs or {}
if salt.utils.platform.is_windows():
cmd = 'python '
if 'cwd' not in popen_kwargs:
popen_kwargs['cwd'] = os.getcwd()
if 'env' not in popen_kwargs:
popen_kwargs['env'] = os.environ.copy()
if sys.version_info[0] < 3:
popen_kwargs['env'][b'PYTHONPATH'] = os.getcwd().encode()
else:
popen_kwargs['env']['PYTHONPATH'] = os.getcwd()
else:
cmd = 'PYTHONPATH='
python_path = os.environ.get('PYTHONPATH', None)
@ -286,7 +295,6 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
tmp_file = tempfile.SpooledTemporaryFile()
popen_kwargs = popen_kwargs or {}
popen_kwargs = dict({
'shell': True,
'stdout': tmp_file,

View File

@ -1 +1,70 @@
# -*- coding: utf-8 -*-
'''
tests.unit.cloud
~~~~~~~~~~~~~~~~
'''
from __future__ import absolute_import, print_function, unicode_literals
from tests.support.unit import TestCase
import salt.cloud
class CloudTest(TestCase):
def test_vm_config_merger(self):
'''
Validate the vm's config is generated correctly.
https://github.com/saltstack/salt/issues/49226
'''
main = {
'minion': {'master': '172.31.39.213'},
'log_file': 'var/log/salt/cloud.log',
'pool_size': 10
}
provider = {
'private_key': 'dwoz.pem',
'grains': {'foo1': 'bar', 'foo2': 'bang'},
'availability_zone': 'us-west-2b',
'driver': 'ec2',
'ssh_interface': 'private_ips',
'ssh_username': 'admin',
'location': 'us-west-2'
}
profile = {
'profile': 'default',
'grains': {'meh2': 'bar', 'meh1': 'foo'},
'provider': 'ec2-default:ec2',
'ssh_username': 'admin',
'image': 'ami-0a1fbca0e5b419fd1',
'size': 't2.micro'
}
vm = salt.cloud.Cloud.vm_config(
'test_vm',
main,
provider,
profile,
{}
)
self.assertEqual({
'minion': {'master': '172.31.39.213'},
'log_file': 'var/log/salt/cloud.log',
'pool_size': 10,
'private_key': 'dwoz.pem',
'grains': {
'foo1': 'bar',
'foo2': 'bang',
'meh2': 'bar',
'meh1': 'foo',
},
'availability_zone': 'us-west-2b',
'driver': 'ec2',
'ssh_interface': 'private_ips',
'ssh_username': 'admin',
'location': 'us-west-2',
'profile': 'default',
'provider': 'ec2-default:ec2',
'image': 'ami-0a1fbca0e5b419fd1',
'size': 't2.micro',
'name': 'test_vm',
}, vm)