Пример #1
0
def send_mail(title, data, receiver_group):
    ms = sender.MailSender()
    ms.send_mail(unquote_plus(title), unquote_plus(data), receiver_group)
    print 'a mail has been sent to ' + receiver_group
    timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
    record = timestamp + '\r\n' + title + '\r\n' + receiver_group + '\r\n' + data + '\r\n----------------------------------------------------------\r\n'
    with open("{path}mail_record/{name}.txt".format(path=self_path, name=timestamp.replace(":", "-")), 'w') as f:
        f.write(record)
Пример #2
0
    def test_load_code(self):
        threadID = 2  # LOGGER IS NUMBER 1 !!!
        queueSize = 500
        poll_period = 5
        numThreads = 8
        worker_t = []

        job_queue = queue.Queue(queueSize)
        sender_queue = queue.Queue(queueSize)
        gen_queue = queue.Queue(queueSize)
        arch_queue = queue.Queue(queueSize)

        self.email_queue = queue.Queue(20000) # used by the mock-up sender function instead of smtp

        self.clean_whitelist()
        self.clean_users()
        self.clean_usertasks()
        self.clean_statcounters()
        self.clean_taskstats()
        self.clean_generalconfig()
        self.clean_specialmsg()
        self.clean_taskconfig()

        curc, conc = c.connect_to_db(self.coursedb, self.logger_queue, "loadtester")

        this_time_yesterday = str(datetime.datetime.now() - datetime.timedelta(1)).split('.')[0]
        this_time_tomorrow = str(datetime.datetime.now() + datetime.timedelta(1)).split('.')[0]

        self.add_task(curc, conc, 1, this_time_yesterday, this_time_tomorrow, \
                      'tasks/implementation/VHDL/gates', 'generator.sh', \
                      'tester.sh', '5', '[email protected]', '1')
        self.add_task(curc, conc, 2, this_time_yesterday, this_time_tomorrow, \
                      'tasks/implementation/VHDL/fsm', 'generator.sh', \
                      'tester.sh', '5', '[email protected]', '1')

        conc.close()

        for i in range(1, self.numusers+1):
            self.insert_email_to_whitelist("testuser{0}@sometestdomain.abc".format(str(i)))
     
        with mock.patch.multiple('fetcher.mailFetcher',
                                 connect_to_imapserver=self.mock_connect_to_imapserver,
                                 fetch_new_emails=self.mock_fetch_new_emails,
                                 fetch_all_emails=self.mock_fetch_all_emails):
            with mock.patch.multiple("imaplib.IMAP4",
                                     fetch=self.mock_fetch,
                                     close=self.mock_close):
                with mock.patch("sender.MailSender.send_out_email", self.mock_send_out_email):

                    while threadID <= numThreads + 1:
                        tName = "Worker" + str(threadID-1)
                        t = worker.Worker(tName, job_queue, gen_queue, \
                                          sender_queue, self.logger_queue, \
                                          self.coursedb, self.semesterdb)
                        t.daemon = True
                        t.start()
                        worker_t.append(t)
                        threadID += 1

                    sender_t = sender.MailSender("sender", \
                                                 sender_queue, \
                                                 "[email protected]", \
                                                 "autosub_user", \
                                                 "autosub_passwd", \
                                                 "smtpserver", \
                                                 self.logger_queue, \
                                                 arch_queue, \
                                                 self.coursedb, \
                                                 self.semesterdb)
                    sender_t.daemon = True 
                    sender_t.start()
                    threadID += 1

                    fetcher_t = fetcher.mailFetcher(threadID, "fetcher", \
                                                    job_queue, sender_queue, \
                                                    gen_queue, "autosub_user", \
                                                    "autosub_passwd", \
                                                    "imapserver", \
                                                    self.logger_queue, \
                                                    arch_queue, poll_period, \
                                                    self.coursedb, \
                                                    self.semesterdb)
                    fetcher_t.daemon = True
                    fetcher_t.start()
                    threadID += 1

                    generator_t = generator.taskGenerator(threadID, \
                                                          "generator", \
                                                          gen_queue, \
                                                          sender_queue, \
                                                          self.logger_queue, \
                                                          self.coursedb, \
                                                          self.semesterdb, \
                                                          "*****@*****.**")
                    generator_t.daemon = True
                    generator_t.start()
                    threadID += 1

                    t1 = datetime.datetime.now()
                    # There first test case is set above in the setup routine: self.testcase = "b'10'"
                    NrEntries = 0
                    while NrEntries < self.numusers:
                        curs, cons = c.connect_to_db(self.semesterdb, \
                                                     self.logger_queue, "testcode")
                        sqlcmd = "SELECT count(*) FROM UserTasks;"
                        curs.execute(sqlcmd)
                        NrEntries = int(curs.fetchone()[0])
                        cons.close()
                        #print(NrEntries)

                    t2 = datetime.datetime.now()

                    tc = "b'84'"
                    config = CP.ConfigParser()
                    config.readfp(open('tests/loadtest_testcases.cfg'))
                    testparam = eval(str(config.get(tc, 'generatorstring')))

                    curs, cons = c.connect_to_db(self.semesterdb, \
                                                 self.logger_queue, "testcode")
                    sqlcmd = ("UPDATE UserTasks SET "
                              "TaskParameters = '162159553761823' "
                              "WHERE TaskNr==1;").format(testparam)
                    curs.execute(sqlcmd)
                    cons.commit()
                    cons.close()

                    self.testcase = tc

                    while NrEntries < self.numusers:
                        curs, cons = c.connect_to_db(self.semesterdb, self.logger_queue, "testcode")
                        sqlcmd = "SELECT count(*) FROM UserTasks;"
                        curs.execute(sqlcmd)
                        NrEntries = int(curs.fetchone()[0])
                        cons.close() 

                    t3 = datetime.datetime.now()
                    delta1 = t2 - t1
                    delta2 = t3 - t2
                    print ("Duration of Registration Test: {0} s {1} us".format(delta1.seconds, delta1.microseconds))
                    print ("Duration of Result Test: {0} s {1} us".format(delta2.seconds, delta2.microseconds))
