def test_properties_present(self):
        '''
        Test to check properties_present
        '''

        ret = {'name': 'name',
               'changes': {'data1': 'value1', 'data2': 'value2'},
               'result': True,
               'comment': 'Cluster properties configured'}

        mock_status = MagicMock(return_value=0)
        mock_configure_get_property = MagicMock()
        mock_configure_property = MagicMock()
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status,
                                            'crm.configure_get_property': mock_configure_get_property,
                                            'crm.configure_property': mock_configure_property}):
            assert crmshmod.cluster_properties_present(
                name='name',
                properties={'data1': 'value1', 'data2': 'value2'}) == ret
            mock_status.assert_called_once_with()
            mock_configure_get_property.assert_has_calls([
                mock.call(option='data1'),
                mock.call(option='data2')
            ])
            mock_configure_property.assert_has_calls([
                mock.call(option='data1', value='value1'),
                mock.call(option='data2', value='value2')
            ])
    def test_properties_present_no_cluster(self):
        '''
        Test to check properties_present when the cluster is not created
        '''

        ret = {'name': 'name',
               'changes': {},
               'result': False,
               'comment': 'Cluster is not created yet. Run cluster_initialized before'}

        mock_status = MagicMock(return_value=1)
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}):
            assert crmshmod.cluster_properties_present('name', {'data': 'value'}) == ret
            mock_status.assert_called_once_with()
    def test_properties_present_test(self):
        '''
        Test to check properties_present in test mode
        '''

        ret = {'name': 'name',
               'changes': {'data': 'value'},
               'result': None,
               'comment': 'Cluster properties would be configured'}

        mock_status = MagicMock(return_value=0)
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}):
            with patch.dict(crmshmod.__opts__, {'test': True}):
                assert crmshmod.cluster_properties_present('name', {'data': 'value'}) == ret
            mock_status.assert_called_once_with()
    def test_properties_present_error(self):
        '''
        Test to check properties_present with an error
        '''

        ret = {
            'name': 'name',
            'changes': {
                'data3': 'value3'
            },
            'result': False,
            'comment': 'Error configuring the properties data1, data2'
        }

        mock_status = MagicMock(return_value=0)
        mock_configure_get_property = MagicMock(side_effect=[
            exceptions.CommandExecutionError('err1'),
            exceptions.CommandExecutionError('err2'), "value3"
        ])
        mock_configure_property = MagicMock()
        # We need to create the dictionary this way, otherwise the items output is different in py2 and py3
        data = collections.OrderedDict()
        data['data1'] = 'value1'
        data['data2'] = 'value2'
        data['data3'] = 'value3'
        with patch.dict(
                crmshmod.__salt__, {
                    'crm.status': mock_status,
                    'crm.configure_get_property': mock_configure_get_property,
                    'crm.configure_property': mock_configure_property
                }):
            assert crmshmod.cluster_properties_present(name='name',
                                                       properties=data) == ret
            mock_status.assert_called_once_with()
            mock_configure_get_property.assert_has_calls([
                mock.call(option='data1'),
                mock.call(option='data2'),
                mock.call(option='data3')
            ])
            mock_configure_property.assert_has_calls(
                [mock.call(option='data3', value='value3')])