Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
41b5fd92
Commit
41b5fd92
authored
3 years ago
by
Janet Goldstein
Browse files
Options
Downloads
Patches
Plain Diff
WS-651: workflow request ID should be in message subject
parent
a5a1094b
No related branches found
No related tags found
1 merge request
!505
WS-651: catches and saves RH CARTA event
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
shared/workspaces/test/test_capability_service.py
+47
-1
47 additions, 1 deletion
shared/workspaces/test/test_capability_service.py
shared/workspaces/workspaces/capability/services/capability_service.py
+20
-0
20 additions, 0 deletions
...aces/workspaces/capability/services/capability_service.py
with
67 additions
and
1 deletion
shared/workspaces/test/test_capability_service.py
+
47
−
1
View file @
41b5fd92
"""
Unit tests for Capability Service
"""
from
unittest.mock
import
patch
# pylint: disable=C0301, E0401, R0201
import
pytest
from
workspaces.capability.schema
import
CapabilityExecution
...
...
@@ -11,7 +15,9 @@ pytest_plugins = ["testing.utils.conftest"]
@pytest.mark.usefixtures
(
"
mock_capability_service
"
)
class
TestCapabilityService
:
@pytest.mark.skip
(
"
Broken due to queue/messenger rework
"
)
"""
Tests for CapabilityService methods
"""
@pytest.mark.skip
(
"
Broken due to queue/messenger rework. Does work in local `make test`
"
)
def
test_on_ingestion_complete
(
self
,
mock_capability_service
:
CapabilityService
,
...
...
@@ -35,3 +41,43 @@ class TestCapabilityService:
assert
mock_capability_info
.
save_entity
.
call_count
==
save_entity_old_call_count
+
1
(
request
,)
=
mock_capability_info
.
save_entity
.
call_args
.
args
assert
request
.
ingested
is
True
@pytest.mark.skip
(
"
As above, broken due to queue/messenger rework? Succeeds locally; fails on CI
"
)
def
test_on_carta_ready
(
self
,
mock_capability_service
:
CapabilityService
,
mock_capability_info
:
CapabilityInfo
,
mock_capability_execution
:
CapabilityExecution
,
):
"""
Are we catching the
"
carta-ready
"
message and saving the metadata
to the capability request version?
:param mock_capability_service: stand-in for capability service
:param mock_capability_info: stand-in for capability info
:param mock_capability_execution: stand-in for capability execution
:return:
"""
wf_request_id
=
-
1
carta_url
=
"
decartes_image_carta_url
"
fake_carta_ready_msg
=
{
"
service
"
:
"
capability
"
,
"
routing_key
"
:
"
capability
"
,
"
carta_url
"
:
carta_url
,
"
subject
"
:
{
"
workflow_request_id
"
:
wf_request_id
},
"
type
"
:
"
carta-ready
"
,
}
save_entity_old_call_count
=
mock_capability_info
.
save_entity
.
call_count
with
patch
(
"
workspaces.capability.services.capability_info.CapabilityInfo.lookup_execution_by_workflow_request_id
"
,
return_value
=
mock_capability_execution
,
):
mock_capability_service
.
on_carta_ready
(
**
fake_carta_ready_msg
)
assert
mock_capability_info
.
save_entity
.
call_count
==
save_entity_old_call_count
+
1
(
request_version
,)
=
mock_capability_info
.
save_entity
.
call_args
.
args
assert
request_version
.
version_number
>
0
assert
request_version
.
workflow_metadata
[
"
carta_url
"
]
==
carta_url
This diff is collapsed.
Click to expand it.
shared/workspaces/workspaces/capability/services/capability_service.py
+
20
−
0
View file @
41b5fd92
import
logging
from
typing
import
Dict
,
List
# pylint: disable=E0401, R0903, W1203
import
transaction
from
messaging.messenger
import
MessageSender
...
...
@@ -149,6 +151,24 @@ class CapabilityService(CapabilityServiceIF):
request
.
ingested
=
True
self
.
capability_info
.
save_entity
(
request
)
@on_message
(
type
=
"
carta-ready
"
)
def
on_carta_ready
(
self
,
**
message
:
Dict
[
str
,
str
]):
"""
Catch the RH-flavored event and save it to the capability request version metadata
:param message: Ingestion-complete message
:return:
"""
logger
.
info
(
f
"
RECEIVED CARTA READY MESSAGE:
{
message
}
"
)
wf_request_id
=
int
(
message
[
"
subject
"
][
"
workflow_request_id
"
])
execution
=
self
.
capability_info
.
lookup_execution_by_workflow_request_id
(
wf_request_id
)
request_version
=
execution
.
version
request_version
.
workflow_metadata
=
{
"
carta_url
"
:
message
[
"
carta_url
"
]}
self
.
capability_info
.
save_entity
(
request_version
)
class
CapabilityLauncher
:
"""
...
...
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