本文整理汇总了Python中salt.state.HighState.merge_tops方法的典型用法代码示例。如果您正苦于以下问题:Python HighState.merge_tops方法的具体用法?Python HighState.merge_tops怎么用?Python HighState.merge_tops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.state.HighState
的用法示例。
在下文中一共展示了HighState.merge_tops方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TopFileMergeTestCase
# 需要导入模块: from salt.state import HighState [as 别名]
# 或者: from salt.state.HighState import merge_tops [as 别名]
class TopFileMergeTestCase(TestCase):
'''
Test various merge strategies for multiple tops files collected from
multiple environments. Various options correspond to merge strategies
which can be set by the user with the top_file_merging_strategy config
option.
Refs #12483
'''
def setUp(self):
'''
Create multiple top files for use in each test
'''
self.env1 = {'base': {'*': ['e1_a', 'e1_b', 'e1_c']}}
self.env2 = {'base': {'*': ['e2_a', 'e2_b', 'e2_c']}}
self.env3 = {'base': {'*': ['e3_a', 'e3_b', 'e3_c']}}
self.config = self._make_default_config()
self.highstate = HighState(self.config)
def _make_default_config(self):
config = salt.config.minion_config(None)
root_dir = tempfile.mkdtemp(dir=integration.TMP)
state_tree_dir = os.path.join(root_dir, 'state_tree')
cache_dir = os.path.join(root_dir, 'cachedir')
config['root_dir'] = root_dir
config['state_events'] = False
config['id'] = 'match'
config['file_client'] = 'local'
config['file_roots'] = dict(base=[state_tree_dir])
config['cachedir'] = cache_dir
config['test'] = False
return config
def _get_tops(self):
'''
A test helper to emulate HighState.get_tops() but just to construct
an appropriate data structure for top files from multiple environments
'''
tops = DefaultOrderedDict(list)
tops['a'].append(self.env1)
tops['b'].append(self.env2)
tops['c'].append(self.env3)
return tops
def test_basic_merge(self):
'''
This is the default approach for Salt. Merge the top files with the
earlier appends taking precendence. Since Salt does the appends
lexecographically, this is effectively a test against the default
lexecographical behaviour.
'''
merged_tops = self.highstate.merge_tops(self._get_tops())
expected_merge = DefaultOrderedDict(OrderedDict)
expected_merge['base']['*'] = ['e1_c', 'e1_b', 'e1_a']
self.assertEqual(merged_tops, expected_merge)
def test_merge_strategy_same(self):
'''
Test to see if the top file that corresponds
to the requested env is the one that is used
by the state system
'''
config = self._make_default_config()
config['top_file_merging_strategy'] = 'same'
config['environment'] = 'b'
highstate = HighState(config)
ret = highstate.get_tops()
self.assertEqual(ret, OrderedDict([('b', [{}])]))
def test_ordered_merge(self):
'''
Test to see if the merger respects environment
ordering
'''
config = self._make_default_config()
config['top_file_merging_strategy'] = 'merge'
config['env_order'] = ['b', 'a', 'c']
with patch('salt.fileclient.FSClient.envs', MagicMock(return_value=['a', 'b', 'c'])):
highstate = HighState(config)
ret = highstate.get_tops()
self.assertEqual(ret, OrderedDict([('a', [{}]), ('c', [{}]), ('b', [{}])]))