Exemplo n.º 1
0
    def setup_action_runs(self):
        self.run_time = datetime.datetime(2012, 3, 14, 15, 9, 26)
        actions = [Turtle(name='act1'), Turtle(name='act2')]
        self.action_graph = actiongraph.ActionGraph(
            actions, dict((a.name, a) for a in actions))

        mock_node = mock.create_autospec(node.Node)
        self.job_run = jobrun.JobRun('jobname',
                                     7,
                                     self.run_time,
                                     mock_node,
                                     action_graph=self.action_graph)

        self.action_state_data = {
            'job_run_id': 'job_run_id',
            'action_name': 'act1',
            'state': 'succeeded',
            'run_time': 'the_run_time',
            'start_time': None,
            'end_time': None,
            'command': 'do action1',
            'node_name': 'anode'
        }
        self.action_runner = mock.create_autospec(
            actioncommand.SubprocessActionRunnerFactory)
Exemplo n.º 2
0
 def test_run_job_shutdown_requested(self):
     self.job_scheduler.shutdown_requested = True
     self.job_scheduler.schedule = Turtle()
     job_run = Turtle()
     self.job_scheduler.run_job(job_run)
     assert_length(self.job_scheduler.schedule.calls, 0)
     assert_length(job_run.start.calls, 0)
     assert_length(job_run.cancel.calls, 0)
Exemplo n.º 3
0
 def test_run_job_job_disabled(self):
     self.job_scheduler.schedule = Turtle()
     job_run = Turtle()
     self.job.enabled = False
     self.job_scheduler.run_job(job_run)
     assert_length(self.job_scheduler.schedule.calls, 0)
     assert_length(job_run.start.calls, 0)
     assert_length(job_run.cancel.calls, 1)
Exemplo n.º 4
0
 def test_run_job_has_starting_queueing(self):
     self.job_scheduler.schedule = Turtle()
     self.job.runs.get_active = lambda s: [Turtle()]
     job_run = Turtle(is_cancelled=False)
     self.job_scheduler.run_job(job_run)
     assert_length(job_run.start.calls, 0)
     assert_length(job_run.queue.calls, 1)
     assert_length(self.job_scheduler.schedule.calls, 0)
Exemplo n.º 5
0
 def test_run_job_schedule_on_complete(self):
     self.job_scheduler.schedule = Turtle()
     self.scheduler.schedule_on_complete = True
     self.job.runs.get_active = lambda s: []
     job_run = Turtle(is_cancelled=False)
     self.job_scheduler.run_job(job_run)
     assert_length(job_run.start.calls, 1)
     assert_length(self.job_scheduler.schedule.calls, 0)
Exemplo n.º 6
0
 def test_run_job_already_running_cancel(self):
     self.job_scheduler.schedule = Turtle()
     self.job.runs.get_active = lambda s: [Turtle()]
     self.job.queueing = False
     job_run = Turtle(is_cancelled=False)
     self.job_scheduler.run_job(job_run)
     assert_length(job_run.start.calls, 0)
     assert_length(job_run.cancel.calls, 1)
     assert_length(self.job_scheduler.schedule.calls, 1)
Exemplo n.º 7
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')
Exemplo n.º 8
0
 def setup_job(self):
     self.scheduler = Turtle()
     run_collection = Turtle()
     node_pool = Turtle()
     self.job = job.Job(
         "jobname",
         self.scheduler,
         run_collection=run_collection,
         node_pool=node_pool,
     )
     self.job_scheduler = job.JobScheduler(self.job)
Exemplo n.º 9
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
        calls = [mock.call(job_runs[i]) for i in xrange(len(job_runs))]
        self.job.watch.assert_has_calls(calls)
        self.job.event.ok.assert_called_with('restored')
Exemplo n.º 10
0
 def test_run_job_already_running_allow_overlap(self):
     self.job_scheduler.schedule = mock.Mock()
     self.job.runs.get_active = lambda s: [mock.Mock()]
     self.job.allow_overlap = True
     job_run = Turtle(is_cancelled=False)
     self.job_scheduler.run_job(job_run)
     job_run.start.assert_called_with()
Exemplo n.º 11
0
    def test_is_run_blocked_required_actions_blocked(self):
        third_act = Turtle(name='third_act',
                           required_actions=[self.second_act])
        self.action_graph.action_map['third_act'] = third_act
        self.run_map['third_act'] = self._build_run('third_act')

        self.run_map['action_name'].machine.state = ActionRun.STATE_FAILED
        assert self.collection._is_run_blocked(self.run_map['third_act'])
Exemplo n.º 12
0
 def setup_args(self):
     self.args = {
         'number': ['123'],
         'string': ['astring'],
         'boolean': ['1'],
         'datetime': ['2012-03-14 15:09:26']
     }
     self.datetime = datetime.datetime(2012, 3, 14, 15, 9, 26)
     self.request = Turtle(args=self.args)
