示例#1
0
文件: jobrun.py 项目: ekmixon/Tron
    def from_state(
        cls,
        state_data,
        action_graph,
        output_path,
        context,
        run_node,
    ):
        """Restore a JobRun from a serialized state."""
        pool_repo = node.NodePoolRepository.get_instance()
        run_node = pool_repo.get_node(state_data.get('node_name'), run_node)
        job_name = state_data['job_name']

        job_run = cls(
            job_name,
            state_data['run_num'],
            state_data['run_time'],
            run_node,
            action_graph=action_graph,
            manual=state_data.get('manual', False),
            output_path=output_path,
            base_context=context,
        )
        action_runs = ActionRunFactory.action_run_collection_from_state(
            job_run,
            state_data['runs'],
            state_data['cleanup_run'],
        )
        job_run.action_runs = action_runs
        return job_run
示例#2
0
    def from_state(
        cls,
        state_data,
        action_graph,
        output_path,
        context,
        run_node,
    ):
        """Restore a JobRun from a serialized state."""
        pool_repo = node.NodePoolRepository.get_instance()
        run_node = pool_repo.get_node(state_data.get('node_name'), run_node)
        job_name = state_data['job_name']

        job_run = cls(
            job_name,
            state_data['run_num'],
            state_data['run_time'],
            run_node,
            action_graph=action_graph,
            manual=state_data.get('manual', False),
            output_path=output_path,
            base_context=context,
        )
        action_runs = ActionRunFactory.action_run_collection_from_state(
            job_run,
            state_data['runs'],
            state_data['cleanup_run'],
        )
        job_run.action_runs = action_runs
        return job_run
示例#3
0
    def test_action_run_collection_from_state(self):
        state_data = [self.action_state_data]
        cleanup_action_state_data = {
            'job_run_id': 'job_run_id',
            'action_name': 'cleanup',
            'state': 'succeeded',
            'run_time': self.run_time,
            'start_time': None,
            'end_time': None,
            'command': 'do cleanup',
            'node_name': 'anode',
            'action_runner': {
                'status_path': '/tmp/foo',
                'exec_path': '/bin/foo'
            }
        }
        collection = ActionRunFactory.action_run_collection_from_state(
            self.job_run,
            state_data,
            cleanup_action_state_data,
        )

        assert_equal(collection.action_graph, self.action_graph)
        assert_length(collection.run_map, 2)
        assert_equal(collection.run_map['act1'].action_name, 'act1')
        assert_equal(collection.run_map['cleanup'].action_name, 'cleanup')
示例#4
0
 def test_build_run_for_mesos_action(self):
     action = MagicMock(
         name='theaction',
         command="doit",
         executor=ExecutorTypes.mesos,
         cpus=10,
         mem=500,
         constraints=[['pool', 'LIKE', 'default']],
         docker_image='fake-docker.com:400/image',
         docker_parameters=[{
             'key': 'test',
             'value': 123
         }],
         env={'TESTING': 'true'},
         extra_volumes=[{
             'path': '/tmp'
         }],
     )
     action_run = ActionRunFactory.build_run_for_action(
         self.job_run,
         action,
         self.action_runner,
     )
     assert_equal(action_run.__class__, MesosActionRun)
     assert_equal(action_run.cpus, action.cpus)
     assert_equal(action_run.mem, action.mem)
     assert_equal(action_run.constraints, action.constraints)
     assert_equal(action_run.docker_image, action.docker_image)
     assert_equal(action_run.docker_parameters, action.docker_parameters)
     assert_equal(action_run.env, action.env)
     assert_equal(action_run.extra_volumes, action.extra_volumes)
示例#5
0
    def test_action_run_from_state_mesos(self):
        state_data = self.action_state_data
        state_data['executor'] = ExecutorTypes.mesos
        state_data['cpus'] = 2
        state_data['mem'] = 200
        state_data['constraints'] = [['pool', 'LIKE', 'default']]
        state_data['docker_image'] = 'fake-docker.com:400/image'
        state_data['docker_parameters'] = [{'key': 'test', 'value': 123}]
        state_data['env'] = {'TESTING': 'true'}
        state_data['extra_volumes'] = [{'path': '/tmp'}]
        action_run = ActionRunFactory.action_run_from_state(
            self.job_run,
            state_data,
        )

        assert_equal(action_run.job_run_id, state_data['job_run_id'])
        assert_equal(action_run.cpus, state_data['cpus'])
        assert_equal(action_run.mem, state_data['mem'])
        assert_equal(action_run.constraints, state_data['constraints'])
        assert_equal(action_run.docker_image, state_data['docker_image'])
        assert_equal(action_run.docker_parameters,
                     state_data['docker_parameters'])
        assert_equal(action_run.env, state_data['env'])
        assert_equal(action_run.extra_volumes, state_data['extra_volumes'])

        assert not action_run.is_cleanup
        assert_equal(action_run.__class__, MesosActionRun)
