Skip to content

Commit a7998fd

Browse files
committed
fix tests for workflow validation
Signed-off-by: Sam Rooke <[email protected]>
1 parent 42cdae0 commit a7998fd

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/TaskManager/Plug-ins/Argo/ArgoPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private void AddLimit(Template2 template, ResourcesKey key)
467467
value = bool.TryParse(value, out bool gpuRequired) && gpuRequired ? "1" : "0";
468468
}
469469

470-
template.Container.Resources.Limits.Add(key.ArgoKey, value);
470+
template.Container.Resources.Limits[key.ArgoKey] = value;
471471
}
472472

473473
private async Task AddMainWorkflowTemplate(Workflow workflow, CancellationToken cancellationToken)

src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,17 @@ private void ValidateInputs(TaskObject currentTask)
350350

351351
private void ValidateArgoTask(TaskObject currentTask)
352352
{
353-
var validKeys = new string[] { WorkflowTemplateName, TaskPriorityClassName, Cpu, Memory, GpuRequired };
354-
if (currentTask.Args.Keys.Any(k => !validKeys.Contains(k)))
353+
if (!currentTask.Args.ContainsKey(WorkflowTemplateName))
355354
{
356-
Errors.Add($"Task: '{currentTask.Id}' args has invalid keys. Please only specify keys from the following list: {string.Join(", ", validKeys)}.");
357-
return;
355+
Errors.Add($"Task: '{currentTask.Id}' workflow_template_name must be specified{Comma}this corresponds to an Argo template name.");
358356
}
359357

360-
if (!currentTask.Args.ContainsKey(WorkflowTemplateName))
358+
var validKeys = new string[] { WorkflowTemplateName, TaskPriorityClassName, Cpu, Memory, GpuRequired };
359+
var invalidKeys = currentTask.Args.Keys.Where(k => !validKeys.Contains(k));
360+
if (invalidKeys.Count() > 0)
361361
{
362-
Errors.Add($"Task: '{currentTask.Id}' workflow_template_name must be specified{Comma}this corresponds to an Argo template name.");
362+
Errors.Add($"Task: '{currentTask.Id}' args has invalid keys: {string.Join(", ", invalidKeys)}. Please only specify keys from the following list: {string.Join(", ", validKeys)}.");
363+
return;
363364
}
364365

365366
if (currentTask.Args.ContainsKey(TaskPriorityClassName))

tests/UnitTests/TaskManager.Argo.Tests/ArgoPluginTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ private static void ValidateSimpleTemplate(TaskDispatchEvent message, Workflow w
371371
Assert.True(template.Container.Resources?.Limits is not null);
372372
var value = "";
373373

374-
Assert.True(template.Container.Resources?.Limits?.TryGetValue("limits.memory", out value));
374+
Assert.True(template.Container.Resources?.Limits?.TryGetValue("memory", out value));
375375
Assert.True(value == "1");
376-
Assert.True(template.Container.Resources?.Limits?.TryGetValue("limits.cpu", out value));
376+
Assert.True(template.Container.Resources?.Limits?.TryGetValue("cpu", out value));
377377
Assert.True(value == "1");
378378
Assert.True(template.Container.Resources?.Limits?.TryGetValue("nvidia.com/gpu", out value));
379379
Assert.True(value == "1");

tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
340340
Type = "argo",
341341
Description = "Invalid Key Argo Task",
342342
Args = {
343-
{ "invalid", "key" },
343+
{ "invalid_key", "value" },
344344
{ "workflow_template_name" ,"spot"},
345345
{ "cpu", "1" },
346346
{ "memory_gb", "1" },
@@ -436,7 +436,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
436436
var invalidSourceName = "Data origin invalid_origin does not exists. Please review sources configuration management.";
437437
Assert.Contains(invalidSourceName, errors);
438438

439-
var invalidArgoKey = $"Task: 'invalid-key-argo-task' args has invalid keys. Please only specify keys from the following list: workflow_template_name, priority, cpu, memory_gb, gpu_required.";
439+
var invalidArgoKey = $"Task: 'invalid-key-argo-task' args has invalid keys: invalid_key. Please only specify keys from the following list: workflow_template_name, priority, cpu, memory_gb, gpu_required.";
440440
Assert.Contains(invalidArgoKey, errors);
441441
}
442442

0 commit comments

Comments
 (0)