Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
99160dd0
Commit
99160dd0
authored
2 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Check that artifact IDs are UUIDs in recipes
parent
6e916183
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1902
Vore Ponos server-side code
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ponos/recipe.py
+5
-0
5 additions, 0 deletions
ponos/recipe.py
tests/server/test_recipe.py
+42
-0
42 additions, 0 deletions
tests/server/test_recipe.py
with
47 additions
and
0 deletions
ponos/recipe.py
+
5
−
0
View file @
99160dd0
import
re
from
collections
import
namedtuple
from
uuid
import
UUID
import
yaml
from
django.core.validators
import
URLValidator
...
...
@@ -56,6 +57,10 @@ def validate_task(task, top_env):
if
"
artifact
"
in
task
:
assert
isinstance
(
task
[
"
artifact
"
],
str
),
"
Task artifact should be a string
"
try
:
UUID
(
task
[
"
artifact
"
])
except
(
TypeError
,
ValueError
):
raise
AssertionError
(
"
Task artifact should be a valid UUID string
"
)
if
"
requires_gpu
"
in
task
:
assert
isinstance
(
...
...
This diff is collapsed.
Click to expand it.
tests/server/test_recipe.py
0 → 100644
+
42
−
0
View file @
99160dd0
from
textwrap
import
dedent
from
django.test
import
TestCase
from
ponos.recipe
import
parse_recipe
# List of (broken recipe, expected AssertionError message) tuples
ERROR_CASES
=
[
(
"
[]
"
,
"
Recipe should be a dict
"
),
(
"
tasks: {}
"
,
"
No tasks
"
),
(
"
tasks: [{image: lol}]
"
,
"
Tasks should be a dict
"
),
(
"
tasks: {a: {},
''
: {}}
"
,
"
Tasks should have non-blank slugs
"
),
(
"
tasks: {a: []}
"
,
"
Task should be a dict
"
),
(
"
tasks: {a: {}}
"
,
"
Missing image
"
),
(
"""
tasks:
lol:
image: blah
artifact: 42
"""
,
"
Task artifact should be a string
"
,
),
(
"""
tasks:
lol:
image: blah
artifact: philosophers_stone
"""
,
"
Task artifact should be a valid UUID string
"
,
),
]
class
TestRecipe
(
TestCase
):
def
test_recipe_errors
(
self
):
for
recipe
,
expected_message
in
ERROR_CASES
:
with
self
.
subTest
(
recipe
=
recipe
),
self
.
assertRaisesMessage
(
AssertionError
,
expected_message
):
parse_recipe
(
dedent
(
recipe
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment