This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for normalization and Literal casting
- Loading branch information
1 parent
88a53e1
commit 6b4bc42
Showing
12 changed files
with
256 additions
and
165 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
7 changes: 7 additions & 0 deletions
7
catalystwan/models/configuration/feature_profile/sdwan/system/literals.py
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,7 @@ | ||
from typing import Literal | ||
|
||
Priority = Literal["information", "debugging", "notice", "warn", "error", "critical", "alert", "emergency"] | ||
Version = Literal["TLSv1.1", "TLSv1.2"] | ||
AuthType = Literal["Server", "Mutual"] | ||
|
||
SYSTEM_LITERALS = [Priority, Version, AuthType] |
52 changes: 0 additions & 52 deletions
52
catalystwan/models/configuration/feature_profile/sdwan/system/logging.py
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
catalystwan/models/configuration/feature_profile/sdwan/system/logging_parcel.py
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,82 @@ | ||
from typing import List, Optional, Union | ||
|
||
from pydantic import AliasPath, BaseModel, ConfigDict, Field | ||
|
||
from catalystwan.api.configuration_groups.parcel import Default, Global, _ParcelBase, as_global | ||
from catalystwan.models.configuration.feature_profile.sdwan.system.literals import AuthType, Priority, Version | ||
from catalystwan.utils.pydantic_validators import ConvertBoolToStringModel | ||
|
||
|
||
class TlsProfile(ConvertBoolToStringModel): | ||
profile: str | ||
version: Optional[Version] = Field(default="TLSv1.1", json_schema_extra={"data_path": ["tls-version"]}) | ||
auth_type: AuthType = Field(json_schema_extra={"vmanage_key": "auth-type"}) | ||
ciphersuite_list: Optional[List] = Field( | ||
default=None, json_schema_extra={"data_path": ["ciphersuite"], "vmanage_key": "ciphersuite-list"} | ||
) | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
|
||
class Server(BaseModel): | ||
name: Global[str] | ||
vpn: Optional[Global[str]] = None | ||
source_interface: Optional[Global[str]] = Field( | ||
default=None, serialization_alias="sourceInterface", validation_alias="sourceInterface" | ||
) | ||
priority: Optional[Global[Priority]] = Field(default="information") | ||
enable_tls: Optional[Global[bool]] = Field( | ||
default=as_global(False), serialization_alias="tlsEnable", validation_alias="tlsEnable" | ||
) | ||
custom_profile: Optional[Global[bool]] = Field( | ||
default=as_global(False), | ||
serialization_alias="tlsPropertiesCustomProfile", | ||
validation_alias="tlsPropertiesCustomProfile", | ||
) | ||
profile_properties: Optional[Global[str]] = Field( | ||
default=None, serialization_alias="tlsPropertiesProfile", validation_alias="tlsPropertiesProfile" | ||
) | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
|
||
class Ipv6Server(BaseModel): | ||
name: Global[str] | ||
vpn: Optional[Global[str]] = None | ||
source_interface: Optional[Global[str]] = Field( | ||
default=None, serialization_alias="sourceInterface", validation_alias="sourceInterface" | ||
) | ||
priority: Optional[Global[Priority]] = Field(default="information") | ||
enable_tls: Optional[Global[bool]] = Field( | ||
default=as_global(False), serialization_alias="tlsEnable", validation_alias="tlsEnable" | ||
) | ||
custom_profile: Optional[Global[bool]] = Field( | ||
default=as_global(False), | ||
serialization_alias="tlsPropertiesCustomProfile", | ||
validation_alias="tlsPropertiesCustomProfile", | ||
) | ||
profile_properties: Optional[Global[str]] = Field( | ||
default=None, serialization_alias="tlsPropertiesProfile", validation_alias="tlsPropertiesProfile" | ||
) | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
|
||
class File(BaseModel): | ||
disk_file_size: Optional[Union[Global[int], Default[int]]] = Field( | ||
default=Default[int](value=10), serialization_alias="diskFileSize", validation_alias="diskFileSize" | ||
) | ||
disk_file_rotate: Optional[Union[Global[int], Default[int]]] = Field( | ||
default=Default[int](value=10), serialization_alias="diskFileRotate", validation_alias="diskFileRotate" | ||
) | ||
|
||
|
||
class Disk(BaseModel): | ||
disk_enable: Optional[Global[bool]] = Field( | ||
default=False, serialization_alias="diskEnable", validation_alias="diskEnable" | ||
) | ||
file: File | ||
|
||
|
||
class LoggingParcel(_ParcelBase): | ||
disk: Optional[Disk] = Field(default=None, validation_alias=AliasPath("data", "disk")) | ||
tls_profile: Optional[List[TlsProfile]] = Field(default=[], validation_alias=AliasPath("data", "tlsProfile")) | ||
server: Optional[List[Server]] = Field(default=[], validation_alias=AliasPath("data", "server")) | ||
ipv6_server: Optional[List[Ipv6Server]] = Field(default=[], validation_alias=AliasPath("data", "ipv6Server")) |
26 changes: 26 additions & 0 deletions
26
catalystwan/tests/config_migration/test_converter_chooser.py
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,26 @@ | ||
import unittest | ||
|
||
from parameterized import parameterized # type: ignore | ||
|
||
from catalystwan.exceptions import CatalystwanException | ||
from catalystwan.utils.config_migration.converters.feature_template import choose_parcel_converter | ||
from catalystwan.utils.config_migration.converters.feature_template.aaa import AAATemplateConverter | ||
from catalystwan.utils.config_migration.converters.feature_template.bfd import BFDTemplateConverter | ||
|
||
|
||
class TestParcelConverterChooser(unittest.TestCase): | ||
@parameterized.expand( | ||
[("cisco_aaa", AAATemplateConverter), ("cedge_aaa", AAATemplateConverter), ("cisco_bfd", BFDTemplateConverter)] | ||
) | ||
def test_choose_parcel_converter_returns_correct_converter_when_supported(self, template_type, expected): | ||
# Arrange, Act | ||
converter = choose_parcel_converter(template_type) | ||
# Assert | ||
self.assertEqual(converter, expected) | ||
|
||
def test_choose_parcel_converter_throws_exception_when_template_type_not_supported(self): | ||
# Arrange | ||
not_supported_type = "!@#$%^&*()" | ||
# Act, Assert | ||
with self.assertRaises(CatalystwanException, msg=f"Template type {not_supported_type} not supported"): | ||
choose_parcel_converter(not_supported_type) |
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
Oops, something went wrong.