示例#1
0
    def setup_servlet(self):
        application = turtle.Turtle()
        application.settings = {
            'static_path':
            os.path.join(os.path.dirname(__file__), "../static"),
            'template_path':
            os.path.join(os.path.dirname(__file__), "../templates"),
            'autoescape':
            None,
        }

        # Properly load ui_modules and ui_methods
        application.ui_modules = {}
        application.ui_methods = {}
        application._load_ui_modules = types.MethodType(
            tornado.web.Application._load_ui_modules.im_func, application)
        application._load_ui_methods = types.MethodType(
            tornado.web.Application._load_ui_methods.im_func, application)
        application._load_ui_modules(ui_modules)
        application._load_ui_methods(ui_methods)

        if self.authenticated:
            application.settings['cookie_secret'] = 'cookie_secret'
        request = turtle.Turtle()
        self.servlet = RequestHandler(application, request)
示例#2
0
    def test_schedule_next_run(self):
        act = action.Action("Test Action")
        jo = job.Job("Test Job", act)
        jo.output_dir = self.test_dir
        jo.node_pool = turtle.Turtle()
        jo.scheduler = scheduler.DailyScheduler()

        act.job = jo
        act.command = "Test command"
        act.node = turtle.Turtle()

        def call_now(time, func, next):
            next.start()
            next.runs[0].succeed()

        callLater = mcp.reactor.callLater
        mcp.reactor.callLater = call_now
        self.mcp.schedule_next_run(jo)
        mcp.reactor.callLater = callLater
        next = jo.runs[0]

        assert_equals(len(filter(lambda r: r.is_success, jo.runs)), 1)
        assert_equals(jo.topo_actions[0], next.runs[0].action)
        assert next.runs[0].is_success
        assert next.is_success
    def start_server(self, test_reporters=None, failure_limit=None):
        if test_reporters is None:
            self.test_reporter = turtle.Turtle()
            test_reporters = [self.test_reporter]

        self.server = test_runner_server.TestRunnerServer(
            self.dummy_test_case,
            options=turtle.Turtle(
                runner_timeout=1,
                server_timeout=10,
                revision=None,
                shutdown_delay_for_connection_close=0.001,
                shutdown_delay_for_outstanding_runners=1,
            ),
            serve_port=0,
            test_reporters=test_reporters,
            plugin_modules=[],
            failure_limit=failure_limit,
        )

        def catch_exceptions_in_thread():
            try:
                self.server.run()
            except (Exception, SystemExit), exc:
                _log.error("Thread threw exception: %r" % exc)
                raise
示例#4
0
 def test_notify_delegate(self):
     delegate = turtle.Turtle()
     handler = turtle.Turtle()
     self.machine = state.StateMachine(self.state_red, delegate=delegate)
     self.machine.attach(True, handler)
     self.machine.transition('true')
     assert_equal(handler.handler.calls,
                  [((delegate, self.state_green), {})])
示例#5
0
 def build_job(self):
     self.test_dir = tempfile.mkdtemp()
     self.action = action.Action(name="Test Action", node_pool=turtle.Turtle())
     self.job = job.Job("Test Job", self.action)
     self.job.node_pool = turtle.Turtle()
     self.job.output_dir = self.test_dir
     self.action.job = self.job
     self.action.command = "Test command"
示例#6
0
    def build_resource(self):
        self.job = turtle.Turtle(
                                 name="foo",
                                 runs=[],
                                 scheduler=None,
                                 node_pool=TEST_POOL,
                                )

        self.resource = www.JobResource(self.job, turtle.Turtle())
示例#7
0
    def setup(self):
        self.test_dir = tempfile.mkdtemp()
        self.action = action.Action(name="Test Action", node_pool=turtle.Turtle())
        self.job = job.Job("Test Job", self.action)
        self.job.node_pool = turtle.Turtle()
        self.job.output_dir = self.test_dir
        self.job.scheduler = scheduler.DailyScheduler()
        self.job.queueing = True
        self.action.job = self.job
        self.action.command = "Test command"

        self.job_run = self.job.next_runs()[0]
        self.run = self.job_run.runs[0]
