Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
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
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
45dd13f1
Commit
45dd13f1
authored
5 months ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Check uniqueness of GS, GA and VC ids against active subscriptions.
parent
899a73b6
No related branches found
No related tags found
1 merge request
!369
Check uniqueness of GS, GA and VC ids against active subscriptions.
Pipeline
#92130
passed
5 months ago
Stage: tox
Stage: documentation
Stage: sonarqube
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/services/subscriptions.py
+8
-3
8 additions, 3 deletions
gso/services/subscriptions.py
test/workflows/edge_port/test_create_edge_port.py
+45
-0
45 additions, 0 deletions
test/workflows/edge_port/test_create_edge_port.py
with
53 additions
and
3 deletions
gso/services/subscriptions.py
+
8
−
3
View file @
45dd13f1
...
@@ -388,7 +388,7 @@ def get_all_active_sites() -> list[dict[str, Any]]:
...
@@ -388,7 +388,7 @@ def get_all_active_sites() -> list[dict[str, Any]]:
def
is_resource_type_value_unique
(
resource_type
:
str
,
value
:
str
)
->
bool
:
def
is_resource_type_value_unique
(
resource_type
:
str
,
value
:
str
)
->
bool
:
"""
Check if the given value for the specified resource type is unique in the database.
"""
Check if the given value for the specified resource type is unique in the database
for active subscriptions
.
This function verifies if the specified value for the given resource type is not already in the core database.
This function verifies if the specified value for the given resource type is not already in the core database.
...
@@ -400,8 +400,13 @@ def is_resource_type_value_unique(resource_type: str, value: str) -> bool:
...
@@ -400,8 +400,13 @@ def is_resource_type_value_unique(resource_type: str, value: str) -> bool:
:rtype: bool
:rtype: bool
"""
"""
exists
=
(
exists
=
(
ResourceTypeTable
.
query
.
join
(
SubscriptionInstanceValueTable
)
SubscriptionTable
.
query
.
join
(
ProductTable
)
.
filter
(
ResourceTypeTable
.
resource_type
==
resource_type
,
SubscriptionInstanceValueTable
.
value
==
value
)
.
join
(
SubscriptionInstanceTable
)
.
join
(
SubscriptionInstanceValueTable
)
.
join
(
ResourceTypeTable
)
.
filter
(
SubscriptionInstanceValueTable
.
value
==
value
)
.
filter
(
ResourceTypeTable
.
resource_type
==
resource_type
)
.
filter
(
SubscriptionTable
.
status
==
SubscriptionLifecycle
.
ACTIVE
)
.
scalar
()
.
scalar
()
)
)
return
exists
is
None
return
exists
is
None
...
...
This diff is collapsed.
Click to expand it.
test/workflows/edge_port/test_create_edge_port.py
+
45
−
0
View file @
45dd13f1
from
unittest.mock
import
patch
from
unittest.mock
import
patch
import
pytest
import
pytest
from
orchestrator.db
import
db
from
orchestrator.types
import
SubscriptionLifecycle
from
pydantic_forms.exceptions
import
FormValidationError
from
pydantic_forms.exceptions
import
FormValidationError
from
gso.products
import
ProductName
from
gso.products
import
ProductName
...
@@ -159,3 +161,46 @@ def test_edge_port_creation_with_invalid_input(
...
@@ -159,3 +161,46 @@ def test_edge_port_creation_with_invalid_input(
error
=
error
.
value
.
errors
[
0
]
error
=
error
.
value
.
errors
[
0
]
assert
error
[
"
msg
"
]
==
"
Number of members must be 1 if LACP is disabled.
"
assert
error
[
"
msg
"
]
==
"
Number of members must be 1 if LACP is disabled.
"
assert
error
[
"
loc
"
][
0
]
==
"
__root__
"
assert
error
[
"
loc
"
][
0
]
==
"
__root__
"
@pytest.mark.workflow
()
@patch
(
"
gso.services.lso_client._send_request
"
)
def
test_edge_port_creation_with_existing_ga_id
(
mock_execute_playbook
,
input_form_wizard_data
,
faker
,
_netbox_client_mock
,
# noqa: PT019
test_client
,
edge_port_subscription_factory
,
):
subscription
=
edge_port_subscription_factory
(
ga_id
=
"
GA-12345
"
)
product_id
=
get_product_id_by_name
(
ProductName
.
EDGE_PORT
)
initial_data
=
[{
"
product
"
:
product_id
},
*
input_form_wizard_data
]
with
pytest
.
raises
(
FormValidationError
)
as
error
:
run_workflow
(
"
create_edge_port
"
,
initial_data
)
error
=
error
.
value
.
errors
[
0
]
assert
error
[
"
msg
"
]
==
"
ga_id must be unique, GA-12345 is already in use.
"
assert
error
[
"
loc
"
][
0
]
==
"
ga_id
"
# Terminate the subscription and check if the workflow can be run successfully
subscription
=
EdgePort
.
from_subscription
(
subscription
.
subscription_id
)
subscription
.
status
=
SubscriptionLifecycle
.
TERMINATED
subscription
.
save
()
db
.
session
.
commit
()
result
,
process_stat
,
step_log
=
run_workflow
(
"
create_edge_port
"
,
initial_data
)
for
_
in
range
(
3
):
result
,
step_log
=
assert_lso_interaction_success
(
result
,
process_stat
,
step_log
)
result
,
step_log
=
assert_stop_moodi
(
result
,
process_stat
,
step_log
)
assert_complete
(
result
)
state
=
extract_state
(
result
)
subscription_id
=
state
[
"
subscription_id
"
]
subscription
=
EdgePort
.
from_subscription
(
subscription_id
)
assert
subscription
.
status
==
"
active
"
assert
subscription
.
edge_port
.
ga_id
.
startswith
(
"
GA-12345
"
)
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