Exemplo n.º 13
0
    def test_build_run_for_action_with_node(self):
        action = Turtle(name='theaction', is_cleanup=True, command="doit")
        action_run = ActionRunFactory.build_run_for_action(
            self.job_run, action, self.action_runner)

        assert_equal(action_run.job_run_id, self.job_run.id)
        assert_equal(action_run.node, action.node_pool.next.returns[0])
        assert action_run.is_cleanup
        assert_equal(action_run.action_name, action.name)
        assert_equal(action_run.command, action.command)
Exemplo n.º 14
0
    def test_build_run_for_action(self):
        action = Turtle(name='theaction',
                        node_pool=None,
                        is_cleanup=False,
                        command="doit")
        action_run = ActionRunFactory.build_run_for_action(
            self.job_run, action, self.action_runner)

        assert_equal(action_run.job_run_id, self.job_run.id)
        assert_equal(action_run.node, self.job_run.node)
        assert_equal(action_run.action_name, action.name)
        assert not action_run.is_cleanup
        assert_equal(action_run.command, action.command)
Exemplo n.º 15
0
 def setup_jobrun(self):
     self.job = build_mock_job()
     self.action_graph = self.job.action_graph
     self.run_time = datetime.datetime(2012, 3, 14, 15, 9 ,26)
     mock_node = mock.create_autospec(node.Node)
     self.job_run = jobrun.JobRun('jobname', 7, self.run_time, mock_node,
             action_runs=Turtle(
                 action_runs_with_cleanup=[],
                 get_startable_action_runs=lambda: []))
     autospec_method(self.job_run.watch)
     autospec_method(self.job_run.notify)
     self.job_run.event = mock.create_autospec(event.EventRecorder)
     self.action_run = mock.create_autospec(actionrun.ActionRun, is_skipped=False)
Exemplo n.º 16
0
 def setup_action_run(self):
     self.parent_context = {}
     self.output_path = ['one', 'two']
     self.state_data = {
         'job_run_id': 'theid',
         'action_name': 'theaction',
         'node_name': 'anode',
         'command': 'do things',
         'start_time': 'start_time',
         'end_time': 'end_time',
         'state': 'succeeded'
     }
     self.run_node = Turtle()
Exemplo n.º 17
0
    def setup_collection(self):
        action_names = ['action_name', 'second_name', 'cleanup']

        action_graph = [
            Turtle(name=name, required_actions=[]) for name in action_names
        ]
        self.second_act = second_act = action_graph.pop(1)
        second_act.required_actions.append(action_graph[0])
        action_map = dict((a.name, a) for a in action_graph)
        action_map['second_name'] = second_act
        self.action_graph = actiongraph.ActionGraph(action_graph, action_map)

        self.output_path = filehandler.OutputPath(tempfile.mkdtemp())
        self.command = "do command"
        self.action_runs = [self._build_run(name) for name in action_names]
        self.run_map = dict((a.action_name, a) for a in self.action_runs)
        self.run_map['cleanup'].is_cleanup = True
        self.collection = ActionRunCollection(self.action_graph, self.run_map)
Exemplo n.º 18
0
    def setup_job(self):
        action_graph = mock.Mock(names=lambda: ['one', 'two'])
        scheduler = mock.Mock()
        run_collection = Turtle()
        self.nodes = mock.create_autospec(node.NodePool)
        self.action_runner = mock.create_autospec(
            actioncommand.SubprocessActionRunnerFactory)

        patcher = mock.patch('tron.core.job.node.NodePoolRepository')
        with patcher as self.mock_node_repo:
            self.job = job.Job("jobname",
                               scheduler,
                               run_collection=run_collection,
                               action_graph=action_graph,
                               node_pool=self.nodes)
            autospec_method(self.job.notify)
            autospec_method(self.job.watch)
            self.job.event = mock.create_autospec(event.EventRecorder)
            yield
Exemplo n.º 19
0
 def test_status_running(self):
     self.job.runs.get_run_by_state = lambda s: Turtle()
     assert_equal(self.job.status, self.job.STATUS_RUNNING)
Exemplo n.º 20
0
 def test_action_runs_for_actions(self):
     actions = [Turtle(name='action_name')]
     action_runs = self.collection.action_runs_for_actions(actions)
     assert_equal(list(action_runs), self.action_runs[:1])
Exemplo n.º 21
0
 def test_run_job_cancelled(self):
     self.job_scheduler.schedule = Turtle()
     job_run = Turtle(is_scheduled=False)
     self.job_scheduler.run_job(job_run)
     assert_length(job_run.start.calls, 0)
     assert_length(self.job_scheduler.schedule.calls, 1)
Exemplo n.º 22
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