Пример #1
0
    def test_state_listener(self, mock_add, mock_get, \
            mock_start, mock_create, mock_get_children):
        """
        test state_listener
        """
        mock_get_children.return_value = ["test#test"]
        mock_start.return_value = None
        mock_get.return_value = "127.0.0.1:666"
        mock_add.return_value = None

        def startfunc():
            """
            mock func
            """
            return "start"

        def stopfunc():
            """
            mock func
            """
            return "stop"

        ham = ha_master.HAMaster(startfunc, stopfunc)
        ham.state_listener(kazoo.client.KazooState.LOST)
        ham.state_listener(kazoo.client.KazooState.SUSPENDED)
        ham.state_listener(kazoo.client.KazooState.CONNECTED)
        ham.state_listener("UNKNOW")
Пример #2
0
    def test_choose_master4(self, mock_add, mock_get, \
            mock_start, mock_create, mock_get_children):
        """
        test choose_master
        """
        mock_get_children.return_value = ["test#test"]
        mock_start.return_value = None
        mock_get.return_value = "127.0.0.1:666"
        mock_add.return_value = None

        def startfunc():
            """
            mock func
            """
            return "start"

        def stopfunc():
            """
            mock func
            """
            return "stop"

        ham = ha_master.HAMaster(startfunc, stopfunc)
        ham.is_leader = True
        ham.choose_master()
Пример #3
0
    def test_init(self, mock_add, mock_get, mock_start):
        """
        test HAMaster init
        """
        mock_start.return_value = None
        mock_get.return_value = "127.0.0.1:666"
        mock_add.return_value = None
        def startfunc():
            """
            mock func
            """
            return "start"

        def stopfunc():
            """
            mock func
            """
            return "stop"

        ham = ha_master.HAMaster(startfunc, stopfunc)
Пример #4
0
    def test_create_instance(self, mock_add, mock_get, mock_start, mock_create):
        """
        test create_instance
        """
        mock_start.return_value = None
        mock_get.return_value = "127.0.0.1:666"
        mock_add.return_value = None

        def startfunc():
            """
            mock func
            """
            return "start"

        def stopfunc():
            """
            mock func
            """
            return "stop"

        ham = ha_master.HAMaster(startfunc, stopfunc)
        ham.create_instance()
Пример #5
0
    def test_event_watcher(self, mock_add, mock_get, \
            mock_start, mock_create, mock_get_children):
        """
        test event_watcher
        """
        mock_get_children.return_value = ["test#test"]
        mock_start.return_value = None
        mock_get.return_value = "127.0.0.1:666"
        mock_add.return_value = None

        def startfunc():
            """
            mock func
            """
            return "start"

        def stopfunc():
            """
            mock func
            """
            return "stop"

        ham = ha_master.HAMaster(startfunc, stopfunc)

        class Event(object):
            """
            mock Event
            """
            def __init__(self, value):
                self.state = value
                self.type  = value

        e = Event("CONNECTED")
        ham.event_watcher(e)

        e = Event("UNKNOW")
        ham.event_watcher(e)