Ejemplo n.º 1
0
    def test_start_no_startable_action_runs(self):
        self.job_run._do_start = Turtle()
        self.job_run.action_runs.has_startable_action_runs = False

        assert not self.job_run.start()
        assert_call(self.job_run.notify, 0, self.job_run.EVENT_START)
        assert_length(self.job_run.notify.calls, 1)
Ejemplo n.º 2
0
    def test_start(self):
        self.job_run._do_start = Turtle()

        assert self.job_run.start()
        assert_call(self.job_run.notify, 0, self.job_run.EVENT_START)
        assert_call(self.job_run._do_start, 0)
        assert_length(self.job_run.notify.calls, 1)
Ejemplo n.º 3
0
    def test_manual_start_with_run_time(self):
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        manual_runs = self.job_scheduler.manual_start(run_time)

        assert_call(self.job.build_new_runs, 0, run_time, manual=True)
        assert_length(manual_runs, 1)
        assert_length(self.manual_run.start.calls, 1)
Ejemplo n.º 4
0
    def test_handler_finished_with_cleanup(self):
        self.job_run.action_runs.cleanup_action_run = Turtle(is_done=False)
        self.job_run.finalize = Turtle()

        self.job_run.handler(None, actionrun.ActionRun.STATE_SUCCEEDED)
        assert_length(self.job_run.finalize.calls, 0)
        assert_call(self.job_run.action_runs.cleanup_action_run.start, 0)
Ejemplo n.º 5
0
    def test_get_runs_to_schedule_no_last_run(self):
        self.job.runs.get_newest = lambda **kwargs: None

        job_runs = list(self.job_scheduler.get_runs_to_schedule())
        assert_length(self.job.scheduler.next_run_time.calls, 1)
        assert_length(job_runs, 1)
        # This should return a JobRun which has the job attached as an observer
        assert_call(job_runs[0].attach, 0, True, self.job)
Ejemplo n.º 6
0
    def test_remove_old_runs(self):
        self.run_collection.run_limit = 1
        self.run_collection.remove_old_runs()

        assert_length(self.run_collection.runs, 1)
        assert_call(self.job_runs[-1].cleanup, 0)
        for job_run in self.run_collection.runs:
            assert_length(job_run.cancel.calls, 0)
Ejemplo n.º 7
0
    def test_remove_old_runs(self):
        self.run_collection.run_limit = 1
        self.run_collection.remove_old_runs()

        assert_length(self.run_collection.runs, 1)
        assert_call(self.job_runs[-1].cleanup, 0)
        for job_run in self.run_collection.runs:
            assert_length(job_run.cancel.calls, 0)
Ejemplo n.º 8
0
    def test_get_runs_to_schedule_no_pending(self):
        job_runs = list(self.job_scheduler.get_runs_to_schedule())

        assert_call(self.job.runs.get_newest, 0, include_manual=False)
        assert_length(self.job.scheduler.next_run_time.calls, 1)
        assert_length(job_runs, 1)
        # This should return a JobRun which has the job attached as an observer
        assert_call(job_runs[0].attach, 0, True, self.job)
Ejemplo n.º 9
0
 def test_handle_job_events_no_schedule_on_complete(self):
     self.job_scheduler.run_job = mock.Mock()
     self.job.scheduler.schedule_on_complete = False
     queued_job_run = mock.Mock()
     self.job.runs.get_first_queued = lambda: queued_job_run
     self.job_scheduler.handle_job_events(self.job, job.Job.NOTIFY_RUN_DONE)
     assert_call(self.reactor.callLater, 0, 0,
         self.job_scheduler.run_job, queued_job_run, run_queued=True)
Ejemplo n.º 10
0
    def test_reconfigure(self):
        self.mcp._load_config = Turtle()
        self.mcp.state_manager = mock.Mock()
        cm = mocks.MockContextManager()
        self.mcp.state_manager.disabled = mock.Mock(return_value=cm)

        self.mcp.reconfigure()
        assert_call(self.mcp._load_config, 0, reconfigure=True)
        self.mcp.state_manager.disabled.assert_called_with()
