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
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
08e9f966
Commit
08e9f966
authored
1 year ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Improved site import endpoint.
parent
0e75e466
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!97
Feature/nat 328 site names should be validated
Pipeline
#84403
passed
1 year ago
Stage: tox
Stage: documentation
Stage: sonarqube
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gso/api/v1/imports.py
+34
-12
34 additions, 12 deletions
gso/api/v1/imports.py
gso/workflows/tasks/import_site.py
+0
-34
0 additions, 34 deletions
gso/workflows/tasks/import_site.py
test/imports/test_imports.py
+1
-1
1 addition, 1 deletion
test/imports/test_imports.py
with
35 additions
and
47 deletions
gso/api/v1/imports.py
+
34
−
12
View file @
08e9f966
...
...
@@ -6,16 +6,21 @@ from fastapi import Depends, HTTPException, status
from
fastapi.routing
import
APIRouter
from
orchestrator.security
import
opa_security_default
from
orchestrator.services
import
processes
from
orchestrator.services
import
subscriptions
as
wfo_subscriptions
from
pydantic
import
BaseModel
,
root_validator
,
validator
from
sqlalchemy.exc
import
MultipleResultsFoun
d
from
pydantic.fields
import
ModelFiel
d
from
gso.products.product_blocks.iptrunk
import
IptrunkType
,
PhyPortCapacity
from
gso.products.product_blocks.router
import
RouterRole
,
RouterVendor
from
gso.products.product_blocks.site
import
SiteTier
from
gso.services
import
subscriptions
from
gso.services.crm
import
CustomerNotFoundError
,
get_customer_by_name
from
gso.utils.helpers
import
LAGMember
from
gso.utils.helpers
import
(
LAGMember
,
validate_country_code
,
validate_ipv4_or_ipv6
,
validate_site_fields_is_unique
,
validate_site_name
,
)
router
=
APIRouter
(
prefix
=
"
/imports
"
,
tags
=
[
"
Imports
"
],
dependencies
=
[
Depends
(
opa_security_default
)])
...
...
@@ -38,6 +43,32 @@ class SiteImportModel(BaseModel):
site_ts_address
:
str
customer
:
str
@validator
(
"
site_ts_address
"
,
allow_reuse
=
True
)
def
validate_ts_address
(
cls
,
site_ts_address
:
str
)
->
str
:
validate_site_fields_is_unique
(
"
site_ts_address
"
,
site_ts_address
)
validate_ipv4_or_ipv6
(
site_ts_address
)
return
site_ts_address
@validator
(
"
site_country_code
"
,
allow_reuse
=
True
)
def
country_code_must_exist
(
cls
,
country_code
:
str
)
->
str
:
validate_country_code
(
country_code
)
return
country_code
@validator
(
"
site_internal_id
"
,
"
site_bgp_community_id
"
,
allow_reuse
=
True
)
def
validate_unique_fields
(
cls
,
value
:
str
,
field
:
ModelField
)
->
str
|
int
:
return
validate_site_fields_is_unique
(
field
.
name
,
value
)
@validator
(
"
site_name
"
,
allow_reuse
=
True
)
def
site_name_must_be_valid
(
cls
,
site_name
:
str
)
->
str
:
"""
Validate the site name.
The site name must consist of three uppercase letters (A-Z) followed
by an optional single digit (0-9).
"""
validate_site_fields_is_unique
(
"
site_name
"
,
site_name
)
validate_site_name
(
site_name
)
return
site_name
class
RouterImportModel
(
BaseModel
):
customer
:
str
...
...
@@ -151,15 +182,6 @@ def import_site(site: SiteImportModel) -> dict[str, Any]:
:raises HTTPException: If the site already exists or if there
'
s an error in the process.
"""
try
:
subscription
=
wfo_subscriptions
.
retrieve_subscription_by_subscription_instance_value
(
resource_type
=
"
site_name
"
,
value
=
site
.
site_name
,
sub_status
=
(
"
provisioning
"
,
"
active
"
)
)
if
subscription
:
raise
HTTPException
(
status_code
=
status
.
HTTP_409_CONFLICT
,
detail
=
"
Site already exists.
"
)
except
MultipleResultsFound
:
raise
HTTPException
(
status_code
=
status
.
HTTP_409_CONFLICT
,
detail
=
"
Multiple subscriptions found.
"
)
pid
=
_start_process
(
"
import_site
"
,
site
.
dict
())
return
{
"
detail
"
:
"
Site added successfully.
"
,
"
pid
"
:
pid
}
...
...
This diff is collapsed.
Click to expand it.
gso/workflows/tasks/import_site.py
+
0
−
34
View file @
08e9f966
...
...
@@ -5,20 +5,12 @@ from orchestrator.targets import Target
from
orchestrator.types
import
FormGenerator
,
State
,
SubscriptionLifecycle
from
orchestrator.workflow
import
StepList
,
done
,
init
,
step
,
workflow
from
orchestrator.workflows.steps
import
resync
,
set_status
,
store_process_subscription
from
pydantic
import
validator
from
pydantic.fields
import
ModelField
from
gso.products
import
ProductType
from
gso.products.product_blocks.site
import
SiteTier
from
gso.products.product_types.site
import
SiteInactive
from
gso.services
import
subscriptions
from
gso.services.crm
import
get_customer_by_name
from
gso.utils.helpers
import
(
validate_country_code
,
validate_ipv4_or_ipv6
,
validate_site_fields_is_unique
,
validate_site_name
,
)
from
gso.workflows.site.create_site
import
initialize_subscription
...
...
@@ -51,32 +43,6 @@ def generate_initial_input_form() -> FormGenerator:
site_ts_address
:
str
customer
:
str
@validator
(
"
site_ts_address
"
,
allow_reuse
=
True
)
def
validate_ts_address
(
cls
,
site_ts_address
:
str
)
->
str
:
validate_site_fields_is_unique
(
"
site_ts_address
"
,
site_ts_address
)
validate_ipv4_or_ipv6
(
site_ts_address
)
return
site_ts_address
@validator
(
"
site_country_code
"
,
allow_reuse
=
True
)
def
country_code_must_exist
(
cls
,
country_code
:
str
)
->
str
:
validate_country_code
(
country_code
)
return
country_code
@validator
(
"
site_internal_id
"
,
"
site_bgp_community_id
"
,
allow_reuse
=
True
)
def
validate_unique_fields
(
cls
,
value
:
str
,
field
:
ModelField
)
->
str
|
int
:
return
validate_site_fields_is_unique
(
field
.
name
,
value
)
@validator
(
"
site_name
"
,
allow_reuse
=
True
)
def
site_name_must_be_valid
(
cls
,
site_name
:
str
)
->
str
:
"""
Validate the site name.
The site name must consist of three uppercase letters (A-Z) followed
by an optional single digit (0-9).
"""
validate_site_fields_is_unique
(
"
site_name
"
,
site_name
)
validate_site_name
(
site_name
)
return
site_name
user_input
=
yield
ImportSite
return
user_input
.
dict
()
...
...
This diff is collapsed.
Click to expand it.
test/imports/test_imports.py
+
1
−
1
View file @
08e9f966
...
...
@@ -132,7 +132,7 @@ def test_import_site_endpoint_with_existing_site(test_client, site_data):
assert
response
.
status_code
==
201
response
=
test_client
.
post
(
SITE_IMPORT_ENDPOINT
,
json
=
site_data
)
assert
response
.
status_code
==
4
09
assert
response
.
status_code
==
4
22
assert
SubscriptionTable
.
query
.
count
()
==
1
...
...
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