def __init__(self, suiteDef):
     Stateful.__init__(self)
     # name of test suite
     self.name = suiteDef.name
     # test suite definition copy
     self.suite = copy(suiteDef)
     self.suite.jobFun = None
     # date of initialization
     self.initDate = datetime.datetime.now()
     # references to slaves who are necessary for the test suite
     self.slaves = []
     # keeps the results of each stage.
     self.stagesResults = []
     # unique identifier of test suite
     self.uid = self.suite.name + "-" + self.initDate.isoformat()
     # remove special chars from uid
     self.uid = self.uid.translate(maketrans("", ""), "-:.")
     # test cases loaded to run in this session, key is testCase.uid
     self.cases = {}
     # uid of last run test case with given name
     self.caseUidByName = {}
     # if result of any stage i.a. init, test case stages or finalize
     # ended with non-zero status code
     self.failed = False
     self.failed_cases = []
     # This will be set if the session times out.
     self.timeout = False
     # Register an email notifier for this session.
     self.notifier = EmailNotifier(self.suite.alert_emails, self.suite.alert_success, self.suite.alert_failure)
if delayStartup:
	delay = random.randint(60,690) #delay between 1 minute and 16 minutes
	print 'Delaying program: ' + str(delay/60) + '  minutes'
	time.sleep(delay)





browser = webdriver.Firefox()

nav = Navigator(browser)
parser = WebParser(browser)
manager = CourseManager(browser,nav, parser)
schedParser = ScheduleParser()
notify = EmailNotifier(sender,sender_pass)



#if True:
try:
	#parse schedule file
	schedParser.parseFile('Spring2015.scd')

	courseList = schedParser.getCourseList()
	schedules = schedParser.getSchedules()


	#Login to access plus
	nav.bypassLogin('student_id','student_pass', '0001soQW4_NsnMLgyDhE4-RQDsP:14a0b94d8')
	nav.gotoClassRegistration('ran_num')
Exemple #3
0
from StandartNotifier import StandartNotifier
from EmailNotifier import EmailNotifier
notifier = StandartNotifier()
notifier2 = EmailNotifier()

notifier.send("Hello this is not so important")

notifier.setNextNotifier(notifier2)

notifier.send("Hello this is slightely important")
#!/usr/bin/python3

import logging
import logging.config
import configparser

from EC2VolumeSnapshotter import EC2VolumeSnapshotter
from EmailNotifier import EmailNotifier

logger = logging.getLogger(__name__)
logging.config.fileConfig('logging.ini', disable_existing_loggers=False)
eNotify = EmailNotifier()

config = configparser.ConfigParser()
config.read('config.ini')


region = 'eu-west-1'
ec2vs = EC2VolumeSnapshotter()


try:
	for key in config.sections():
		logger.info('Snapshotting ' + key)
		logger.info('Maintaining ' + config[key]['ssmin'] + ' snapshots')

		ec2vs.runSnapshotter(
			config[key]['vol_name'],
			int(config[key]['ssmin']),
			config[key]['region'])
	pass