示例#8
0
    def test_success_but_recent_failure(self):
        job_run = turtle.Turtle()
        job_run.is_success = True
        job_run.end_time = timeutils.current_time() - datetime.timedelta(
            seconds=30)
        self.job.runs.append(job_run)

        bad_job_run = turtle.Turtle()
        bad_job_run.is_success = False
        bad_job_run.end_time = timeutils.current_time()
        self.job.runs.append(bad_job_run)

        assert self.resource.is_ready
示例#9
0
    def test_all_nodes_build_run(self):
        self.job.all_nodes = True
        self.job.node_pool = turtle.Turtle(
            nodes=[turtle.Turtle(),
                   turtle.Turtle(),
                   turtle.Turtle()])
        runs = self.job.build_runs()

        assert_equals(len(runs), 3)

        assert_equals(runs[0].node, self.job.node_pool.nodes[0])
        assert_equals(runs[1].node, self.job.node_pool.nodes[1])
        assert_equals(runs[2].node, self.job.node_pool.nodes[2])
示例#10
0
    def build_job(self):
        self.test_dir = tempfile.mkdtemp()
        self.action = action.Action(name="Test Action")
        self.action.command = "Test command"
        self.action.node_pool = turtle.Turtle()
        self.action.job = turtle.Turtle()
        self.action.job.output_dir = None
        self.run = self.action.build_run(turtle.Turtle(output_dir=self.test_dir))
        self.run.job_run = turtle.Turtle()

        def noop_execute():
            pass

        self.run._execute = noop_execute
示例#11
0
    def test_exception_in_setup_phase(self):
        """If a class_setup method raises an exception, this exception is
        reported as an error in all of the test methods in the test case. The
        methods are then treated as flakes and re-run.
        """
        # Pull and run the test case, thereby causing class_setup to run.
        test_case = get_test(self.server, 'runner')
        assert_equal(len(test_case['methods']), 3)
        # The last method will be the special 'run' method which signals the
        # entire test case is complete (including class_teardown).
        assert_equal(test_case['methods'][-1], 'run')

        self.run_test('runner')

        # 'classTearDown' is a deprecated synonym for 'class_teardown'. We
        # don't especially care about it, but it's in there.
        #
        # Exceptions during execution of class_setup cause test methods to fail
        # and get requeued as flakes. They aren't reported now because they
        # aren't complete.
        expected_methods = set(['classTearDown', 'run'])
        # self.run_test configures us up to collect results submitted at
        # class_teardown completion time. class_setup_teardown methods report
        # the result of their teardown phase at "class_teardown completion"
        # time. So, when testing the setup phase of class_setup_teardown, we
        # will see an "extra" method.
        #
        # Child classes which exercise class_setup_teardown will set
        # self.class_setup_teardown_method_name so we can add it to
        # expected_methods here.
        if hasattr(self, 'class_setup_teardown_method_name'):
            expected_methods.add(self.class_setup_teardown_method_name)
        seen_methods = self.get_seen_methods(self.test_reporter.test_complete.calls)
        # This produces a clearer diff than simply asserting the sets are
        # equal.
        assert_equal(expected_methods.symmetric_difference(seen_methods), set())

        # Verify the failed test case is re-queued for running.
        assert_equal(self.server.test_queue.empty(), False)
        requeued_test_case = get_test(self.server, 'runner2')
        assert_in(self.dummy_test_case.__name__, requeued_test_case['class_path'])

        # Reset reporter.
        self.test_reporter.test_complete = turtle.Turtle()

        # Run tests again.
        self.run_test('runner2')

        # This time, test methods have been re-run as flakes. Now that these
        # methods are are complete, they should be reported.
        expected_methods = set(['test1', 'test2', 'classTearDown', 'run'])
        if hasattr(self, 'class_setup_teardown_method_name'):
            expected_methods.add(self.class_setup_teardown_method_name)
        seen_methods = self.get_seen_methods(self.test_reporter.test_complete.calls)
        # This produces a clearer diff than simply asserting the sets are
        # equal.
        assert_equal(expected_methods.symmetric_difference(seen_methods), set())

        # Verify no more test cases have been re-queued for running.
        assert_equal(self.server.test_queue.empty(), True)
