def _create_mesos_task(self, mesos_cluster, serializer, attempt, task_id=None): command_config = attempt.command_config return mesos_cluster.create_task( action_run_id=self.id, command=attempt.rendered_command, cpus=command_config.cpus, mem=command_config.mem, disk=1024.0 if command_config.disk is None else command_config.disk, constraints=[[c.attribute, c.operator, c.value] for c in command_config.constraints], docker_image=command_config.docker_image, docker_parameters=[ e._asdict() for e in command_config.docker_parameters ], env=build_environment(original_env=command_config.env, run_id=self.id), extra_volumes=[e._asdict() for e in command_config.extra_volumes], serializer=serializer, task_id=task_id, )
def test_build_environment(self): with mock.patch('tron.bin.action_runner.os.environ', dict(PATH='/usr/bin/nowhere'), autospec=None): env = action_runner.build_environment('MASTER.foo.10.bar') assert env == dict( PATH='/usr/bin/nowhere', TRON_JOB_NAMESPACE='MASTER', TRON_JOB_NAME='foo', TRON_RUN_NUM='10', TRON_ACTION='bar', )
def test_build_environment_invalid_run_id(self): with mock.patch('tron.bin.action_runner.os.environ', dict(PATH='/usr/bin/nowhere'), autospec=None): env = action_runner.build_environment('asdf') assert env == dict( PATH='/usr/bin/nowhere', TRON_JOB_NAMESPACE='UNKNOWN', TRON_JOB_NAME='UNKNOWN', TRON_RUN_NUM='UNKNOWN', TRON_ACTION='UNKNOWN', )