Ejemplo n.º 11
0
 def test_restore_job_state(self):
     run_collection = mocks.MockJobRunCollection(get_scheduled=lambda: ['a'])
     self.job_scheduler.job = Turtle(runs=run_collection)
     self.job_scheduler._set_callback = Turtle()
     state_data = 'state_data_token'
     self.job_scheduler.restore_state(state_data)
     assert_call(self.job_scheduler.job.restore_state, 0, state_data)
     assert_length(self.job_scheduler._set_callback.calls, 1)
     assert_call(self.job_scheduler._set_callback, 0, 'a')
Ejemplo n.º 12
0
    def test_build_new_runs_manual(self):
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        runs = list(self.job.build_new_runs(run_time, manual=True))

        self.job.node_pool.next.assert_called_with()
        node = self.job.node_pool.next.return_value
        assert_length(runs, 1)
        assert_call(self.job.runs.build_new_run,
                0, self.job, run_time, node, manual=True)
        self.job.watch.assert_called_with(runs[0])
Ejemplo n.º 13
0
 def test_restore_job_state(self):
     run_collection = mocks.MockJobRunCollection(
         get_scheduled=lambda: ['a'])
     self.job_scheduler.job = Turtle(runs=run_collection)
     self.job_scheduler._set_callback = Turtle()
     state_data = 'state_data_token'
     self.job_scheduler.restore_state(state_data)
     assert_call(self.job_scheduler.job.restore_state, 0, state_data)
     assert_length(self.job_scheduler._set_callback.calls, 1)
     assert_call(self.job_scheduler._set_callback, 0, 'a')
Ejemplo n.º 14
0
    def test_cleanup(self):
        self.job_run.clear_observers = Turtle()
        self.job_run.output_path = Turtle()
        self.job_run.cleanup()

        assert_call(self.job_run.clear_observers, 0)
        assert_call(self.job_run.output_path.delete, 0)
        assert not self.job_run.node
        assert not self.job_run.action_graph
        assert not self.job_run.action_runs
Ejemplo n.º 15
0
 def test_restore_state(self):
     def restore(jobs, services):
         state_data = {'1': 'things', '2': 'things'}
         return state_data, state_data
     self.mcp.state_watcher = Turtle(restore=restore)
     self.mcp.restore_state()
     for job in self.mcp.jobs.values():
         assert_call(job.restore_job_state, 0, 'things')
     for service in self.mcp.services.values():
         assert_call(service.restore_service_state, 0, 'things')
Ejemplo n.º 16
0
    def test_handler_with_startable(self):
        self.job_run.action_runs.get_startable_action_runs = lambda: True
        startable_run = Turtle()
        self.job_run.action_runs.get_startable_action_runs = lambda: [startable_run]
        self.job_run.finalize = Turtle()

        self.job_run.handler(None, actionrun.ActionRun.STATE_SUCCEEDED)
        assert_call(self.job_run.notify, 0, self.job_run.NOTIFY_STATE_CHANGED)
        assert_call(startable_run.start, 0)
        assert_length(self.job_run.finalize.calls, 0)
Ejemplo n.º 17
0
    def test_restore_state_partial(self):
        def restore(jobs, services):
            return {'1': 'thing'}, {'2': 'thing'}
        self.mcp.state_watcher = Turtle(restore=restore)
        self.mcp.restore_state()

        assert_call(self.mcp.jobs['1'].restore_job_state, 0, 'thing')
        assert_length(self.mcp.jobs['2'].restore_job_state.calls, 0)
        assert_length(self.mcp.services['1'].restore_service_state.calls, 0)
        assert_call(self.mcp.services['2'].restore_service_state, 0, 'thing')
Ejemplo n.º 18
0
 def test_set_action_runs(self):
     self.job_run._action_runs = None
     action_runs = [Turtle(), Turtle()]
     run_collection = Turtle(action_runs_with_cleanup=action_runs)
     self.job_run._set_action_runs(run_collection)
     assert_length(self.job_run.watch.calls, 2)
     for i in xrange(2):
         assert_call(self.job_run.watch, i, action_runs[i])
     assert_equal(self.job_run.action_runs, run_collection)
     assert self.job_run.action_runs_proxy
