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
b8c08435
Commit
b8c08435
authored
1 year ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Fixed site name validtor issues.
parent
9446a4c5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!97
Feature/nat 328 site names should be validated
Pipeline
#84396
failed
1 year ago
Stage: tox
Stage: documentation
Stage: sonarqube
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gso/utils/helpers.py
+2
-3
2 additions, 3 deletions
gso/utils/helpers.py
gso/workflows/tasks/import_site.py
+34
-0
34 additions, 0 deletions
gso/workflows/tasks/import_site.py
test/imports/test_imports.py
+0
-4
0 additions, 4 deletions
test/imports/test_imports.py
with
36 additions
and
7 deletions
gso/utils/helpers.py
+
2
−
3
View file @
b8c08435
...
...
@@ -187,10 +187,9 @@ def validate_site_name(site_name: str) -> str:
The site name must consist of three uppercase letters (A-Z) followed by an optional single digit (0-9).
"""
pattern
=
re
.
compile
(
r
"
^[A-Z]{3}[0-9]?$
"
)
if
pattern
.
match
(
site_name
):
return
site_name
else
:
if
not
pattern
.
match
(
site_name
):
raise
ValueError
(
"
Enter a valid site name. It must consist of three uppercase letters (A-Z) followed by an optional single
"
"
digit (0-9).
"
)
return
site_name
This diff is collapsed.
Click to expand it.
gso/workflows/tasks/import_site.py
+
34
−
0
View file @
b8c08435
...
...
@@ -5,12 +5,20 @@ 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
...
...
@@ -43,6 +51,32 @@ 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
+
0
−
4
View file @
b8c08435
...
...
@@ -295,7 +295,3 @@ def test_import_iptrunk_fails_on_side_a_and_b_members_mismatch(
assert
response
.
json
()
==
{
"
detail
"
:
[{
"
loc
"
:
[
"
body
"
,
"
__root__
"
],
"
msg
"
:
"
Mismatch between Side A and B members
"
,
"
type
"
:
"
value_error
"
}]
}
def
test_site_name_is_valid
():
site_model
=
SiteImportModel
(
site_name
=
"
123456
"
)
assert
site_model
is
not
None
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