def test_parse_multi_state_down(self):

        pattern_args = {'host' : 'cert-wn64-01', 'state' : 'offline,down', 'np' : '2'}
        tmpfile = self.workspace.createFile(self.pbsnodesPattern % pattern_args)
        
        pattern_args = {'host' : 'cert-wn64-02', 'state' : 'free', 'np' : '2'}
        self.workspace.appendToFile(self.pbsnodesPattern % pattern_args, tmpfile)

        container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
        self.assertTrue(container.totalCPU == 2 and container.freeCPU == 2)
    def test_parse_half_busy(self):

        pattern_args = {'host': 'cert-wn64-01', 'state': 'busy', 'np': '2'}
        tmpfile = self.workspace.createFile(self.pbsnodesPattern %
                                            pattern_args)

        pattern_args = {'host': 'cert-wn64-02', 'state': 'free', 'np': '2'}
        self.workspace.appendToFile(self.pbsnodesPattern % pattern_args,
                                    tmpfile)

        container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
        self.assertTrue(container.totalCPU == 4 and container.freeCPU == 2)
    def test_parse_all_free_with_job(self):

        pattern_args = {'host' : 'cert-wn64-01', 'state' : 'free', 'np' : '2'}
        tmpfile = self.workspace.createFile(self.pbsnodesPattern % pattern_args)
        
        pattern_args = {'host' : 'cert-wn64-02', 'state' : 'free', 'np' : '4'}
        tmps = self.pbsnodesPattern % pattern_args
        tmps += '     jobs = 0/15.cert-34.pd.infn.it, 1/16.cert-34.pd.infn.it\n'
        self.workspace.appendToFile(tmps, tmpfile)
        
        container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
        self.assertTrue(container.totalCPU == 6 and container.freeCPU == 4)
    def test_parse_all_free_with_job(self):

        pattern_args = {'host': 'cert-wn64-01', 'state': 'free', 'np': '2'}
        tmpfile = self.workspace.createFile(self.pbsnodesPattern %
                                            pattern_args)

        pattern_args = {'host': 'cert-wn64-02', 'state': 'free', 'np': '4'}
        tmps = self.pbsnodesPattern % pattern_args
        tmps += '     jobs = 0/15.cert-34.pd.infn.it, 1/16.cert-34.pd.infn.it\n'
        self.workspace.appendToFile(tmps, tmpfile)

        container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
        self.assertTrue(container.totalCPU == 6 and container.freeCPU == 4)
    def test_parse_wrong_cpunum(self):
        
        try:
            pattern_args = {'host' : 'cert-wn64-01', 'state' : 'free', 'np' : '2a'}
            tmpfile = self.workspace.createFile(self.pbsnodesPattern % pattern_args)
        
            pattern_args = {'host' : 'cert-wn64-02', 'state' : 'free', 'np' : '2'}
            self.workspace.appendToFile(self.pbsnodesPattern % pattern_args, tmpfile)

            container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
            self.fail("No exception detected")
        except Exception, ex:
            msg = str(ex)
            self.assertTrue(msg.startswith("invalid literal for int"))
    def test_parse_wrong_cpunum(self):

        try:
            pattern_args = {
                'host': 'cert-wn64-01',
                'state': 'free',
                'np': '2a'
            }
            tmpfile = self.workspace.createFile(self.pbsnodesPattern %
                                                pattern_args)

            pattern_args = {'host': 'cert-wn64-02', 'state': 'free', 'np': '2'}
            self.workspace.appendToFile(self.pbsnodesPattern % pattern_args,
                                        tmpfile)

            container = PBSNodesHandler.parseCPUInfo(None, tmpfile)
            self.fail("No exception detected")
        except Exception, ex:
            msg = str(ex)
            self.assertTrue(msg.startswith("invalid literal for int"))