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
dd1da406
Commit
dd1da406
authored
1 year ago
by
Erwan Rouchet
Committed by
Bastien Abadie
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Update existing GitRefs in CreateDockerWorkerVersion
parent
b10d78e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2156
Update existing GitRefs in CreateDockerWorkerVersion
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/serializers/workers.py
+11
-0
11 additions, 0 deletions
arkindex/process/serializers/workers.py
arkindex/process/tests/test_docker_worker_version.py
+95
-1
95 additions, 1 deletion
arkindex/process/tests/test_docker_worker_version.py
with
106 additions
and
1 deletion
arkindex/process/serializers/workers.py
+
11
−
0
View file @
dd1da406
...
...
@@ -579,6 +579,17 @@ class DockerWorkerVersionSerializer(serializers.ModelSerializer):
GitRef
(
revision
=
revision
,
repository
=
repository
,
type
=
ref_type
,
name
=
ref_name
)
for
ref_type
,
ref_name
in
new_git_refs
),
# When a GitRef already exists on the repo, update its revision to the current one.
# If the revision already exists, this could mean that an earlier revision
# could get a ref that it shouldn't have, for example when retrying a CI pipeline.
update_conflicts
=
True
,
update_fields
=
[
'
revision
'
],
# With PostgreSQL, Django also requires specifying the fields
# of the unique constraint that will cause a conflict.
# Note that GitRefs are unique per name and repository, but not by type.
# This means that a branch and a tag cannot have the same name,
# or one of the two will be skipped without any error.
unique_fields
=
[
'
repository
'
,
'
name
'
],
)
# Use a specific worker type in case a worker must be created
...
...
This diff is collapsed.
Click to expand it.
arkindex/process/tests/test_docker_worker_version.py
+
95
−
1
View file @
dd1da406
...
...
@@ -265,7 +265,101 @@ class TestDockerWorkerVersion(FixtureAPITestCase):
}
})
# Existing repository memberships are not updated
self
.
assertListEqual
(
list
(
self
.
repo
.
memberships
.
values_list
(
"
level
"
,
"
level
"
)),
[])
self
.
assertFalse
(
self
.
repo
.
memberships
.
exists
())
def
test_create_update_git_ref
(
self
):
"""
Existing GitRefs on the repository on a different revision
are updated to the new revision
"""
self
.
assertFalse
(
self
.
repo
.
refs
.
exists
())
branch_ref
=
self
.
repo
.
refs
.
create
(
revision
=
self
.
rev
,
type
=
GitRefType
.
Branch
,
name
=
'
master
'
,
)
tag_ref
=
self
.
repo
.
refs
.
create
(
revision
=
self
.
rev
,
type
=
GitRefType
.
Tag
,
name
=
'
2.0
'
,
)
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
19
):
response
=
self
.
client
.
post
(
reverse
(
'
api:version-from-docker
'
),
data
=
{
'
configuration
'
:
{
'
test
'
:
'
A
'
},
'
docker_image_iid
'
:
'
a_docker_image
'
,
'
repository_url
'
:
self
.
repo
.
url
,
'
revision_hash
'
:
'
new_revision_hash
'
,
'
worker_slug
'
:
self
.
worker
.
slug
,
'
revision_message
'
:
'
Bruce was very clever
'
,
'
revision_author
'
:
'
Iwan Roberts
'
,
'
revision_references
'
:
[
{
'
type
'
:
'
branch
'
,
'
name
'
:
'
master
'
},
{
'
type
'
:
'
tag
'
,
'
name
'
:
'
2.0
'
},
],
'
gpu_usage
'
:
WorkerVersionGPUUsage
.
Required
.
value
,
'
model_usage
'
:
True
,
},
format
=
'
json
'
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
new_revision
=
self
.
repo
.
revisions
.
get
(
hash
=
'
new_revision_hash
'
)
branch_ref
.
refresh_from_db
()
tag_ref
.
refresh_from_db
()
self
.
assertEqual
(
branch_ref
.
revision
,
new_revision
)
self
.
assertEqual
(
tag_ref
.
revision
,
new_revision
)
# No new refs were created
self
.
assertEqual
(
self
.
repo
.
refs
.
count
(),
2
)
data
=
response
.
json
()
# GitRefs are not sorted in the API output, so we have to assert separately
refs_data
=
data
[
'
revision
'
].
pop
(
'
refs
'
)
self
.
assertCountEqual
(
refs_data
,
[
{
'
id
'
:
str
(
tag_ref
.
id
),
'
name
'
:
'
2.0
'
,
'
type
'
:
'
tag
'
,
},
{
'
id
'
:
str
(
branch_ref
.
id
),
'
name
'
:
'
master
'
,
'
type
'
:
'
branch
'
,
},
])
new_version
=
new_revision
.
versions
.
get
()
self
.
assertDictEqual
(
response
.
json
(),
{
'
id
'
:
str
(
new_version
.
id
),
'
configuration
'
:
{
'
test
'
:
'
A
'
},
'
docker_image
'
:
None
,
'
docker_image_iid
'
:
'
a_docker_image
'
,
'
docker_image_name
'
:
new_version
.
docker_image_name
,
'
gpu_usage
'
:
WorkerVersionGPUUsage
.
Required
.
value
,
'
model_usage
'
:
True
,
'
revision
'
:
{
'
id
'
:
str
(
new_revision
.
id
),
'
author
'
:
'
Iwan Roberts
'
,
'
commit_url
'
:
'
http://my_repo.fake/workers/worker/commit/new_revision_hash
'
,
'
created
'
:
new_revision
.
created
.
isoformat
().
replace
(
'
+00:00
'
,
'
Z
'
),
'
hash
'
:
'
new_revision_hash
'
,
'
message
'
:
'
Bruce was very clever
'
,
},
'
state
'
:
'
available
'
,
'
worker
'
:
{
'
id
'
:
str
(
self
.
worker
.
id
),
'
name
'
:
'
Recognizer
'
,
'
slug
'
:
'
reco
'
,
'
type
'
:
'
recognizer
'
}
})
# Existing repository memberships are not updated
self
.
assertFalse
(
self
.
repo
.
memberships
.
exists
())
def
test_create_add_git_ref
(
self
):
"""
...
...
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