示例#12
0
    def test_remove_old_runs(self):
        self.job.run_limit = 3
        runs = []
        for i in range(6):
            runs.append(self.job.next_runs()[0])
            runs[i].runs[0].node = turtle.Turtle()

        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 6)

        runs[0].queue()
        runs[1].cancel()
        runs[2].succeed()
        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 6)

        runs[0].succeed()
        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 4)

        runs[4].succeed()
        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 3)

        runs[5].succeed()
        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 3)

        runs[3].cancel()
        for i in range(5):
            self.job.next_runs()[0]

        self.job.remove_old_runs()
        assert_equals(len(self.job.runs), 6)
示例#13
0
    def setup(self):
        self.test_dir = tempfile.mkdtemp()
        self.mcp = mcp.MasterControlProgram(self.test_dir, "config")
        self.state_handler = self.mcp.state_handler
        self.action = action.Action("Test Action")

        self.action.command = "Test command"
        self.action.queueing = True
        self.action.node = turtle.Turtle()
        self.job = job.Job("Test Job", self.action)
        self.job.output_dir = self.test_dir

        self.job.node_pool = turtle.Turtle()
        self.job.scheduler = scheduler.IntervalScheduler(
            datetime.timedelta(seconds=5))
        self.action.job = self.job
示例#14
0
 def test_status(self):
     """Verify that we return a status"""
     request = turtle.Turtle()
     resp = self.resource.render_GET(request)
     
     status = simplejson.loads(resp)
     assert status['status']
示例#15
0
    def test_success(self):
        job_run = turtle.Turtle()
        job_run.is_success = True
        job_run.end_time = timeutils.current_time() - datetime.timedelta(
            seconds=30)
        self.job.runs.append(job_run)

        assert self.resource.is_ready
示例#16
0
 def test_transition(self):
     handler = turtle.Turtle()
     self.machine.attach(True, handler)
     self.machine.transition('true')
     assert_equal(
         handler.handler.calls,
         [((self.machine, self.state_green), {})],
     )
示例#17
0
    def build_resource(self):
        self.run = turtle.Turtle(
                      id="1",
                      start_time=None,
                      end_time=None,
                      exit_status=None,
                      is_done=False,
                      )

        self.job = turtle.Turtle(
                                 name="foo",
                                 runs=[self.run],
                                 scheduler=None,
                                 node_pool=TEST_POOL,
                                )

        self.resource = www.JobRunResource(self.run)
示例#18
0
    def build_job(self):
        self.job = turtle.Turtle()
        self.job.runs = []

        self.resource = resource.JobResource(self.job)

        # Freeze the current time to prevent race conditions
        timeutils.override_current_time(datetime.datetime.now())
示例#19
0
    def test_success_too_old(self):
        job_run = turtle.Turtle()
        job_run.is_success = True
        job_run.end_time = timeutils.current_time() - datetime.timedelta(
            days=1)
        self.job.runs.append(job_run)

        assert not self.resource.is_ready
示例#20
0
 def build_scheduler(self):
     self.test_dir = tempfile.mkdtemp()
     self.scheduler = scheduler.DailyScheduler()
     self.action = action.Action("Test Action")
     self.job = job.Job("Test Job", self.action)
     self.job.node_pool = turtle.Turtle()
     self.job.output_dir = self.test_dir
     self.job.scheduler = self.scheduler
     self.action.job = self.job
示例#21
0
    def build_job(self):
        self.job = turtle.Turtle()
        self.job.runs = []

        start_time = datetime.datetime.now()
        timeutils.override_current_time(start_time)

        self.resource = resource.JobResource(self.job)
        self.resource.last_succeed_interval = datetime.timedelta(minutes=1)
示例#22
0
 def test_file_log(self):
     run = self.action.build_run(turtle.Turtle(output_dir=self.test_dir))
     run.stdout_path = "./test_stdout_file.out"
     run.stderr_path = "./test_stderr_file.out"
     run.start()
     assert os.path.isfile("./test_stdout_file.out")
     assert os.path.isfile("./test_stderr_file.out")
     os.remove("./test_stdout_file.out")
     os.remove("./test_stderr_file.out")
