Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
720137e7
Commit
720137e7
authored
2 years ago
by
ml bonhomme
Committed by
Erwan Rouchet
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
update self.config with default user_configuration values
parent
1da1bb24
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!172
update self.config with default user_configuration values
Pipeline
#79252
passed
2 years ago
Stage: test
Stage: build
Stage: release
Changes
3
Pipelines
8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex_worker/worker/base.py
+7
-0
7 additions, 0 deletions
arkindex_worker/worker/base.py
tests/conftest.py
+36
-1
36 additions, 1 deletion
tests/conftest.py
tests/test_base_worker.py
+13
-4
13 additions, 4 deletions
tests/test_base_worker.py
with
56 additions
and
5 deletions
arkindex_worker/worker/base.py
+
7
−
0
View file @
720137e7
...
...
@@ -170,6 +170,13 @@ class BaseWorker(object):
f
"
Loaded worker
{
worker_version
[
'
worker
'
][
'
name
'
]
}
revision
{
worker_version
[
'
revision
'
][
'
hash
'
][
0
:
7
]
}
from API
"
)
self
.
config
=
worker_version
[
"
configuration
"
][
"
configuration
"
]
if
"
user_configuration
"
in
worker_version
[
"
configuration
"
]:
# Add default values (if set) to user_configuration
for
key
,
value
in
worker_version
[
"
configuration
"
][
"
user_configuration
"
].
items
():
if
"
default
"
in
value
:
self
.
user_configuration
[
key
]
=
value
[
"
default
"
]
self
.
worker_details
=
worker_version
[
"
worker
"
]
required_secrets
=
worker_version
[
"
configuration
"
].
get
(
"
secrets
"
,
[])
elif
self
.
args
.
config
:
...
...
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
36
−
1
View file @
720137e7
...
...
@@ -101,7 +101,7 @@ def setup_api(responses, monkeypatch, cache_yaml):
@pytest.fixture
(
autouse
=
True
)
def
give_env_variable
(
monkeypatch
):
def
give_env_variable
(
request
,
monkeypatch
):
"""
Defines required environment variables
"""
monkeypatch
.
setenv
(
"
WORKER_VERSION_ID
"
,
"
12341234-1234-1234-1234-123412341234
"
)
monkeypatch
.
setenv
(
"
ARKINDEX_PROCESS_ID
"
,
"
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff
"
)
...
...
@@ -147,6 +147,41 @@ def mock_worker_version_api(responses):
)
@pytest.fixture
def
mock_worker_version_user_configuration_api
(
responses
):
"""
Provide a mock API response to get a worker configuration
that includes a `user_configuration`
"""
payload
=
{
"
worker
"
:
{
"
id
"
:
"
1234
"
,
"
name
"
:
"
Workerino
"
,
"
slug
"
:
"
workerino
"
},
"
revision
"
:
{
"
hash
"
:
"
1234lala-lalalalala-lala
"
},
"
configuration
"
:
{
"
configuration
"
:
{
"
param_1
"
:
"
/some/path/file.pth
"
,
"
param_2
"
:
12
},
"
user_configuration
"
:
{
"
param_3
"
:
{
"
title
"
:
"
A Third Parameter
"
,
"
type
"
:
"
string
"
,
"
default
"
:
"
Animula vagula blandula
"
,
},
"
param_4
"
:
{
"
title
"
:
"
Parameter The Fourth
"
,
"
type
"
:
"
int
"
},
"
param_5
"
:
{
"
title
"
:
"
Parameter 5 (Five)
"
,
"
type
"
:
"
bool
"
,
"
default
"
:
True
,
},
},
},
}
responses
.
add
(
responses
.
GET
,
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
status
=
200
,
body
=
json
.
dumps
(
payload
),
content_type
=
"
application/json
"
,
)
@pytest.fixture
def
mock_process_api
(
responses
):
"""
Provide a mock of the API response to get information on a process. Workers activity is enabled
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_base_worker.py
+
13
−
4
View file @
720137e7
...
...
@@ -160,11 +160,16 @@ def test_configure_worker_run(mocker, monkeypatch, responses, mock_config_api):
assert
worker
.
user_configuration
==
{
"
a
"
:
"
b
"
}
def
test_configure_worker_run_missing_worker_conf
(
mocker
,
monkeypatch
,
responses
,
mock_config_api
def
test_configure_user_configuration_defaults
(
mocker
,
monkeypatch
,
mock_worker_version_user_configuration_api
,
mock_user_api
,
mock_process_api
,
responses
,
):
worker
=
BaseWorker
()
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
]
)
mocker
.
patch
.
object
(
sys
,
"
argv
"
)
run_id
=
"
aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"
monkeypatch
.
setenv
(
"
ARKINDEX_WORKER_RUN_ID
"
,
run_id
)
responses
.
add
(
...
...
@@ -174,7 +179,11 @@ def test_configure_worker_run_missing_worker_conf(
)
worker
.
configure
()
assert
worker
.
user_configuration
==
{}
assert
worker
.
config
==
{
"
param_1
"
:
"
/some/path/file.pth
"
,
"
param_2
"
:
12
}
assert
worker
.
user_configuration
==
{
"
param_3
"
:
"
Animula vagula blandula
"
,
"
param_5
"
:
True
,
}
def
test_configure_worker_run_missing_conf
(
...
...
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