Пример #1
0
    def test_joined(self):
        '''
            Test to ensure the current node joined
            to a cluster with node user@host
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': ''}

        mock = MagicMock(side_effect=[['rahulha@salt'], [''], ['']])
        with patch.dict(rabbitmq_cluster.__salt__,
                        {"rabbitmq.cluster_status": mock}):
            ret.update({'comment': 'Already in cluster'})
            self.assertDictEqual(rabbitmq_cluster.joined('salt', 'salt',
                                                         'rahulha'), ret)

            with patch.dict(rabbitmq_cluster.__opts__, {"test": True}):
                ret.update({'result': None,
                            'comment': 'Node is set to join '
                            'cluster rahulha@salt'})
                self.assertDictEqual(rabbitmq_cluster.joined('salt', 'salt',
                                                             'rahulha'), ret)

            with patch.dict(rabbitmq_cluster.__opts__, {"test": False}):
                mock = MagicMock(return_value={'Error': 'ERR'})
                with patch.dict(rabbitmq_cluster.__salt__,
                                {"rabbitmq.join_cluster": mock}):
                    ret.update({'result': False,
                                'comment': 'ERR'})
                    self.assertDictEqual(rabbitmq_cluster.joined('salt',
                                                                 'salt',
                                                                 'rahulha'),
                                         ret)
Пример #2
0
def test_joined():
    """
    Test to ensure the current node joined
    to a cluster with node user@host
    """
    ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}

    mock = MagicMock(side_effect=[["rahulha@salt"], [""], [""]])
    with patch.dict(rabbitmq_cluster.__salt__, {"rabbitmq.cluster_status": mock}):
        ret.update({"comment": "Already in cluster"})
        assert rabbitmq_cluster.joined("salt", "salt", "rahulha") == ret

        with patch.dict(rabbitmq_cluster.__opts__, {"test": True}):
            ret.update(
                {
                    "result": None,
                    "comment": "Node is set to join cluster rahulha@salt",
                    "changes": {"new": "rahulha@salt", "old": ""},
                }
            )
            assert rabbitmq_cluster.joined("salt", "salt", "rahulha") == ret

        with patch.dict(rabbitmq_cluster.__opts__, {"test": False}):
            mock = MagicMock(return_value={"Error": "ERR"})
            with patch.dict(rabbitmq_cluster.__salt__, {"rabbitmq.join_cluster": mock}):
                ret.update({"result": False, "comment": "ERR", "changes": {}})
                assert rabbitmq_cluster.joined("salt", "salt", "rahulha") == ret
Пример #3
0
def test_joined(rabbitmq_container):
    """
    Test rabbitmq_cluster.joined
    """

    hostname = rabbitmq_container.container.attrs["Config"]["Hostname"]
    ret = rabbitmq_cluster.joined("name", host=hostname)
    expected = {
        "name": "name",
        "result": True,
        "comment": "Already in cluster",
        "changes": {},
    }
    assert ret == expected