Exemplo n.º 1
0
    def test_node_cpu_relation(self):
        """
        Unit test that verifies that the correct relation between
        the testbed class and the node class is built
        """

        # We create a node
        node = Node()
        node.name = "node1"
        node.information_retrieved = True

        # We add several CPUs to it
        node.cpus = [
            CPU("Intel", "Xeon", "x86_64", "e6333", "2600Mhz", True, 2, "cache", "111"),
            CPU("AMD", "Zen", "x86_64", "xxxxx", "2600Mhz", True, 2, "cache", "111")
        ]

        # We save everything to the db
        db.session.add(node)
        db.session.commit()

        # We retrived and verify that the cpus are there
        node = db.session.query(Node).filter_by(name='node1').first()

        self.assertEquals(2, len(node.cpus))
        self.assertEquals("Intel", node.cpus[0].vendor_id)
        self.assertEquals("AMD", node.cpus[1].vendor_id)

        # Lets delete a cpu directly from the session
        db.session.delete(node.cpus[1])
        db.session.commit()
        node = db.session.query(Node).filter_by(name='node1').first()
        self.assertEquals(1, len(node.cpus))
        self.assertEquals("Intel", node.cpus[0].vendor_id)
Exemplo n.º 2
0
    def test_update_cpu_node_information(self, mock_parser):
        """
        Test that the correct work of this function
        """
        l = LogCapture()  # we cature the logger

        # We store some data in the db for the test.
        testbed, node_1, node_2 = self._create_initial_db_data()

        node_3 = Node()
        node_3.name = "node_3"
        node_3.information_retrieved = True
        testbed.nodes.append(node_3)

        node_3.cpus = [
            CPU("Intel", "Xeon", "x86_64", "e6333", "2600Mhz", True, 2,
                "cache", "111")
        ]

        # So, testbed has 3 nodes, one disabled and the other ones enabled
        db.session.commit()

        cpus_result = [
            CPU("Intel2", "Xeon2", "x86_64", "e6333", "2600Mhz", True, 2,
                "cache", "111"),
            CPU("Intel3", "Xeon3", "x86_64", "e6333", "2600Mhz", True, 2,
                "cache", "111")
        ]

        mock_parser.return_value = cpus_result

        slurm.update_cpu_node_information()

        # We verify the results
        self.assertEquals(
            0, len(db.session.query(CPU).filter_by(vendor_id="Intel").all()))
        self.assertEquals(
            1, len(db.session.query(CPU).filter_by(vendor_id="Intel2").all()))
        self.assertEquals(
            1, len(db.session.query(CPU).filter_by(vendor_id="Intel3").all()))

        calls = [mock.call(testbed, node_2), mock.call(testbed, node_3)]
        mock_parser.assert_has_calls(calls)
        self.assertEquals(2, mock_parser.call_count)

        # In case an error occours retrieving the information
        mock_parser.return_value = []

        slurm.update_cpu_node_information()

        calls = [mock.call(testbed, node_2), mock.call(testbed, node_3)]
        mock_parser.assert_has_calls(calls)
        self.assertEquals(4, mock_parser.call_count)

        # Checking that we are logging the correct messages
        l.check(('root', 'INFO', 'Updating CPU info for node: node_2'),
                ('root', 'INFO', 'Updating CPU info for node: node_3'),
                ('root', 'ERROR',
                 'Impossible to update CPU info for node: node_2'),
                ('root', 'ERROR',
                 'Impossible to update CPU info for node: node_3'))
        l.uninstall()  # We uninstall the capture of the logger