Ejemplo n.º 19
0
    def test_handler_with_startable(self):
        startable_run = mock.create_autospec(actionrun.ActionRun)
        self.job_run.action_runs.get_startable_action_runs = lambda: [startable_run]
        autospec_method(self.job_run.finalize)
        self.action_run.is_broken = False

        self.job_run.handler(self.action_run, mock.Mock())
        assert_call(self.job_run.notify, 0, self.job_run.NOTIFY_STATE_CHANGED)
        startable_run.start.assert_called_with()
        assert not self.job_run.finalize.mock_calls
Ejemplo n.º 20
0
 def test_build_new_run_manual(self):
     self.run_collection.remove_old_runs = Turtle()
     run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
     job = Turtle(name="thejob")
     job.action_graph.action_map = {}
     node = MockNode("thenode")
     job_run = self.run_collection.build_new_run(job, run_time, node, True)
     assert_in(job_run, self.run_collection.runs)
     assert_call(self.run_collection.remove_old_runs, 0)
     assert_equal(job_run.run_num, 5)
     assert job_run.manual
Ejemplo n.º 21
0
    def test_build_new_runs_all_nodes(self):
        self.job.all_nodes = True
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        runs = list(self.job.build_new_runs(run_time))

        assert_length(runs, 2)
        for i in xrange(len(runs)):
            node = self.job.node_pool.nodes[i]
            assert_call(self.job.runs.build_new_run,
                    i, self.job, run_time, node, manual=False)
            assert_call(self.job.watch, 1, runs[1])
Ejemplo n.º 22
0
    def test_restore_state(self):
        run_data = ['one', 'two']
        job_runs = [Turtle(), Turtle()]
        self.job.runs.restore_state = lambda r, a, o, c, n: job_runs
        state_data = {'enabled': False, 'runs': run_data}

        self.job.restore_state(state_data)

        assert not self.job.enabled
        for i in xrange(len(job_runs)):
            assert_call(self.job.watch, i, job_runs[i])
        assert_call(self.job.notify, 0, self.job.EVENT_STATE_RESTORED)
Ejemplo n.º 23
0
    def test_schedule(self):
        self.job_scheduler.schedule()
        assert_length(self.reactor.callLater.calls, 1)

        # Args passed to callLater
        call_args = self.reactor.callLater.calls[0][0]
        assert_equal(call_args[1], self.job_scheduler.run_job)
        secs = call_args[0]
        run = call_args[2]

        assert_call(run.seconds_until_run_time, 0)
        # Assert that we use the seconds we get from the run to schedule
        assert_equal(run.seconds_until_run_time.returns[0], secs)
Ejemplo n.º 24
0
    def test_build_new_runs_all_nodes(self):
        self.job.all_nodes = True
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        node_count = 2
        self.job.node_pool.nodes = [mock.Mock()] * node_count
        runs = list(self.job.build_new_runs(run_time))

        assert_length(runs, node_count)
        for i in xrange(len(runs)):
            node = self.job.node_pool.nodes[i]
            assert_call(self.job.runs.build_new_run,
                    i, self.job, run_time, node, manual=False)

        self.job.watch.assert_has_calls([mock.call(run) for run in runs])
Ejemplo n.º 25
0
    def test_build_new_runs_manual(self):
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        runs = list(self.job.build_new_runs(run_time, manual=True))

        self.job.node_pool.next.assert_called_with()
        node = self.job.node_pool.next.return_value
        assert_length(runs, 1)
        assert_call(self.job.runs.build_new_run,
                    0,
                    self.job,
                    run_time,
                    node,
                    manual=True)
        self.job.watch.assert_called_with(runs[0])
