1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

example & example validation cleanup

This commit is contained in:
checktheroads
2020-03-21 15:00:37 -07:00
parent 4b5e37986d
commit cf6958e469
6 changed files with 89 additions and 52 deletions

View File

@ -12,7 +12,7 @@ function isort_all () {
} }
function validate_examples () { function validate_examples () {
python3 .tests/validate_examples.py python3 ./validate_examples.py
if [[ ! $? == 0 ]]; then if [[ ! $? == 0 ]]; then
exit 1 exit 1
fi fi

View File

@ -35,7 +35,7 @@ class OpenGraph(HyperglassModel):
supported_extensions = (".jpg", ".jpeg", ".png") supported_extensions = (".jpg", ".jpeg", ".png")
if ( if (
values["image"] is not None values["image"] is not None
and values["image"].suffix not in supported_extensions and Path(values["image"]).suffix not in supported_extensions
): ):
raise ValueError( raise ValueError(
"OpenGraph image must be one of {e}".format( "OpenGraph image must be one of {e}".format(

View File

@ -204,6 +204,7 @@ class DnsOverHttps(HyperglassLevel3):
"""Validation model for DNS over HTTPS resolution.""" """Validation model for DNS over HTTPS resolution."""
name: constr(regex="|".join(DNS_OVER_HTTPS.keys())) = "cloudflare" name: constr(regex="|".join(DNS_OVER_HTTPS.keys())) = "cloudflare"
url: StrictStr = ""
@root_validator @root_validator
def validate_dns(cls, values): def validate_dns(cls, values):

View File

@ -123,4 +123,4 @@
# bgp_community: show route protocol bgp table {vrf} community {target} # bgp_community: show route protocol bgp table {vrf} community {target}
# bgp_route: show route protocol bgp table {vrf} {target} detail # bgp_route: show route protocol bgp table {vrf} {target} detail
# ping: ping inet6 routing-instance {vrf} {target} count 5 source {source} # ping: ping inet6 routing-instance {vrf} {target} count 5 source {source}
# traceroute: traceroute inet6 routing-instance {vrf} {target} wait 1 source {source} # traceroute: traceroute inet6 routing-instance {vrf} {target} wait 1 source {source}

View File

@ -6,14 +6,13 @@
# show_text: true # show_text: true
# timeout: 120 # timeout: 120
# cors_origins: [] # cors_origins: []
# debug: false # debug: true
# developer_mode: false # developer_mode: false
# docs: # docs:
# base_url: https://lg.example.net # base_url: https://lg.example.net
# description: '' # description: ""
# devices: # devices:
# description: List of all devices/locations with associated identifiers, display # description: List of all devices/locations with associated identifiers, display names, networks, & VRFs.
# names, networks, & VRFs.
# summary: Devices List # summary: Devices List
# title: Devices # title: Devices
# enable: true # enable: true
@ -27,28 +26,28 @@
# description: Request a query response per-location. # description: Request a query response per-location.
# summary: Query the Looking Glass # summary: Query the Looking Glass
# title: Submit Query # title: Submit Query
# title: '{site_title} API Documentation' # title: "{site_title} API Documentation"
# uri: /api/docs # uri: /api/docs
# listen_address: localhost # listen_address: 0.0.0.0
# listen_port: 8001 # listen_port: 8001
# log_file: /tmp/hyperglass_20202919-172921.log # log_file: /tmp/hyperglass_20204821-134836.log
# messages: # messages:
# acl_denied: '{target} is a member of {denied_network}, which is not allowed.' # acl_denied: "{target} is a member of {denied_network}, which is not allowed."
# acl_not_allowed: '{target} is not allowed.' # acl_not_allowed: "{target} is not allowed."
# authentication_error: Authentication error occurred. # authentication_error: Authentication error occurred.
# connection_error: 'Error connecting to {device_name}: {error}' # connection_error: "Error connecting to {device_name}: {error}"
# feature_not_enabled: '{feature} is not enabled for {device_name}.' # feature_not_enabled: "{feature} is not enabled for {device_name}."
# general: Something went wrong. # general: Something went wrong.
# invalid_field: '{input} is an invalid {field}.' # invalid_field: "{input} is an invalid {field}."
# invalid_input: '{target} is not a valid {query_type} target.' # invalid_input: "{target} is not a valid {query_type} target."
# no_input: '{field} must be specified.' # no_input: "{field} must be specified."
# no_output: No output. # no_output: No output.
# no_response: No response. # no_response: No response.
# request_timeout: Request timed out. # request_timeout: Request timed out.
# vrf_not_associated: VRF {vrf_name} is not associated with {device_name}. # vrf_not_associated: VRF {vrf_name} is not associated with {device_name}.
# vrf_not_found: VRF {vrf_name} is not defined. # vrf_not_found: VRF {vrf_name} is not defined.
# org_name: Beloved Hyperglass User # org_name: Beloved Hyperglass User
# primary_asn: '65001' # primary_asn: "65001"
# queries: # queries:
# bgp_aspath: # bgp_aspath:
# display_name: BGP AS Path # display_name: BGP AS Path
@ -76,27 +75,27 @@
# request_timeout: 30 # request_timeout: 30
# site_description: Beloved Hyperglass User Network Looking Glass # site_description: Beloved Hyperglass User Network Looking Glass
# site_keywords: # site_keywords:
# - hyperglass # - hyperglass
# - looking glass # - looking glass
# - lg # - lg
# - peer # - peer
# - peering # - peering
# - ipv4 # - ipv4
# - ipv6 # - ipv6
# - transit # - transit
# - community # - community
# - communities # - communities
# - bgp # - bgp
# - routing # - routing
# - network # - network
# - isp # - isp
# site_title: hyperglass # site_title: hyperglass
# web: # web:
# credit: # credit:
# enable: true # enable: true
# dns_provider: # dns_provider:
# name: cloudflare # name: google
# url: https://cloudflare-dns.com/dns-query # url: https://dns.google/resolve
# external_link: # external_link:
# enable: true # enable: true
# title: PeeringDB # title: PeeringDB
@ -131,24 +130,24 @@
# title_mode: logo_only # title_mode: logo_only
# theme: # theme:
# colors: # colors:
# black: '#262626' # black: "#262626"
# blue: '#314cb6' # blue: "#314cb6"
# cyan: '#118ab2' # cyan: "#118ab2"
# danger: '#d84b4b' # danger: "#d84b4b"
# error: '#ff6b35' # error: "#ff6b35"
# gray: '#c1c7cc' # gray: "#c1c7cc"
# green: '#35b246' # green: "#35b246"
# orange: '#ff6b35' # orange: "#ff6b35"
# pink: '#f2607d' # pink: "#f2607d"
# primary: '#118ab2' # primary: "#118ab2"
# purple: '#8d30b5' # purple: "#8d30b5"
# red: '#d84b4b' # red: "#d84b4b"
# secondary: '#314cb6' # secondary: "#314cb6"
# success: '#35b246' # success: "#35b246"
# teal: '#35b299' # teal: "#35b299"
# warning: '#edae49' # warning: "#edae49"
# white: '#f7f7f7' # white: "#f7f7f7"
# yellow: '#edae49' # yellow: "#edae49"
# fonts: # fonts:
# body: Nunito # body: Nunito
# mono: Fira Code # mono: Fira Code

View File

@ -1,5 +1,6 @@
"""Validate example files.""" """Validate example files."""
# Standard Library # Standard Library
import re
import sys import sys
from pathlib import Path from pathlib import Path
@ -7,6 +8,7 @@ from pathlib import Path
import yaml import yaml
# Project # Project
from hyperglass.util import set_app_path
from hyperglass.configuration.models.params import Params from hyperglass.configuration.models.params import Params
from hyperglass.configuration.models.routers import Routers from hyperglass.configuration.models.routers import Routers
from hyperglass.configuration.models.commands import Commands from hyperglass.configuration.models.commands import Commands
@ -18,6 +20,36 @@ COMMANDS = EXAMPLES / "commands.yaml"
MAIN = EXAMPLES / "hyperglass.yaml" MAIN = EXAMPLES / "hyperglass.yaml"
def _uncomment_files():
"""Uncomment out files."""
for file in (MAIN, COMMANDS):
output = []
with file.open("r") as f:
for line in f.readlines():
if re.match(r"^(#\s+[a-z0-9]+)|(#\s+\-\s.*$)", line):
output.append(re.sub(r"^(#\s)", "", line))
else:
output.append(line)
with file.open("w") as f:
f.write("".join(output))
return True
def _comment_optional_files():
"""Comment out files."""
for file in (MAIN, COMMANDS):
output = []
with file.open("r") as f:
for line in f.readlines():
if not re.match(r"^(#\s+[A-Za-z0-9])|(^\-{3})", line):
output.append("# " + line)
else:
output.append(line)
with file.open("w") as f:
f.write("".join(output))
return True
def _validate_devices(): def _validate_devices():
with DEVICES.open() as raw: with DEVICES.open() as raw:
devices_dict = yaml.safe_load(raw.read()) or {} devices_dict = yaml.safe_load(raw.read()) or {}
@ -44,12 +76,14 @@ def _validate_main():
try: try:
Params(**main_dict) Params(**main_dict)
except Exception as e: except Exception as e:
raise
raise ValueError(str(e)) raise ValueError(str(e))
return True return True
def validate_all(): def validate_all():
"""Validate all example configs against configuration models.""" """Validate all example configs against configuration models."""
_uncomment_files()
for validator in (_validate_main, _validate_commands, _validate_devices): for validator in (_validate_main, _validate_commands, _validate_devices):
try: try:
validator() validator()
@ -59,6 +93,7 @@ def validate_all():
if __name__ == "__main__": if __name__ == "__main__":
set_app_path()
try: try:
all_passed = validate_all() all_passed = validate_all()
message = "All tests passed" message = "All tests passed"
@ -66,5 +101,7 @@ if __name__ == "__main__":
except RuntimeError as e: except RuntimeError as e:
message = str(e) message = str(e)
status = 1 status = 1
if status == 0:
_comment_optional_files()
print(message) print(message)
sys.exit(status) sys.exit(status)