-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// service.proto | ||
// | ||
// Service and rpcs for infrastructure and bindings | ||
|
||
syntax = "proto3"; | ||
|
||
package service; | ||
|
||
import "infra.proto"; | ||
import "bind.proto"; | ||
|
||
message ValidationRequest { | ||
infra.Infrastructure infrastructure = 1; | ||
bind.Bindings bindingas = 2; | ||
} | ||
|
||
message ValidationError { | ||
oneof type { | ||
string optional = 1; | ||
string oneof = 2; | ||
string map = 3; | ||
string repeated = 4; | ||
string connection = 5; | ||
} | ||
} | ||
|
||
message ValidationResponse { | ||
repeated ValidationError errors = 1; | ||
} | ||
|
||
service Service { | ||
rpc Validate(ValidationRequest) returns (ValidationResponse); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
if __package__ is None or __package__ == "": | ||
from generated.service_pb2 import ValidationRequest, ValidationError, ValidationResponse | ||
else: | ||
from .generated.service_pb2 import ValidationRequest, ValidationError, ValidationResponse | ||
|
||
|
||
class Service: | ||
@staticmethod | ||
def Validate(request: ValidationRequest): | ||
"""Validate every connection in the Infrastructure. | ||
Every Device in Infrastructure.inventory.devices has connections which | ||
must have a valid number of pieces separated by a ".". | ||
Every connection in Infrastructure.connections must be composed of | ||
a valid number of pieces separated by a "." and the pieces must exist | ||
in the Infrastructure.inventory.devices and Infrastructure.inventory.links. | ||
The format of a Device connection is the following: | ||
"component_name.component_index.link_name.component_name.component_index" | ||
""" | ||
errors = [] | ||
for device_key, device in request.infrastructure.inventory.devices.items(): | ||
if device.HasField("name") is False: | ||
errors.append(ValidationError(optional=f"Device name field has not been set")) | ||
if device_key != device.name: | ||
errors.append( | ||
ValidationError( | ||
map=f"Device key '{device_key}' does not match Device.name '{device.name}'" | ||
) | ||
) | ||
for link_key, link in device.links.items(): | ||
if link_key != link.name: | ||
errors.append( | ||
ValidationError( | ||
map=f"Device '{device.name}' link key '{link_key}' does not match Link.name '{link.name}'" | ||
) | ||
) | ||
if link.bandwidth.WhichOneof("type") is None: | ||
errors.append(ValidationError(oneof="Device.links.bandwidth type must be set")) | ||
for connection in device.connections: | ||
try: | ||
src, src_idx, link, dst, dst_idx = connection.split(".") | ||
except ValueError: | ||
errors.append( | ||
ValidationError( | ||
connection=f"Component connection in device '{device.name}' is incorrectly formatted" | ||
) | ||
) | ||
return ValidationResponse(errors=errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
import pytest | ||
import os | ||
import sys | ||
|
||
sys.path.extend( | ||
[ | ||
os.path.join(os.path.dirname(__file__), ".."), | ||
os.path.join(os.path.dirname(__file__), "../generated"), | ||
] | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.