示例#1
0
    def test_change_agent_id_with_inactive_node(self):
        """Tests the NodeManager where a registered node changes its agent ID, and the node is inactive"""

        manager = NodeManager()
        manager.register_agents([self.agent_1, self.agent_2])
        manager.sync_with_database(scheduler_mgr.config)

        # Node 2 is now inactive
        Node.objects.filter(
            id=manager.get_node(self.agent_2.agent_id).id).update(
                is_active=False)
        manager.sync_with_database(scheduler_mgr.config)

        manager.lost_node(self.agent_2.agent_id)
        manager.register_agents([self.agent_3])
        manager.sync_with_database(scheduler_mgr.config)

        # Make sure two nodes are registered, one for agent 1 and one for agent 3, and both are online
        nodes = manager.get_nodes()
        self.assertEqual(len(nodes), 2)
        node_1 = manager.get_node(self.agent_1.agent_id)
        self.assertEqual(node_1.hostname, self.node_1.hostname)
        self.assertTrue(node_1._is_online)
        self.assertIsNone(manager.get_node(self.agent_2.agent_id))
        node_2 = manager.get_node(self.agent_3.agent_id)
        self.assertEqual(node_2.hostname, 'host_2')
        self.assertTrue(node_2._is_online)
        self.assertFalse(node_2._is_active)
示例#2
0
    def test_lost_known_node(self):
        """Tests the NodeManager where a known node was lost"""

        manager = NodeManager()
        manager.register_agents([self.agent_1, self.agent_2])
        manager.sync_with_database(scheduler_mgr.config)
        manager.lost_node(self.agent_2.agent_id)

        nodes = manager.get_nodes()
        self.assertEqual(len(nodes), 2)
        node_1 = manager.get_node(self.agent_1.agent_id)
        self.assertTrue(node_1._is_online)
        node_2 = manager.get_node(self.agent_2.agent_id)
        self.assertFalse(node_2._is_online)
示例#3
0
    def test_lost_unknown_node(self):
        """Tests the NodeManager where an unknown node was lost"""

        manager = NodeManager()
        manager.register_agents([self.agent_1, self.agent_2])
        manager.lost_node(self.agent_2.agent_id)
        manager.sync_with_database(scheduler_mgr.config)

        # Unknown node 2 was lost before syncing with database, it should not appear in the manager
        nodes = manager.get_nodes()
        self.assertEqual(len(nodes), 1)
        node_1 = manager.get_node(self.agent_1.agent_id)
        self.assertEqual(node_1.hostname, self.node_1.hostname)
        self.assertTrue(node_1._is_online)
        self.assertIsNone(manager.get_node(self.agent_2.agent_id))
示例#4
0
    def test_no_job_exe_no_offers(self):
        """Tests the NodeManager where a node is not running an exe and has not given offers to Scale in 1 hour.
           Expected behavior: The node is deleted and the DB model is update with is_active=False"""

        last_offer = now() - datetime.timedelta(hours=1)
        node_mgr = NodeManager()
        node_mgr.register_agents([self.agent_1])
        node_mgr.sync_with_database(scheduler_mgr.config)

        # Set last_offer_received to 1 hour ago
        Node.objects.filter(id=self.node_1.id).update(last_offer_received=last_offer)

        # This inspects what nodes are running jobs and what nodes need to be removed if they
        # have not sent offers in the last 5 minutes
        node_mgr.sync_with_database(scheduler_mgr.config)

        # Get the DB state
        db_record = Node.objects.get(id=self.node_1.id)
        
        self.assertIsNone(node_mgr.get_node(self.agent_1.agent_id))
        self.assertEqual(db_record.is_active, False)