def test_create_executor_output_streams(self, app, mocker): """ Verifies presence of output stream mapping in executor causes adds an additional task to handle stream copy """ mocked_batch_client, mocked_blob_client, mocked_file_client = setup_common_mocks_for_create( mocker) task = models.TesTask( name="task-name", description="task-description", executors=[ models.TesExecutor( image="ubuntu:latest", command=["ls", "-l"], stdout="/tes-wd/shared/executions/stdout.txt", stderr="/tes-wd/shared/executions/stderr.txt"), models.TesExecutor( image="ubuntu:latest", command=["ls", "-l"], stdout="/tes-wd/shared/executions/stdout.txt", stderr="/tes-wd/shared/executions/stderr.txt") ]) result = compute_backend.backend.createJob(task) assert (uuid.UUID(result)) assert (mocked_batch_client.return_value.job.add.call_count == 1) assert (mocked_batch_client.return_value.task.add.call_count == len( task.executors))
def test_multiple_executors(self, app, mocker): """ Verifies task is added for each executor """ mocked_batch_client, mocked_blob_client, mocked_file_client = setup_common_mocks_for_create( mocker) task = models.TesTask( name="task-name", description="task-description", executors=[ models.TesExecutor(image="alpine", command=["pwd"]), models.TesExecutor( image="ubuntu:latest", command=["ls", "-l"], workdir="/tes-wd/shared", ), models.TesExecutor( image= "ubuntu@sha256:868fd30a0e47b8d8ac485df174795b5e2fe8a6c8f056cc707b232d65b8a1ab68", command=["ls -l"], workdir="/tes-wd", ) ]) result = compute_backend.backend.createJob(task) assert (uuid.UUID(result)) assert (mocked_batch_client.return_value.job.add.call_count == 1) assert (mocked_batch_client.return_value.task.add.call_count == len( task.executors))
def test_create_executor_environment(self, app, mocker): """ Verifies environment variables are mapped to tasks """ environ = {"foo": "bar"} mocked_batch_client, mocked_blob_client, mocked_file_client = setup_common_mocks_for_create( mocker) task = models.TesTask(name="task-name", description="task-description", executors=[ models.TesExecutor( image="ubuntu:latest", command=["ls", "-l"], env=environ, ) ]) result = compute_backend.backend.createJob(task) assert (uuid.UUID(result)) # ensure env mappings are present args, kwargs = mocked_batch_client.return_value.task.add.call_args batch_task = kwargs['task'] assert (isinstance(batch_task, azbatch.models.TaskAddParameter)) assert (batch_task.environment_settings == [ azbatch.models.EnvironmentSetting(name=k, value=v) for k, v in environ.items() ])
def test_copy_command_generation_with_dirs(self): executor = tesmodels.TesExecutor() executor.stderr = '/a/b/c/foo' # we expect a mkdir and cp command for stdout and stderr commands = common.commands.generate_copy_commands("stderr.txt", executor.stderr) assert(len(commands) == 2)
def test_copy_command_generation_nodirs(self): executor = tesmodels.TesExecutor() # no directory prefixes on these executor.stdout = 'foo' # we expect a cp command only, for stdout and stderr commands = common.commands.generate_copy_commands("stdout.txt", executor.stdout) assert(len(commands) == 1) for command in commands: assert(command.startswith('cp'))
def test_tes_task_procedural_build(self, session): schema = models.TesTaskSchema() # Read a sample task from file with open( os.path.join('tests', 'unit', 'data', 'test_models_task.json')) as fh: task_json = json.loads(fh.read()) task_from_file = schema.load(task_json).data # Define same task programattically tags = {"tag-key": "tag-value"} executors = [ models.TesExecutor(image="alpine", command=["pwd"]), models.TesExecutor(image="ubuntu:latest", command=["ls", "-l"], env={"foo": "bar"}, workdir="/tes-wd/shared", stdout="/tes-wd/shared/executions/stdout.txt", stderr="/tes-wd/shared/executions/stderr.txt"), models.TesExecutor( image= "ubuntu@sha256:868fd30a0e47b8d8ac485df174795b5e2fe8a6c8f056cc707b232d65b8a1ab68", command=["cat"], workdir="/tes-wd/shared", stdin="/tes-wd/shared/executions/stdin.txt") ] resources = models.TesResources(cpu_cores=4, disk_gb=4, preemptible=True, ram_gb=7) inputs = [ models.TesInput( url="https://tesazure.blob.core.windows.net/samples/random.dat", path="random.dat", description="input-description", name="input-name", type=models.TesFileType.FILE, ), models.TesInput(path="/tes-wd/shared/script", description="Should echo OK", content='#!/bin/bash\necho "OK"', name="commandScript", type=models.TesFileType.FILE) ] outputs = [ models.TesOutput( url="https://tesazure.blob.core.windows.net/samples/random.dat", path="random.dat", description="output-description", name="output-name", type=models.TesFileType.FILE) ] task_from_code = models.TesTask(name="task-name", description="task-description", tags=tags, executors=executors, resources=resources, inputs=inputs, outputs=outputs) # Ensure they are equivalent assert (schema.dump(task_from_code).data == schema.dump( task_from_file).data)