Пример #3
0
def start_threads():
    """
    Create and start all threads of the autosub system
    """

    global threads

    dbs = {"semester": semesterdb, "course": coursedb}

    ######################
    #       SENDER       #
    ######################
    queues = {"sender": sender_queue, \
              "logger": logger_queue, \
              "archive": archive_queue}

    smtp_info = {"mail": smtpmail, \
                 "server": smtpserver, \
                 "user": smtpuser, \
                 "passwd": smtppasswd, \
                 "port" :smtpport, \
                 "security": smtpsecurity}

    course_info = {
        "name": course_name,
        "mail": imapmail,
        "tasks_dir": tasks_dir
    }

    sender_t = sender.MailSender("sender", queues, dbs, smtp_info, course_info, \
                                 allow_requests)

    # make the sender thread a daemon, this way the main will clean it up before
    # terminating!
    sender_t.daemon = True
    sender_t.start()
    threads.append(sender_t)

    ######################
    #      FETCHER       #
    ######################
    queues = {"sender": sender_queue, \
              "logger": logger_queue, \
              "archive": archive_queue, \
              "generator": generator_queue, \
              "job": job_queue}

    imap_info = {"mail": imapmail, \
                 "server": imapserver, \
                 "user": imapuser, \
                 "passwd": imappasswd, \
                 "port" :imapport, \
                 "security": imapsecurity}

    fetcher_t = fetcher.MailFetcher("fetcher", queues, dbs, imap_info, \
                                    poll_period, allow_requests)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    fetcher_t.daemon = True
    fetcher_t.start()
    threads.append(fetcher_t)

    ######################
    #     GENERATOR      #
    ######################
    queues = {"sender": sender_queue, \
              "logger": logger_queue, \
              "generator": generator_queue}

    submission_mail = imapmail

    generator_t = generator.TaskGenerator("generator", queues, dbs, \
                                          submission_mail, \
                                          tasks_dir, course_mode, allow_requests)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    generator_t.daemon = True
    generator_t.start()
    threads.append(generator_t)

    ######################
    #      ACTIVATOR     #
    ######################
    queues = {"sender": sender_queue, \
              "logger": logger_queue, \
              "generator": generator_queue}

    activator_t = activator.TaskActivator("activator", queues, dbs, \
                                          auto_advance, allow_requests)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    activator_t.daemon = True
    activator_t.start()
    threads.append(activator_t)

    ######################
    #       WORKERS      #
    ######################
    queues = {"sender": sender_queue, \
              "logger": logger_queue, \
              "generator": generator_queue, \
              "job": job_queue}

    for thread_id in range(1, num_workers + 1):
        t_name = "Worker" + str(thread_id)
        worker_t = worker.Worker(t_name, queues, dbs, tasks_dir,
                                 allow_requests)
        worker_t.daemon = True
        worker_t.start()
        threads.append(worker_t)

    ######################
    #     DAILYSTATS    #
    ######################
    dailystats_t = dailystats.DailystatsTask("dailystats", logger_queue, \
                                             semesterdb)
    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    dailystats_t.daemon = True
    dailystats_t.start()
    threads.append(dailystats_t)

    c.log_a_msg(logger_queue, "Main", "All threads started successfully",
                "INFO")
Пример #4
0
    logger_t.start()
    thread_id += 1

    signal.signal(signal.SIGUSR1, sig_handler)

    ####################
    # Init Ressources  #
    ####################
    init_ressources(semesterdb, coursedb, num_tasks, smtpmail, challenge_mode, \
                    course_name, specialpath, allow_skipping)

    ####################
    ## Start Threads  ##
    ####################
    sender_t = sender.MailSender("sender", sender_queue, smtpmail, \
                                 smtpuser, smtppasswd, smtpserver, smtpport, smtpsecurity, \
                                 logger_queue, arch_queue, coursedb, semesterdb)

    # make the sender thread a daemon, this way the main will clean it up before
    # terminating!
    sender_t.daemon = True
    sender_t.start()
    thread_id += 1

    fetcher_t = fetcher.mailFetcher(thread_id, "fetcher", job_queue, sender_queue, gen_queue, \
                                    imapuser, imappasswd, imapserver, imapport, imapsecurity, \
                                    logger_queue, arch_queue, poll_period, coursedb, \
                                    semesterdb, allow_skipping)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!