class TestSuiteSession(Stateful):
    """
    Represents run of Test Suite from the moment of its initialization.
    It stores all information required for test suite to be run as well as
    results of test stages. It has unique id (uid parameter) for recognition,
    because there will be for sure many test suites with the same name.
    """

    def __init__(self, suiteDef):
        Stateful.__init__(self)
        # name of test suite
        self.name = suiteDef.name
        # test suite definition copy
        self.suite = copy(suiteDef)
        self.suite.jobFun = None
        # date of initialization
        self.initDate = datetime.datetime.now()
        # references to slaves who are necessary for the test suite
        self.slaves = []
        # keeps the results of each stage.
        self.stagesResults = []
        # unique identifier of test suite
        self.uid = self.suite.name + "-" + self.initDate.isoformat()
        # remove special chars from uid
        self.uid = self.uid.translate(maketrans("", ""), "-:.")
        # test cases loaded to run in this session, key is testCase.uid
        self.cases = {}
        # uid of last run test case with given name
        self.caseUidByName = {}
        # if result of any stage i.a. init, test case stages or finalize
        # ended with non-zero status code
        self.failed = False
        self.failed_cases = []
        # This will be set if the session times out.
        self.timeout = False
        # Register an email notifier for this session.
        self.notifier = EmailNotifier(self.suite.alert_emails, self.suite.alert_success, self.suite.alert_failure)

    def addCaseRun(self, tc):
        """
        Registers run of test case. Gives unique id (uid) for started
        test case, because one test case can be run many time within test
        suite session.
        @param tc: TestCase definition object
        """
        tc.uid = tc.name + "-" + datetime.datetime.now().isoformat()
        tc.uid = tc.uid.translate(maketrans("", ""), "-:.")  # remove special
        # chars from uid
        tc.initDate = datetime.datetime.now()

        self.cases[tc.uid] = tc
        self.caseUidByName[tc.name] = tc.uid

    def addStageResult(self, state, result, uid=None, slave_name=None):
        """
        Adds all information about stage that has finished to test suite session
        object. Stage are e.g.: initialize suite on some slave, run test case
        on some slave etc.
        @param state: state that happened
        @param result: result of test run (code, stdout, stderr, custom logs, core dump info)
        @param uid: uid of test case or test suite init/finalize
        @param slave_name: where stage ended
        """
        state.time = state.datetime.strftime("%H:%M:%S, %d-%m-%Y")

        LOGGER.info("New stage result %s (ret code %s)" % (state, result[2]))
        LOGGER.debug("New stage result %s: (code %s) %s" % (state, result[2], result[0]))

        if result[2] != "0":
            self.failed = True

            if uid not in ("suite_inited", "suite_finalized"):
                for tc in self.cases.itervalues():
                    if tc.uid == uid:
                        tc.failed = True

        if result[1] == None:
            result = (result[0], "", result[2], result[3], result[4])

        self.stagesResults.append((state, result, uid, slave_name))

    def getTestCaseStages(self, test_case_uid):
        """
        Retrieve test case stages for given test case unique id.
        @param test_case_uid:
        """
        stages = [v for v in self.stagesResults if v[2] == test_case_uid]
        return stages

    def sendEmailAlert(self, failure, state, result=None, slave_name=None, test_case=None, timeout=False):
        args = {
            "testsuite": self.name,
            "failure": failure,
            "failed_cases": self.failed_cases if self.failed_cases else "",
            "state": state,
            "time": state.time,
            "slave": slave_name if slave_name else "",
            "testcase": test_case.name if test_case else "",
            "result": result if result else "",
        }

        type = None

        if int(failure):
            if state == TestSuite.S_INIT_ERROR:
                desc = "Error during suite initialization"
                type = EmailNotifier.SUITE_EVENT

            elif state == TestSuite.S_ALL_FINALIZED:
                desc = "Test suite failed"
                type = EmailNotifier.SUITE_EVENT

            elif state == TestSuite.S_SLAVE_TEST_INITIALIZED:
                desc = "Error initializing test case"
                type = EmailNotifier.CASE_EVENT

            elif state == TestSuite.S_SLAVE_TEST_RUN_FINISHED:
                desc = "Error running test case"
                type = EmailNotifier.CASE_EVENT

            elif state == TestSuite.S_SLAVE_TEST_FINALIZED:
                desc = "Error finalizing test case"
                type = EmailNotifier.CASE_EVENT
            #
            #            elif state == TestSuite.S_ALL_TEST_INITIALIZED:
            #                desc = 'Error initializing test cases'
            #                type = EmailNotifier.CASE_EVENT
            #
            #            elif state == TestSuite.S_ALL_TEST_RUN_FINISHED:
            #                desc = 'Error running test cases'
            #                type = EmailNotifier.CASE_EVENT
            #
            #            elif state == TestSuite.S_ALL_TEST_FINALIZED:
            #                desc = 'Error finalizing test cases'
            #                type = EmailNotifier.CASE_EVENT

            elif timeout:
                desc = "Test suite timed out"
                type = EmailNotifier.TIMEOUT_EVENT

            if test_case is not None and test_case not in self.failed_cases:
                self.failed_cases.append(test_case)

            if type is not None:
                self.notifier.notify_failure(args, desc, type)

        else:
            if state == TestSuite.S_ALL_FINALIZED:
                desc = "Test suite ran successfully on all slaves"
                type = EmailNotifier.SUITE_EVENT
            elif state == TestSuite.S_ALL_TEST_FINALIZED:
                desc = "Test case ran successfully on all slaves"
                type = EmailNotifier.CASE_EVENT

            if type is not None:
                self.notifier.notify_success(args, desc, type)