示例#23
0
 def build_scheduler(self):
     self.test_dir = tempfile.mkdtemp()
     self.scheduler = scheduler.DailyScheduler(
         start_time=datetime.time(hour=16, minute=30))
     self.action = action.Action("Test Action - Beer Time")
     self.job = job.Job("Test Job", self.action)
     self.job.node_pool = turtle.Turtle()
     self.job.output_dir = self.test_dir
     self.job.scheduler = self.scheduler
     self.action.job = self.job
示例#24
0
 def build_scheduler(self):
     self.test_dir = tempfile.mkdtemp()
     self.interval = datetime.timedelta(seconds=1)
     self.scheduler = scheduler.IntervalScheduler(self.interval)
     self.action = action.Action("Test Action")
     self.job = job.Job("Test Job", self.action)
     self.job.node_pool = turtle.Turtle()
     self.job.output_dir = self.test_dir
     self.job.scheduler = self.scheduler
     self.action.job = self.job
示例#25
0
 def test(self):
     req = twisted.web.server.Request(turtle.Turtle(), None)
     req.args = {'command': ['disable']}
     req.childLink = lambda val : "/jobs/foo/%s" % val
     resp = self.resource.render_POST(req)
     
     # Verify the response
     assert_equal(req.code, twisted.web.http.OK)
     # Check if a run would have been queued
     func = self.job.build_run
示例#26
0
    def setup(self):
        self.test_dir = tempfile.mkdtemp()
        self.action = action.Action(name="Test Action")
        self.action.command = "Test Command"

        self.job = job.Job("Test Job", self.action)
        self.job.output_dir = self.test_dir
        self.job.node_pool = turtle.Turtle()
        self.job.scheduler = scheduler.DailyScheduler()
        self.action.job = self.job
示例#27
0
    def build_resource(self):
        self.mc = turtle.Turtle()
        self.job = turtle.Turtle(
                            name="testname", 
                            enable_act=None,
                            disable_act=None,
                            last_success=None,
                            runs=[], 
                            scheduler_str="testsched", 
                            node_pool=TEST_POOL)
        
        self.service = turtle.Turtle(
                            name='name',
                            runs=[],
                            last_success=None,
                            scheduler_str="testsched",
                            node_pool=TEST_POOL)

        self.mc.jobs = {self.job.name: self.job, self.service.name: self.service}

        self.resource = www.JobsResource(self.mc)
示例#28
0
    def test(self):
        req = twisted.web.server.Request(turtle.Turtle(), None)
        req.prePathURL = lambda : "/jobs/foo/1"
        req.args = {'command': ['start']}
        req.childLink = lambda val : "/jobs/foo/%s" % val
        resp = self.resource.render_POST(req)

        # Verify the response
        assert_equal(req.code, twisted.web.http.OK)
        # Check if a run would have been queued
        func = self.run.start
        assert_equal(len(func.calls), 0)
示例#29
0
    def test_next_run(self):
        assert_equals(self.job.next_runs(), [])
        
        self.action.scheduler = turtle.Turtle()
        self.action.scheduler.next_run = lambda j:None

        assert_equals(self.job.next_runs(), [])
        assert_equals(get_num_runs_by_state(self.job, action.ACTION_RUN_SCHEDULED), 0)

        self.job.scheduler = scheduler.ConstantScheduler()
        assert self.job.next_runs()[0]
        assert_equals(get_num_runs_by_state(self.job, action.ACTION_RUN_SCHEDULED), 1)
示例#30
0
    def build_job(self):
        self.test_dir = tempfile.mkdtemp()
        self.action = action.Action(name="Test Action1")
        self.action.command = "Test command1"
        self.action.node_pool = turtle.Turtle()

        self.dep_action = action.Action(name="Test Action2")
        self.dep_action.command = "Test command2"
        self.dep_action.node_pool = turtle.Turtle()
        self.dep_action.required_actions.append(self.action)

        self.job = job.Job("Test Job", self.action)
        self.job.node_pool = turtle.Turtle()
        self.job.output_dir = self.test_dir
        self.action.job = self.job
        self.dep_action.job = self.job 

        self.job.topo_actions.append(self.dep_action)
        self.job.scheduler = scheduler.DailyScheduler()
        self.job_run = self.job.next_runs()[0]
        self.run = self.job_run.runs[0]
        self.dep_run = self.job_run.runs[1]