示例#6
0
 def test_build_action_run_collection(self):
     collection = ActionRunFactory.build_action_run_collection(self.job_run)
     assert_equal(collection.action_graph, self.action_graph)
     assert_in('act1', collection.run_map)
     assert_in('act2', collection.run_map)
     assert_length(collection.run_map, 2)
     assert_equal(collection.run_map['act1'].action_name, 'act1')
示例#7
0
    def test_action_run_from_state(self):
        state_data = self.action_state_data
        action_run = ActionRunFactory.action_run_from_state(
            self.job_run, state_data)

        assert_equal(action_run.job_run_id, state_data['job_run_id'])
        assert not action_run.is_cleanup
示例#8
0
文件: jobrun.py 项目: Bklyn/Tron
    def from_state(cls, state_data, action_graph, output_path, context,
                run_node):
        """Restore a JobRun from a serialized state."""
        node_pools = node.NodePoolStore.get_instance()
        if state_data.get('node_name'):
            run_node = node_pools.get(state_data['node_name'])

        # TODO: remove in 0.6
        if 'job_name' not in state_data:
            # This is only to support old state files.
            job_name = state_data['id'].split('.')[0]
        else:
            job_name = state_data['job_name']

        job_run =  cls(
            job_name,
            state_data['run_num'],
            state_data['run_time'],
            run_node,
            action_graph=action_graph,
            manual=state_data.get('manual', False),
            output_path=output_path,
            base_context=context
        )
        action_runs = ActionRunFactory.action_run_collection_from_state(
                job_run, state_data['runs'], state_data['cleanup_run'])
        job_run.action_runs = action_runs
        return job_run
示例#9
0
    def test_action_run_from_state(self):
        state_data = self.action_state_data
        action_run = ActionRunFactory.action_run_from_state(
                self.job_run, state_data)

        assert_equal(action_run.job_run_id, state_data['job_run_id'])
        assert not action_run.is_cleanup
示例#10
0
文件: jobrun.py 项目: Bklyn/Tron
    def for_job(cls, job, run_num, run_time, node, manual):
        """Create a JobRun for a job."""
        run = cls(job.name, run_num, run_time, node, job.output_path.clone(),
                job.context, action_graph=job.action_graph, manual=manual)

        action_runs     = ActionRunFactory.build_action_run_collection(run)
        run.action_runs = action_runs
        return run
示例#11
0
 def test_build_action_run_collection(self):
     collection = ActionRunFactory.build_action_run_collection(
         self.job_run, self.action_runner)
     assert_equal(collection.action_graph, self.action_graph)
     assert_in('act1', collection.run_map)
     assert_in('act2', collection.run_map)
     assert_length(collection.run_map, 2)
     assert_equal(collection.run_map['act1'].action_name, 'act1')
示例#12
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)

        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)
示例#13
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)

        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)
示例#14
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)
示例#15
0
 def test_build_run_for_ssh_action(self):
     action = MagicMock(
         name='theaction',
         command="doit",
         executor=ExecutorTypes.ssh,
     )
     action_run = ActionRunFactory.build_run_for_action(
         self.job_run,
         action,
         self.action_runner,
     )
     assert_equal(action_run.__class__, SSHActionRun)
示例#16
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)
示例#17
0
    def test_build_run_for_action_with_node(self):
        action = MagicMock(name='theaction', is_cleanup=True, command="doit")
        action.node_pool = mock.create_autospec(node.NodePool)
        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())
        assert action_run.is_cleanup
        assert_equal(action_run.action_name, action.name)
        assert_equal(action_run.command, action.command)
示例#18
0
    def for_job(cls, job, run_num, run_time, node, manual):
        """Create a JobRun for a job."""
        run = cls(job.get_name(),
                  run_num,
                  run_time,
                  node,
                  job.output_path.clone(),
                  job.context,
                  action_graph=job.action_graph,
                  manual=manual)

        action_runs = ActionRunFactory.build_action_run_collection(
            run, job.action_runner)
        run.action_runs = action_runs
        return run
示例#19
0
    def test_action_run_collection_from_state(self):
        state_data = [self.action_state_data]
        cleanup_action_state_data = {
            'job_run_id':       'job_run_id',
            'action_name':      'cleanup',
            'state':            'succeeded',
            'run_time':         self.run_time,
            'start_time':       None,
            'end_time':         None,
            'command':          'do cleanup',
            'node_name':        'anode'
        }
        collection = ActionRunFactory.action_run_collection_from_state(
            self.job_run, state_data, cleanup_action_state_data)

        assert_equal(collection.action_graph, self.action_graph)
        assert_length(collection.run_map, 2)
        assert_equal(collection.run_map['act1'].action_name, 'act1')
        assert_equal(collection.run_map['cleanup'].action_name, 'cleanup')