def test_corosync_updated_test(self, mock_mergedicts, mock_convert2dict): ''' Test to check corosync_updated in test mode ''' ret = { 'name': '/etc/corosync/corosync.conf', 'changes': { 'data': 1 }, 'result': None, 'comment': 'Corosync configuration would be update' } mock_convert2dict.return_value = ({}, {}) mock_mergedicts.return_value = ({}, {'data': 1}) file_content = "my corosync file content\nmy corosync file 2nd line content" with patch.dict(crmshmod.__opts__, {'test': True}): with patch("salt.utils.files.fopen", mock_open(read_data=file_content)): assert crmshmod.corosync_updated( name='/etc/corosync/corosync.conf', data={'my_data': 1}) == ret mock_convert2dict.assert_called_once_with( ['my corosync file content', 'my corosync file 2nd line content']) mock_mergedicts.assert_called_once_with({}, {'my_data': 1}, {})
def test_corosync_updated_already(self, mock_mergedicts, mock_convert2dict): ''' Test to check corosync_updated when configuration is already applied ''' ret = { 'name': '/etc/corosync/corosync.conf', 'changes': {}, 'result': True, 'comment': 'Corosync already has the required configuration' } mock_convert2dict.return_value = ({'data': 1}, {}) mock_mergedicts.return_value = ({}, {}) file_content = "my corosync file content\nmy corosync file 2nd line content" with patch("salt.utils.files.fopen", mock_open(read_data=file_content)): assert crmshmod.corosync_updated( name='/etc/corosync/corosync.conf', data={'my_data': 1}) == ret mock_convert2dict.assert_called_once_with( ['my corosync file content', 'my corosync file 2nd line content']) mock_mergedicts.assert_called_once_with({'data': 1}, {'my_data': 1}, {})
def test_corosync_updated(self, mock_mergedicts, mock_convert2dict, mock_convert2corosync): ''' Test to check corosync_updated when configuration is applied ''' ret = { 'name': '/etc/corosync/corosync.conf', 'changes': { 'change1': 1, 'change2': 2 }, 'result': True, 'comment': 'Corosync configuration file updated' } mock_copy = MagicMock() mock_write = MagicMock() mock_convert2dict.return_value = ({'data': 1}, {}) mock_mergedicts.return_value = ({ 'updated': 2 }, { 'change1': 1, 'change2': 2 }) mock_convert2corosync.return_value = 'new content' file_content = "my corosync file content\nmy corosync file 2nd line content" with patch.dict(crmshmod.__salt__, { 'file.copy': mock_copy, 'file.write': mock_write }): with patch("salt.utils.files.fopen", mock_open(read_data=file_content)): assert crmshmod.corosync_updated( name='/etc/corosync/corosync.conf', data={'my_data': 1}) == ret mock_convert2dict.assert_called_once_with( ['my corosync file content', 'my corosync file 2nd line content']) mock_mergedicts.assert_called_once_with({'data': 1}, {'my_data': 1}, {}) mock_convert2corosync.assert_called_once_with({'updated': 2}) mock_copy.assert_called_once_with( '/etc/corosync/corosync.conf', '/etc/corosync/corosync.conf.backup') mock_write.assert_called_once_with('/etc/corosync/corosync.conf', 'new content')