コード例 #1
0
    def test_present(self):
        '''
        Test to ensure the RabbitMQ policy exists.
        '''
        name = 'HA'
        pattern = '.*'
        definition = '{"ha-mode":"all"}'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': ''}

        mock = MagicMock(side_effect=[{'/': {name: {'pattern': pattern,
                                                    'definition': definition,
                                                    'priority': 0}}}, {}])
        with patch.dict(rabbitmq_policy.__salt__,
                        {'rabbitmq.list_policies': mock}):
            comt = ('Policy / HA is already present')
            ret.update({'comment': comt})
            self.assertDictEqual(rabbitmq_policy.present(name, pattern,
                                                         definition), ret)

            with patch.dict(rabbitmq_policy.__opts__, {'test': True}):
                comment = 'Policy / HA is set to be created'
                changes = {'new': 'HA', 'old': {}}
                ret.update({'comment': comment, 'result': None, 'changes': changes})
                self.assertDictEqual(rabbitmq_policy.present(name, pattern,
                                                             definition), ret)
コード例 #2
0
ファイル: rabbitmq_policy_test.py プロジェクト: mjura/salt-1
    def test_present(self):
        '''
        Test to ensure the RabbitMQ policy exists.
        '''
        name = 'HA'
        pattern = '.*'
        definition = '{"ha-mode":"all"}'

        ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}

        mock = MagicMock(side_effect=[{
            '/': {
                name: {
                    'pattern': pattern,
                    'definition': definition,
                    'priority': 0
                }
            }
        }, {}])
        with patch.dict(rabbitmq_policy.__salt__,
                        {'rabbitmq.list_policies': mock}):
            comt = ('Policy / HA is already present')
            ret.update({'comment': comt})
            self.assertDictEqual(
                rabbitmq_policy.present(name, pattern, definition), ret)

            with patch.dict(rabbitmq_policy.__opts__, {'test': True}):
                comt = ('Policy / HA is set to be created')
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(
                    rabbitmq_policy.present(name, pattern, definition), ret)
コード例 #3
0
def test_present_absent(rabbitmq_container):
    """
    Test rabbitmq_policy.present and rabbitmq_policy.absent
    """

    with patch.dict(rabbitmq.__salt__, {"pkg.version": MagicMock(return_value="3.8")}):
        # Clear the policy
        ret = rabbitmq_policy.present(
            name="HA", pattern=".*", definition={"ha-mode": "all"}
        )
        expected = {
            "name": "HA",
            "result": True,
            "comment": (
                'Setting policy "HA" for pattern ".*" to "{"ha-mode": "all"}" with'
                ' priority "0" for vhost "/" ...\n'
            ),
            "changes": {"old": {}, "new": "HA"},
        }
        assert ret == expected

        # Delete the policy
        ret = rabbitmq_policy.absent("HA")
        expected = {
            "name": "HA",
            "result": True,
            "comment": "Deleted",
            "changes": {"new": "", "old": "HA"},
        }

        assert ret == expected
コード例 #4
0
    def test_present(self):
        """
        Test to ensure the RabbitMQ policy exists.
        """
        name = "HA"
        pattern = ".*"
        definition = '{"ha-mode":"all"}'

        ret = {"name": name, "changes": {}, "result": True, "comment": ""}

        mock = MagicMock(side_effect=[
            {
                "/": {
                    name: {
                        "pattern": pattern,
                        "definition": definition,
                        "priority": 0,
                    }
                }
            },
            {},
        ])
        with patch.dict(rabbitmq_policy.__salt__,
                        {"rabbitmq.list_policies": mock}):
            comt = "Policy / HA is already present"
            ret.update({"comment": comt})
            self.assertDictEqual(
                rabbitmq_policy.present(name, pattern, definition), ret)

            with patch.dict(rabbitmq_policy.__opts__, {"test": True}):
                comment = "Policy / HA is set to be created"
                changes = {"new": "HA", "old": {}}
                ret.update({
                    "comment": comment,
                    "result": None,
                    "changes": changes
                })
                self.assertDictEqual(
                    rabbitmq_policy.present(name, pattern, definition), ret)