Ejemplo n.º 26
0
    def test_build_new_runs_all_nodes(self):
        self.job.all_nodes = True
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        node_count = 2
        self.job.node_pool.nodes = [mock.Mock()] * node_count
        runs = list(self.job.build_new_runs(run_time))

        assert_length(runs, node_count)
        for i in xrange(len(runs)):
            node = self.job.node_pool.nodes[i]
            assert_call(self.job.runs.build_new_run,
                        i,
                        self.job,
                        run_time,
                        node,
                        manual=False)

        self.job.watch.assert_has_calls([mock.call(run) for run in runs])
Ejemplo n.º 27
0
    def test_build_new_runs(self):
        run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        runs = list(self.job.build_new_runs(run_time))

        assert_call(self.job.node_pool.next, 0)
        node = self.job.node_pool.next.returns[0]
        assert_call(self.job.runs.build_new_run,
                0, self.job, run_time, node, manual=False)
        assert_length(runs, 1)
        assert_call(self.job.watch, 0, runs[0])
Ejemplo n.º 28
0
    def test_do_start(self):
        startable_runs = [Turtle(), Turtle(), Turtle()]
        self.job_run.action_runs.get_startable_action_runs = lambda: startable_runs

        assert self.job_run._do_start()
        assert_call(self.job_run.action_runs.ready, 0)
        for i, startable_run in enumerate(startable_runs):
            assert_call(startable_run.start, 0)

        assert_length(self.job_run.notify.calls, 1)
        assert_call(self.job_run.notify, 0, self.job_run.EVENT_STARTED)
Ejemplo n.º 29
0
 def test_enable_all(self):
     self.controller.enable_all()
     for job in self.jobs:
         assert_call(job.enable, 0)
Ejemplo n.º 30
0
 def test_render_GET(self):
     self.resource.get_data = Turtle()
     result = self.resource.render_GET(REQUEST)
     assert_call(self.resource.get_data, 0, False, False)
     assert 'jobs' in result
Ejemplo n.º 31
0
 def test_render_GET(self):
     self.resource.get_data = MagicMock()
     result = self.resource.render_GET(REQUEST)
     assert_call(self.resource.get_data, 0, False, False, True, True)
     assert 'jobs' in result
Ejemplo n.º 32
0
 def test_emit_crash(self):
     self.event_dict['message'] = ["Ooops"]
     self.event_dict['isError'] = True
     self.reporter.emit(self.event_dict)
     assert_call(self.emailer.send, 0, "Ooops")
Ejemplo n.º 33
0
 def test_remove_pending(self):
     self.run_collection.remove_pending()
     assert_length(self.run_collection.runs, 3)
     assert_equal(self.run_collection.runs[0], self.job_runs[1])
     assert_call(self.job_runs[0].cleanup, 0)
Ejemplo n.º 34
0
 def test_render_GET(self):
     resource = resource_fixture()
     resource.get_data = MagicMock()
     result = resource.render_GET(REQUEST)
     assert_call(resource.get_data, 0, False, False, True, True)
     assert 'jobs' in result
Ejemplo n.º 35
0
 def test_remove_pending(self):
     self.run_collection.remove_pending()
     assert_length(self.run_collection.runs, 4)
     assert_equal(self.run_collection.runs[0], self.job_runs[1])
     assert_call(self.job_runs[0].cleanup, 0)
Ejemplo n.º 36
0
 def test_render_GET(self):
     self.resource.get_data = Turtle()
     result = self.resource.render_GET(REQUEST)
     assert_call(self.resource.get_data, 0, False, False)
     assert 'jobs' in result
Ejemplo n.º 37
0
 def test_emit_crash(self):
     self.event_dict['message'] = ["Ooops"]
     self.event_dict['isError'] = True
     self.reporter.emit(self.event_dict)
     assert_call(self.emailer.send, 0, "Ooops")
Ejemplo n.º 38
0
 def test_handle_job_events_schedule_on_complete(self):
     self.job_scheduler.schedule = Turtle()
     self.job.scheduler.schedule_on_complete = True
     self.job_scheduler.handle_job_events(self.job, job.Job.NOTIFY_RUN_DONE)
     assert_call(self.job_scheduler.schedule, 0)