Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Dev/switchport (#15)
Browse files Browse the repository at this point in the history
* Add tests. Fix model

* Add unit test

* Add converter
  • Loading branch information
jpkrajewski authored Apr 11, 2024
1 parent ace12ed commit 2526697
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
Ospfv3IPv6Parcel,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.route_policy import RoutePolicyParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.switchport import (
ControlDirection,
Duplex,
HostMode,
PortControl,
Speed,
StaticMacAddress,
SwitchportInterface,
SwitchportMode,
SwitchportParcel,
)


class TestServiceFeatureProfileModels(TestFeatureProfileModels):
Expand Down Expand Up @@ -168,6 +179,56 @@ def test_when_default_values_acl_ipv4_expect_successful_post(self):
# Assert
assert parcel_id

def test_when_default_values_switchport_expect_successful_post(self):
# Arrange
switchport_parcel = SwitchportParcel(
parcel_name="TestSwitchportParcel",
parcel_description="Test Switchport Parcel",
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, switchport_parcel).id
# Assert
assert parcel_id

def test_when_fully_specified_values_switchport_expect_successful_post(self):
# Arrange
switchport_parcel = SwitchportParcel(
parcel_name="TestSwitchportParcel",
parcel_description="Test Switchport Parcel",
age_time=Global[int](value=100),
static_mac_address=[
StaticMacAddress(
mac_address=as_global("00:00:00:00:00:00"),
vlan=Global[int](value=1),
interface_name=as_global("GigabitEthernet0/0/0"),
)
],
interface=[
SwitchportInterface(
interface_name=as_global("GigabitEthernet0/0/0"),
mode=Global[SwitchportMode](value="access"),
shutdown=Global[bool](value=True),
speed=Global[Speed](value="10"),
duplex=Global[Duplex](value="full"),
switchport_access_vlan=Global[int](value=1),
switchport_trunk_allowed_vlans=Global[str](value="1-10"),
switchport_trunk_native_vlan=Global[int](value=1),
voice_vlan=Global[int](value=1),
host_mode=Global[HostMode](value="single-host"),
port_control=Global[PortControl](value="auto"),
control_direction=Global[ControlDirection](value="both"),
pae_enable=Global[bool](value=True),
guest_vlan=Global[int](value=1),
critical_vlan=Global[int](value=1),
enable_voice=Global[bool](value=True),
)
],
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, switchport_parcel).id
# Assert
assert parcel_id

@classmethod
def tearDownClass(cls) -> None:
cls.api.delete_profile(cls.profile_uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .ospf import OspfParcel
from .ospfv3 import Ospfv3IPv4Parcel, Ospfv3IPv6Parcel
from .route_policy import RoutePolicyParcel
from .switchport import SwitchportParcel

AnyTopLevelServiceParcel = Annotated[
Union[
Expand All @@ -26,6 +27,7 @@
Ospfv3IPv6Parcel,
RoutePolicyParcel,
EigrpParcel,
SwitchportParcel,
Ipv6AclParcel,
Ipv4AclParcel,
# TrackerGroupData,
Expand Down Expand Up @@ -60,6 +62,7 @@
"Ospfv3IPv6Parcel",
"Ipv6AclParcel",
"Ipv4AclParcel",
"SwitchportParcel",
"InterfaceSviParcel",
"InterfaceGreParcel",
"AnyServiceParcel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pydantic import AliasPath, BaseModel, ConfigDict, Field

from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase
from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase, as_default


class StaticMacAddress(BaseModel):
Expand Down Expand Up @@ -45,17 +45,27 @@ class StaticMacAddress(BaseModel):
"in",
]

Speed = Literal[
"10",
"100",
"1000",
"2500",
"10000",
]


class SwitchportInterface(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="forbid")

interface_name: Union[Global[str], Variable] = Field(serialization_alias="ifName", validation_alias="ifName")
mode: Optional[Global[SwitchportMode]] = None
shutdown: Optional[Union[Global[bool], Variable, Default[bool]]] = Default[bool](value=True)
speed: Optional[Union[Global[str], Variable, Default[None]]] = Default[None](value=None)
duplex: Optional[Union[Global[Duplex], Variable, Default[None]]] = Default[None](value=None)
switchport_access_vlan: Optional[Union[Global[int], Variable, Default[None]]] = Field(
serialization_alias="switchportAccessVlan", validation_alias="switchportAccessVlan", default=None
mode: Global[SwitchportMode] = as_default("access", SwitchportMode)
shutdown: Union[Global[bool], Variable, Default[bool]] = Default[bool](value=True)
speed: Union[Global[Speed], Variable, Default[None]] = Default[None](value=None)
duplex: Union[Global[Duplex], Variable, Default[None]] = Default[None](value=None)
switchport_access_vlan: Union[Global[int], Variable, Default[None]] = Field(
serialization_alias="switchportAccessVlan",
validation_alias="switchportAccessVlan",
default=Default[None](value=None),
)
switchport_trunk_allowed_vlans: Optional[Union[Global[str], Variable, Default[None]]] = Field(
serialization_alias="switchportTrunkAllowedVlans", validation_alias="switchportTrunkAllowedVlans", default=None
Expand All @@ -81,8 +91,8 @@ class SwitchportInterface(BaseModel):
enable_periodic_reauth: Optional[Union[Global[bool], Variable, Default[None]]] = Field(
serialization_alias="enablePeriodicReauth", validation_alias="enablePeriodicReauth", default=None
)
inactivity: Optional[Union[Global[int], Variable, Default[None]]] = None
reauthentication: Optional[Union[Global[int], Variable, Default[int]]] = None
inactivity: Union[Global[int], Variable, Default[None]] = Default[None](value=None)
reauthentication: Union[Global[int], Variable, Default[int]] = as_default(3600)
control_direction: Optional[Union[Global[ControlDirection], Variable, Default[None]]] = Field(
serialization_alias="controlDirection", validation_alias="controlDirection", default=None
)
Expand All @@ -104,12 +114,10 @@ class SwitchportParcel(_ParcelBase):
type_: Literal["switchport"] = Field(default="switchport", exclude=True)
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="forbid")

interface: Optional[List[SwitchportInterface]] = Field(
default=None, validation_alias=AliasPath("data", "interface")
)
age_time: Optional[Union[Global[int], Variable, Default[int]]] = Field(
validation_alias=AliasPath("data", "ageTime"), default=Default[int](value=300)
interface: List[SwitchportInterface] = Field(default_factory=list, validation_alias=AliasPath("data", "interface"))
age_time: Union[Global[int], Variable, Default[int]] = Field(
default=Default[int](value=300), validation_alias=AliasPath("data", "ageTime")
)
static_mac_address: Optional[List[StaticMacAddress]] = Field(
serialization_alias="staticMacAddress", validation_alias="staticMacAddress", default=None
static_mac_address: List[StaticMacAddress] = Field(
default_factory=list, validation_alias=AliasPath("data", "staticMacAddress")
)
2 changes: 2 additions & 0 deletions catalystwan/tests/test_feature_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
LanVpnDhcpServerParcel,
LanVpnParcel,
OspfParcel,
SwitchportParcel,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.acl import Ipv4AclParcel, Ipv6AclParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.eigrp import EigrpParcel
Expand Down Expand Up @@ -115,6 +116,7 @@ def test_update_method_with_valid_arguments(self, parcel, expected_path):
EigrpParcel: "routing/eigrp",
Ipv6AclParcel: "ipv6-acl",
Ipv4AclParcel: "ipv4-acl",
SwitchportParcel: "switchport",
}

service_interface_parcels = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
RedistributeProtocolOspf,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.ospfv3 import NetworkType
from catalystwan.models.configuration.feature_profile.sdwan.service.switchport import (
ControlDirection,
Duplex,
HostMode,
PortControl,
SwitchportMode,
)
from catalystwan.models.configuration.feature_profile.sdwan.system.logging_parcel import (
AuthType,
CypherSuite,
Expand All @@ -31,6 +38,7 @@
)
from catalystwan.models.configuration.feature_profile.sdwan.system.mrf import EnableMrfMigration, Role

"""List of all literals that can be casted."""
CastableLiterals = Union[
Priority,
TlsVersion,
Expand All @@ -48,6 +56,7 @@
TunnelApplication,
GreTunnelMode,
VrrpTrackerAction,
Duplex,
DuplexMode,
MediaType,
NatType,
Expand All @@ -58,6 +67,10 @@
AdvertiseType,
RedistributeProtocolOspf,
MetricType,
SwitchportMode,
PortControl,
HostMode,
ControlDirection,
]

CastedTypes = Union[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from catalystwan.utils.config_migration.converters.feature_template.dhcp import DhcpTemplateConverter
from catalystwan.utils.config_migration.converters.feature_template.ethernet import InterfaceEthernetTemplateConverter
from catalystwan.utils.config_migration.converters.feature_template.snmp import SNMPTemplateConverter
from catalystwan.utils.config_migration.converters.feature_template.switchport import SwitchportTemplateConverter
from catalystwan.utils.feature_template.find_template_values import find_template_values

from .aaa import AAATemplateConverter
Expand Down Expand Up @@ -57,6 +58,7 @@
InterfaceIpsecTemplateConverter,
OspfTemplateConverter,
Ospfv3TemplateConverter,
SwitchportTemplateConverter,
]


Expand Down
Loading

0 comments on commit 2526697

Please sign in to comment.