Example #1
0
    def _create_initial_db_data(self):
        """
        This method creates some initial data in the db that is employed by
        some of the tests here.
        """

        # We add two testbeds to the db
        testbed = Testbed("name1", True, Testbed.slurm_category, "ssh",
                          "user@server", ['slurm'])

        # We add some nodes to Testbed_1
        node_1 = Node()
        node_1.name = "node_1"
        node_1.information_retrieved = True
        node_2 = Node()
        node_2.name = "node_2"
        node_2.information_retrieved = True
        testbed.nodes = [node_1, node_2]
        node_1.disabled = True

        db.session.add(testbed)
        db.session.commit()

        return testbed, node_1, node_2
Example #2
0
    def test_update_node_information(self, mock_shell):
        """
        Test that the correct work of this function
        """
        l = LogCapture()  # we capture the logger
        command = "pbsnodes"
        params = ["-x"]

        # We store some data in the db for the test.
        # We add a testbed to the db
        testbed = Testbed("name1", True, Testbed.torque_category,
                          Testbed.protocol_ssh, "user@server", ['torque'])

        # We add some nodes to Testbed_1
        node_1 = Node()
        node_1.name = "node-1.novalocal"
        node_1.information_retrieved = True
        node_2 = Node()
        node_2.name = "node-2.novalocal"
        node_2.information_retrieved = True
        testbed.nodes = [node_1, node_2]
        node_1.disabled = True

        db.session.add(testbed)
        db.session.commit()

        # We mock the command call
        mock_shell.return_value = self.command_pbsnodes_output

        testbeds.facade.update_testbed_node_information(testbed)

        # We verify the results
        node_1 = db.session.query(Node).filter_by(
            name='node-1.novalocal').first()
        node_2 = db.session.query(Node).filter_by(
            name='node-2.novalocal').first()
        self.assertEqual('free', node_1.state)
        self.assertEqual(1, len(node_1.memories))
        self.assertEqual(Memory.KILOBYTE, node_1.memories[0].units)
        self.assertEqual(131583196, node_1.memories[0].size)
        self.assertEqual(1, len(node_1.gpus))

        self.assertEqual('free', node_2.state)
        self.assertEqual(1, len(node_2.memories))
        self.assertEqual(Memory.KILOBYTE, node_2.memories[0].units)
        self.assertEqual(131583197, node_2.memories[0].size)
        self.assertEqual(0, len(node_2.gpus))

        mock_shell.assert_called_with(command=command,
                                      server="user@server",
                                      params=params)
        self.assertEqual(1, mock_shell.call_count)

        # Checking that we are logging the correct messages
        l.check(
            ('root', 'INFO',
             'Updating information for node: node-1.novalocal if necessary'),
            ('root', 'INFO',
             'Updating memory information for node: node-1.novalocal'),
            ('root', 'INFO',
             'Updating gpu information for node: node-1.novalocal'),
            ('root', 'INFO',
             'Updating information for node: node-2.novalocal if necessary'),
            ('root', 'INFO',
             'Updating memory information for node: node-2.novalocal'),
        )
        l.uninstall()  # We uninstall the capture of the logger
Example #3
0
    def test_update_node_information(self, mock_shell):
        """
        Test that the correct work of this function
        """
        l = LogCapture()  # we cature the logger
        command = "scontrol"
        params = ["-o", "--all", "show", "node"]

        # We store some data in the db for the test.
        # We add two testbeds to the db
        testbed = Testbed("name1", True, Testbed.slurm_category,
                          Testbed.protocol_ssh, "user@server", ['slurm'])

        # We add some nodes to Testbed_1
        node_1 = Node()
        node_1.name = "nd80"
        node_1.information_retrieved = True
        node_2 = Node()
        node_2.name = "nd23"
        node_2.information_retrieved = True
        testbed.nodes = [node_1, node_2]
        node_1.disabled = True

        db.session.add(testbed)
        db.session.commit()

        # We mock the command call
        mock_shell.return_value = self.command_scontrol_output

        slurm.update_node_information()

        # We verify the results
        node_80 = db.session.query(Node).filter_by(name='nd80').first()
        node_23 = db.session.query(Node).filter_by(name='nd23').first()
        self.assertEquals('ALLOCATED', node_80.state)
        self.assertEquals(1, len(node_80.memories))
        self.assertEquals(Memory.MEGABYTE, node_80.memories[0].units)
        self.assertEquals(6850663, node_80.memories[0].size)
        self.assertEquals(0, len(node_80.gpus))

        self.assertEquals('MAINT', node_23.state)
        self.assertEquals(1, len(node_23.memories))
        self.assertEquals(Memory.MEGABYTE, node_23.memories[0].units)
        self.assertEquals(24018, node_23.memories[0].size)
        self.assertEquals(2, len(node_23.gpus))
        self.assertEquals('Nvidia', node_23.gpus[0].vendor_id)
        self.assertEquals('Nvidia TESLA C2075', node_23.gpus[0].model_name)
        self.assertEquals('Nvidia', node_23.gpus[1].vendor_id)
        self.assertEquals('Nvidia TESLA C2075', node_23.gpus[1].model_name)

        mock_shell.assert_called_with(command=command,
                                      server="user@server",
                                      params=params)
        self.assertEquals(1, mock_shell.call_count)

        # Checking that we are logging the correct messages
        l.check(('root', 'INFO',
                 'Updating information for node: nd80 if necessary'),
                ('root', 'INFO', 'Updating memory information for node: nd80'),
                ('root', 'INFO',
                 'Updating information for node: nd23 if necessary'),
                ('root', 'INFO', 'Updating memory information for node: nd23'),
                ('root', 'INFO', 'Updating gpu information for node: nd23'))
        l.uninstall()  # We uninstall the capture of the logger
