Exemple #1
0
    def _compile(self):
        cwd = os.getcwd()
        os.chdir(self.path)

        script_cmds = self.data.msg.split('\n')
        for cmd in script_cmds:
            r = [0, 0, 0]
            r[0] = os.system('echo " +++ TESTHARD +++ Running %s:" >> output.tmp' % cmd)
            r[1] = os.system('%s >> output.tmp 2>> output.tmp' % cmd)
            r[2] = os.system('echo " +++ TESTHARD +++ Last command result: %d" >> output.tmp' % r[1])
            if r != [0, 0, 0]:
                print 'Error while running tests'
                break

        f = open('output.tmp', 'r')
        if not f:
            print 'Nie mozna otworzyc pliku wyjsciowego'
            self.close()
        result = ''.join(f.readlines())

        self.data = pakiet()
        self.data.typ = pakiet.BUILD
        self.data.msg = result
        self.buffer.send(self.data)

        os.system('rm output.tmp')
        os.chdir(cwd)
Exemple #2
0
    def start(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        while 1:
            try:
                self.socket.bind((self.host, self.port))
            except:
                time.sleep(30)
            else:
                break

        self.socket.listen(1)
        self.active = True
        self.ftp = ftpClient.ftpClient(self.socket.getsockname()[0])
        self.conn, self.addr = self.socket.accept()
        self.buffer = bufor(self.conn)
        
        while self.active:
            self.data = self.buffer.read()
            if not self.data:
                print 'Serwer zakonczyl nieoczekiwanie sesje.'
                break
            if self.data.typ == pakiet.PING and self.data.msg == 'ping':
                self.data = pakiet()
                self.data.typ = pakiet.PING
                self.data.msg = 'pong'
                self.buffer.send(self.data)
            elif self.data.typ == pakiet.FTPDOWNLOAD:
                if not self.ftp.download((self.data.msg, self.data.port), self.path):
                    return
                self.data = pakiet()
                self.data.typ = pakiet.FTPDOWNLOAD
                self.data.msg = 'ok'
                self.buffer.send(self.data)
            elif self.data.typ == pakiet.RUNTESTS:
                self._run_test()
            elif self.data.typ == pakiet.BUILD:
                self._compile()
            elif self.data.typ == pakiet.EXIT:
                self.active = False

        self.close()
Exemple #3
0
    def _test(self, job_file, test_cmd):
        self.data = pakiet()
        self.data.typ = pakiet.RUNTESTS
        self.data.msg = test_cmd
        self.buffer.send(self.data)

        self.data = self.buffer.read()
        if self.data.typ != pakiet.RUNTESTS:
            print 'Blad w wykonywaniu testow!', self.data.msg
            self.close()
            return
 
        print 'RETURNED', self.data.msg
        results = AntJUnitParser(self.data.msg, job_file)
        return results
Exemple #4
0
    def _run_test(self):
        cwd = os.getcwd()
        os.chdir(self.path)

        cmd = self.data.msg
        print 'Run', cmd

        retcode = os.system('%s >> output.tmp 2>> output.tmp' % cmd)
        f = open('output.tmp', 'r')
        if not f:
            print 'Nie mozna otworzyc pliku wyjsciowego'
            self.close()
        result = ''.join(f.readlines())

        self.data = pakiet()
        self.data.typ = pakiet.RUNTESTS
        self.data.msg = result
        self.buffer.send(self.data)
        
        os.system('rm output.tmp')
        os.chdir(cwd)
Exemple #5
0
    def run(self):
        #Send ping
        self.data = pakiet()
        self.data.typ = pakiet.PING
        self.data.msg = 'ping'
        self.buffer.send(self.data)

        #Recv ping
        self.data = self.buffer.read()
        if self.data.typ != pakiet.PING or self.data.msg != 'pong':
            #wyslij error
            print 'Bledna odpowiedz na ping!'
            self.close()
            return
        
        #pobieranie aplikacji testowanej przez workera
        self.data = pakiet()
        self.data.typ = pakiet.FTPDOWNLOAD
        self.data.port = 2222   # TODO: poprawic!
        self.data.msg = self.socket.getsockname()[0]
        self.buffer.send(self.data)

        self.data = self.buffer.read()
        if self.data.typ != pakiet.FTPDOWNLOAD or self.data.msg != 'ok':
            print 'Worker nie pobral FTP ', self.data.msg
            self.close()
            return
        
        self.ftpDownloaded = True
        log('Worker '+self.ip[:-1]+' pobral FTP')

        self.data = pakiet()
        self.data.typ = pakiet.BUILD
        self.data.msg = 'ant compile'
        self.buffer.send(self.data)

        self.data = self.buffer.read()
        if not self.data or self.data.typ != pakiet.BUILD:
            log('Blad podczas budowania')
            #self.close()
            #return
    
        rep = RepoManager()

        while True:
            self.server.workersLock.acquire()
            if len(self.server.jobs) > 0:
                job_file = self.server.jobs[0]
                job = self.server.run_test_cmd.replace('$$', job_file)
                self.server.jobs = self.server.jobs[1:]
            else:
                self.server.workersLock.release()
                self.server.serverCond.acquire()
                self.server.serverCond.notify()
                self.server.serverCond.release()
                break
            self.server.workersLock.release()

            try:
                results = self._test(job_file, job)
            except ValueError:
                print 'Blad podczas parsowania wyjscia'
                continue

            rep = RepoManager()
            rep.addResult(self.server.taskName, results)
            print 'WYNIKI TESTOW'
            print 'ILE: %d FAILURES: %d, ERRORS: %d LOG:' % (results.tests_count, results.failures, results.errors)
            print '/-------------\\'
            print results.log
            print '\\-------------/'


        #koniec pracy
        self.data = pakiet()
        self.data.typ = pakiet.EXIT
        self.buffer.send(self.data)
        
        self.close()