Пример #1
0
    def test_toggle_offline(self):
        mock_data_io = MagicMock()

        n = Node(mock_data_io)
        n.toggle_offline()

        mock_data_io.post.assert_called_once_with("/toggleOffline")
Пример #2
0
    def test_toggle_offline_with_message_with_spaces(self):
        mock_data_io = MagicMock()

        n = Node(mock_data_io)
        offline_message = "Descriptive text goes here"
        n.toggle_offline(offline_message)

        mock_data_io.post.assert_called_once_with("/toggleOffline?offlineMessage=Descriptive%20text%20goes%20here")
Пример #3
0
    def test_toggle_offline_with_message(self):
        mock_data_io = MagicMock()

        n = Node(mock_data_io)
        offline_message = "Description"
        n.toggle_offline(offline_message)

        mock_data_io.post.assert_called_once_with("/toggleOffline?offlineMessage=" + offline_message)
Пример #4
0
    def test_wait_for_idle_timeout(self):
        mock_data_io = MagicMock()
        mock_data_io.get_api_data.return_value = {"idle": False}

        n = Node(mock_data_io)

        # TODO: Consider launching this method asynchronously
        # somehow to prevent deadlocks if the wait method has bugs in it
        start_time = time.time()
        final_is_idle_value = n.wait_for_idle(3.1)
        duration_in_seconds = time.time() - start_time

        self.assertGreaterEqual(duration_in_seconds, 3, "wait method should have taken at least 3 seconds to complete")
        self.assertFalse(final_is_idle_value)
Пример #5
0
    def find_node(self, nodename):
        """Locates a Jenkins build agent with the given name

        :param str nodename: name of node to locate
        :returns:
            reference to Jenkins object that manages this node's information.
        :rtype: :class:`~.node.Node` or None if node not found
        """
        if nodename == "master":
            temp_nodename = "(master)"
        else:
            temp_nodename = nodename

        # TODO: Rework 'nodes' property to cache the node name for all nodes in
        #       one query, so we can rework this implementation to simply call
        #       self.nodes then iterate through them all to find the one
        #       we're looking for. Then we don't have to guess the URL.

        new_url = self._api.url + "computer/" + temp_nodename
        try:
            retval = Node(self._api.clone(new_url))
            assert retval.name == nodename
            return retval
        except RequestException:
            return None
Пример #6
0
    def test_wait_for_idle(self):
        mock_data_io = MagicMock()

        def mock_get_api_data():
            if not hasattr(mock_get_api_data, "is_called"):
                mock_get_api_data.is_called = True
                return {"idle": False}

            return {"idle": True}

        mock_data_io.get_api_data.side_effect = mock_get_api_data

        n = Node(mock_data_io)
        final_is_idle_value = n.wait_for_idle()

        self.assertTrue(final_is_idle_value)
        self.assertGreaterEqual(
            mock_data_io.get_api_data.call_count, 2, "Mock dataio object should have been called at least twice."
        )
Пример #7
0
    def nodes(self):
        """gets the list of nodes (aka: agents) managed by this Jenkins master

        :returns: list of 0 or more Node objects managed by this Jenkins master
        :rtype: :class:`list` of :class:`~.node.Node` objects
        """
        data = self._api.get_api_data(target_url=self._api.url + "computer/")
        nodes = data['computer']
        retval = []
        for cur_node in nodes:
            if cur_node['displayName'] == 'master':
                node_url = self._api.url + 'computer/(master)'
            else:
                node_url = self._api.url + 'computer/' + cur_node['displayName']

            retval.append(Node(self._api.clone(node_url)))

        return retval