Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate enviroment for environment in heat modules #55641

Merged
merged 3 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions salt/modules/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def delete_stack(name=None, poll=0, timeout=60, profile=None):

def create_stack(name=None, template_file=None, environment=None,
parameters=None, poll=0, rollback=False, timeout=60,
profile=None, enviroment=None):
profile=None):
'''
Create a stack (heat stack-create)

Expand Down Expand Up @@ -472,16 +472,9 @@ def create_stack(name=None, template_file=None, environment=None,
.. versionadded:: 2017.7.5,2018.3.1

The spelling mistake in parameter `enviroment` was corrected to `environment`.
The misspelled version is still supported for backward compatibility, but will
be removed in Salt Neon.
The `enviroment` spelling mistake has been removed in Salt Neon.

'''
if environment is None and enviroment is not None:
salt.utils.versions.warn_until('Neon', (
"Please use the 'environment' parameter instead of the misspelled 'enviroment' "
"parameter which will be removed in Salt Neon."
))
environment = enviroment
h_client = _auth(profile)
ret = {
'result': True,
Expand All @@ -496,9 +489,11 @@ def create_stack(name=None, template_file=None, environment=None,
template=None,
source=template_file,
source_hash=None,
source_hash_name=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
context=None,
defaults=None,
Expand All @@ -514,6 +509,7 @@ def create_stack(name=None, template_file=None, environment=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
backup=None,
makedirs=True,
Expand Down Expand Up @@ -556,9 +552,11 @@ def create_stack(name=None, template_file=None, environment=None,
template=None,
source=environment,
source_hash=None,
source_hash_name=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
context=None,
defaults=None,
Expand All @@ -574,6 +572,7 @@ def create_stack(name=None, template_file=None, environment=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
backup=None,
makedirs=True,
Expand Down Expand Up @@ -626,7 +625,7 @@ def create_stack(name=None, template_file=None, environment=None,

def update_stack(name=None, template_file=None, environment=None,
parameters=None, poll=0, rollback=False, timeout=60,
profile=None, enviroment=None):
profile=None):
'''
Update a stack (heat stack-template)

Expand Down Expand Up @@ -667,16 +666,9 @@ def update_stack(name=None, template_file=None, environment=None,
.. versionadded:: 2017.7.5,2018.3.1

The spelling mistake in parameter `enviroment` was corrected to `environment`.
The misspelled version is still supported for backward compatibility, but will
be removed in Salt Neon.
The `enviroment` spelling mistake has been removed in Salt Neon.

'''
if environment is None and enviroment is not None:
salt.utils.versions.warn_until('Neon', (
"Please use the 'environment' parameter instead of the misspelled 'enviroment' "
"parameter which will be removed in Salt Neon."
))
environment = enviroment
h_client = _auth(profile)
ret = {
'result': True,
Expand All @@ -695,9 +687,11 @@ def update_stack(name=None, template_file=None, environment=None,
template=None,
source=template_file,
source_hash=None,
source_hash_name=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
context=None,
defaults=None,
Expand All @@ -713,6 +707,7 @@ def update_stack(name=None, template_file=None, environment=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
backup=None,
makedirs=True,
Expand Down Expand Up @@ -755,9 +750,11 @@ def update_stack(name=None, template_file=None, environment=None,
template=None,
source=environment,
source_hash=None,
source_hash_name=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
context=None,
defaults=None,
Expand All @@ -773,6 +770,7 @@ def update_stack(name=None, template_file=None, environment=None,
user=None,
group=None,
mode=None,
attrs=None,
saltenv='base',
backup=None,
makedirs=True,
Expand Down
12 changes: 2 additions & 10 deletions salt/states/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
.. versionadded:: 2017.7.5,2018.3.1

The spelling mistake in parameter `enviroment` was corrected to `environment`.
The misspelled version is still supported for backward compatibility, but will
be removed in Salt Neon.
The `enviroment` spelling mistake has been removed in Salt Neon.

'''
# Import Python libs
Expand Down Expand Up @@ -132,16 +131,9 @@ def deployed(name, template=None, environment=None, params=None, poll=5,
.. versionadded:: 2017.7.5,2018.3.1

The spelling mistake in parameter `enviroment` was corrected to `environment`.
The misspelled version is still supported for backward compatibility, but will
be removed in Salt Neon.
The `enviroment` spelling mistake has been removed in Salt Neon.

'''
if environment is None and 'enviroment' in connection_args:
salt.utils.versions.warn_until('Neon', (
"Please use the 'environment' parameter instead of the misspelled 'enviroment' "
"parameter which will be removed in Salt Neon."
))
environment = connection_args.pop('enviroment')
log.debug('Deployed with(' +
'{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})'
.format(name, template, environment, params, poll, rollback,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/files/file/base/templates/heat-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameter_defaults: ''
parameters: ''
resource_registry: ''
event_sinks: ''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HeatTemplateFormatVersion: 4.0
201 changes: 201 additions & 0 deletions tests/unit/modules/test_heat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# -*- coding: utf-8 -*-

# Import Python Libs
from __future__ import absolute_import, unicode_literals, print_function
import os

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.runtests import RUNTIME_VARS
from tests.support.mock import (
MagicMock,
patch,
)

# Import Salt Libs
import salt.utils.platform
import salt.modules.win_file
import salt.modules.heat as heat
import salt.modules.file as file_
import salt.modules.win_file as win_file
import salt.utils.win_dacl as dacl


class MockStacks(object):
'''
Mock stacks.StackManager
'''
def validate(self, **kwargs):
'''
Mock of stacks.StackManager.validate method
'''
self.mock_val_ret = MagicMock()
self.mock_val_ret.json.return_value = {'result': 'mocked response'}
self.mock_validate = MagicMock()
self.mock_validate.post.return_value = self.mock_val_ret
return self.mock_validate

def create(self, **kwargs):
self.mock_create_ret = MagicMock()
self.mock_create_ret.json.return_value = {'result': 'mocked create',
'fields': kwargs}
self.mock_create = MagicMock()
self.mock_create.post.return_value = self.mock_create_ret
return self.mock_create

def update(self, name, **kwargs):
self.mock_update_ret = MagicMock()
self.mock_update_ret.json.return_value = {'result': 'mocked update',
'fields': kwargs, 'name': name}
self.mock_update = MagicMock()
self.mock_update.post.return_value = self.mock_update_ret
return self.mock_update


class MockClient(object):
"""
Mock of Client class
"""
def __init__(self, profile=None, **conn_args):
self.stacks = MockStacks()


class HeatTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.heat
'''

def setup_loader_modules(self):
return {
heat: {
'_auth': MockClient,
},
file_: {
'__opts__': {'hash_type': 'sha256',
'cachedir': os.path.join(RUNTIME_VARS.TMP,
'rootdir', 'cache'),
'test': False},
'__salt__': {'config.option':
MagicMock(return_value={'obfuscate_templates':
False}),
'config.backup_mode':
MagicMock(return_value=False)}
},
win_file: {
'__utils__': {'dacl.check_perms': salt.utils.win_dacl.check_perms}
},
dacl: {'__opts__': {'test': False}},
}

def setUp(self):
self.patch_check = patch('salt.modules.file.check_perms', file_.check_perms)
if salt.utils.platform.is_windows():
self.patch_check = patch('salt.modules.file.check_perms', win_file.check_perms)

def test_heat_create_stack(self):
'''
Test salt.modules.heat.create_stack method
'''
patch_file = patch.dict(heat.__salt__,
{'file.get_managed': file_.get_managed,
'file.manage_file': file_.manage_file, },
)

with patch_file, self.patch_check:
ret = heat.create_stack(name='mystack',
profile='openstack1',
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'))
assert ret == {'result': True, 'comment': "Created stack 'mystack'."}

def test_heat_create_stack_environment(self):
'''
Test salt.modules.heat.create_stack method with environment set
'''
patch_file = patch.dict('salt.modules.heat.__salt__',
{'file.get_managed': file_.get_managed,
'file.manage_file': file_.manage_file, },
)
with patch_file, self.patch_check:
ret = heat.create_stack(name='mystack',
profile='openstack1',
environment=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-env.yml'),
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'))
assert ret == {'result': True, 'comment': "Created stack 'mystack'."}

def test_heat_create_stack_environment_err(self):
'''
Test salt.modules.heat.create_stack method with environment set
and there is an error reading the environment file
'''
patch_file = patch.dict('salt.modules.heat.__salt__',
{'file.get_managed': file_.get_managed,
'file.manage_file': MagicMock(side_effect=[{'result': True}, {'result': False}]), },
)
patch_template = patch('salt.modules.heat._parse_template', MagicMock(return_value=True))
env_file = os.path.join(RUNTIME_VARS.BASE_FILES, 'templates', 'heat-env.yml')
with patch_file, patch_template, self.patch_check:
ret = heat.create_stack(name='mystack',
profile='openstack1',
environment=env_file,
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'))
assert ret == {'result': False, 'comment': 'Can not open environment: {0}, '.format(env_file)}

def test_heat_update_stack(self):
'''
Test salt.modules.heat.update_method method
'''
patch_file = patch.dict(heat.__salt__,
{'file.get_managed': file_.get_managed,
'file.manage_file': file_.manage_file, },
)
with patch_file, self.patch_check:
ret = heat.update_stack(name='mystack',
profile='openstack1',
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'))
assert ret == {'result': True, 'comment': ("Updated stack 'mystack'.",)}

def test_heat_update_stack_env(self):
'''
Test salt.modules.heat.update_method method
with environment set
'''
patch_file = patch.dict(heat.__salt__,
{'file.get_managed': file_.get_managed,
'file.manage_file': file_.manage_file, },
)
with patch_file, self.patch_check:
ret = heat.update_stack(name='mystack',
profile='openstack1',
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'),
environment=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-env.yml'))
assert ret == {'result': True, 'comment': ("Updated stack 'mystack'.",)}

def test_heat_update_stack_env_err(self):
'''
Test salt.modules.heat.update_method method
with environment set and there is an error
reading the environment file
'''
patch_file = patch.dict(heat.__salt__,
{'file.get_managed': file_.get_managed,
'file.manage_file':
MagicMock(side_effect=[{'result': True},
{'result': False}]), }
)
with patch_file, self.patch_check:
ret = heat.update_stack(name='mystack',
profile='openstack1',
template_file=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-template.yml'),
environment=os.path.join(RUNTIME_VARS.BASE_FILES,
'templates', 'heat-env.yml'))
assert ret == {'result': False,
'comment': 'Error parsing template Template format version not found.'}
Loading