2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch
|
2013-06-27 00:30:49 +00:00
|
|
|
|
|
|
|
# Import Salt libs
|
|
|
|
from salt.modules import config
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
|
|
|
|
config.__opts__ = config.__pillar__ = {}
|
|
|
|
|
|
|
|
__opts__ = {
|
|
|
|
'test.option.all': 'value of test.option.all in __opts__'
|
2013-01-19 14:02:06 +00:00
|
|
|
}
|
2013-09-28 22:50:30 +00:00
|
|
|
__pillar__ = {
|
|
|
|
'test.option.all': 'value of test.option.all in __pillar__',
|
|
|
|
'master': {
|
|
|
|
'test.option.all': 'value of test.option.all in master'
|
2013-01-19 14:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
DEFAULTS = {
|
|
|
|
'test.option.all': 'value of test.option.all in DEFAULTS',
|
|
|
|
'test.option': 'value of test.option in DEFAULTS'
|
|
|
|
}
|
2013-01-19 14:02:06 +00:00
|
|
|
|
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2013-01-19 14:02:06 +00:00
|
|
|
class TestModulesConfig(TestCase):
|
2013-09-28 22:50:30 +00:00
|
|
|
def test_defaults_only_name(self):
|
|
|
|
with patch.dict(config.DEFAULTS, DEFAULTS):
|
|
|
|
opt_name = 'test.option'
|
|
|
|
opt = config.option(opt_name)
|
|
|
|
self.assertEqual(opt, config.DEFAULTS[opt_name])
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
def test_omits(self):
|
|
|
|
with patch.dict(config.DEFAULTS, DEFAULTS):
|
|
|
|
with patch.dict(config.__pillar__, __pillar__):
|
|
|
|
with patch.dict(config.__opts__, __opts__):
|
|
|
|
opt_name = 'test.option.all'
|
|
|
|
opt = config.option(opt_name,
|
|
|
|
omit_opts=False,
|
|
|
|
omit_master=True,
|
|
|
|
omit_pillar=True)
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
self.assertEqual(opt, config.__opts__[opt_name])
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
opt = config.option(opt_name,
|
|
|
|
omit_opts=True,
|
|
|
|
omit_master=True,
|
|
|
|
omit_pillar=False)
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
self.assertEqual(opt, config.__pillar__[opt_name])
|
|
|
|
opt = config.option(opt_name,
|
|
|
|
omit_opts=True,
|
|
|
|
omit_master=False,
|
|
|
|
omit_pillar=True)
|
2013-01-19 14:02:06 +00:00
|
|
|
|
2013-09-28 22:50:30 +00:00
|
|
|
self.assertEqual(
|
|
|
|
opt, config.__pillar__['master'][opt_name])
|