Example #4
0
    def test_get_cpuinfo_node(self, mock_shell):
        """
        It verfies that given a testbed it is possible to get the cpuinfo
        information of the node.
        """

        l = LogCapture() # we cature the logger

        # When the testbed is local
        testbed = Testbed("name1",
                            True,
                            Testbed.slurm_category,
                            Testbed.protocol_local,
                            "user@server",
                            ['slurm'])

        node_1 = Node() # We add some nodes to Testbed_1
        node_1.name = "node_1"
        node_1.information_retrieved = True
        node_2 = Node()
        node_2.name = "node_2"
        node_2.information_retrieved = True
        testbed.nodes = [ node_1, node_2]
        node_1.disabled = True
        node_3 = Node()
        node_3.name = "node_3"
        node_3.information_retrieved = True

        # When the node does not belong to the testbed it should return empty list
        cpus = parser.get_cpuinfo_node(testbed, node_3)

        self.assertEquals(0, len(cpus))

        # When the node is there, we have to get double CPU info
        mock_shell.return_value = self.command_output

        cpus = parser.get_cpuinfo_node(testbed, node_2)

        self.assertEquals(8, len(cpus))
        mock_shell.assert_called_with(command="ssh",
                                      params=["node_2", "'cat", "/proc/cpuinfo'"])
        self.assertEqual(mock_shell.call_count, 1)

        # When the node is dissabled it should return an empty list
        cpus = parser.get_cpuinfo_node(testbed, node_1)

        self.assertEquals(0, len(cpus))
        self.assertEqual(mock_shell.call_count, 1)

        # When the testbed is using ssh protocol
        testbed = Testbed("name1",
                            True,
                            Testbed.slurm_category,
                            Testbed.protocol_ssh,
                            "user@server",
                            ['slurm'])
        testbed.nodes = [node_2]

        mock_shell.return_value = self.command_output

        cpus = parser.get_cpuinfo_node(testbed, node_2)

        self.assertEquals(8, len(cpus))
        mock_shell.assert_called_with(command="ssh",
                                      server=testbed.endpoint,
                                      params=["node_2", "'cat", "/proc/cpuinfo'"])
        self.assertEqual(mock_shell.call_count, 2)

        # We simulate what happens if we get an exception executing the command
        error = subprocess.CalledProcessError(returncode=255, cmd="ls")
        mock_shell.side_effect = error

        cpus = parser.get_cpuinfo_node(testbed, node_2)

        self.assertEquals(0, len(cpus))
        self.assertEqual(mock_shell.call_count, 3)

        # When the testbed has an unknown protocol
        testbed = Testbed("name1",
                            True,
                            Testbed.slurm_category,
                            "xxx",
                            "user@server",
                            ['slurm'])
        testbed.nodes = [node_2]

        cpus = parser.get_cpuinfo_node(testbed, node_2)

        self.assertEquals(0, len(cpus))
        self.assertEqual(mock_shell.call_count, 3)

        # We verify that we raised the right errors
        # Checking that we are logging the correct messages
        l.check(
            ('root', 'ERROR', 'Exception trying to get the node cpu info'),
            ('root', 'INFO', 'Tesbed protocol: xxx not supported to get node information')
            )
        l.uninstall() # We uninstall the capture of the logger