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

Commit

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

* Add unit test

* Add converter

* Add model. integration tests unit test. fix model. mode Subnetmask to common

* Add converter to migration list

* Fix bad autocomplete
  • Loading branch information
jpkrajewski authored Apr 15, 2024
1 parent 2526697 commit 84b3226
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from ipaddress import IPv4Address
from secrets import token_hex
from uuid import UUID

from catalystwan.api.configuration_groups.parcel import Global, as_global, as_variable
from catalystwan.integration_tests.feature_profile.sdwan.base import TestFeatureProfileModels
from catalystwan.models.common import SubnetMask
from catalystwan.models.configuration.feature_profile.common import Prefix
from catalystwan.models.configuration.feature_profile.sdwan.service.acl import Ipv4AclParcel, Ipv6AclParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.dhcp_server import (
AddressPool,
LanVpnDhcpServerParcel,
SubnetMask,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.eigrp import (
AddressFamily,
Expand Down Expand Up @@ -44,6 +45,17 @@
SwitchportMode,
SwitchportParcel,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.wireless_lan import (
SSID,
CountryCode,
MeIpConfig,
MeStaticIpConfig,
QosProfile,
RadioType,
SecurityConfig,
SecurityType,
WirelessLanParcel,
)


class TestServiceFeatureProfileModels(TestFeatureProfileModels):
Expand Down Expand Up @@ -229,6 +241,46 @@ def test_when_fully_specified_values_switchport_expect_successful_post(self):
# Assert
assert parcel_id

def test_when_fully_specified_values_wireless_lan_expect_successful_post(self):
# Arrange
wireless_lan_parcel = WirelessLanParcel(
parcel_name="TestWirelessLanParcel",
parcel_description="Test Wireless Lan Parcel",
enable_2_4G=as_global(True),
enable_5G=as_global(True),
country=as_global("US", CountryCode),
username=as_global("admin"),
password=as_global(token_hex(16) + "TEST!@#"),
ssid=[
SSID(
name=as_global("TestSSID"),
admin_state=as_global(True),
vlan_id=as_global(1),
broadcast_ssid=as_global(True),
radio_type=as_global("all", RadioType),
qos_profile=as_global("platinum", QosProfile),
security_config=SecurityConfig(
security_type=as_global("enterprise", SecurityType),
radius_server_ip=as_global(IPv4Address("1.1.1.1")),
radius_server_port=as_global(1884),
radius_server_secret=as_global("23452345245"),
),
)
],
me_ip_config=MeIpConfig(
me_dynamic_ip_enabled=as_global(False),
me_static_ip_config=MeStaticIpConfig(
me_ipv4_address=as_global(IPv4Address("10.2.3.2")),
netmask=as_global("255.255.255.0", SubnetMask),
default_gateway=as_global(IPv4Address("10.0.0.1")),
),
),
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, wireless_lan_parcel).id
# Assert
assert parcel_id

@classmethod
def tearDownClass(cls) -> None:
cls.api.delete_profile(cls.profile_uuid)
Expand Down
35 changes: 35 additions & 0 deletions catalystwan/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,38 @@ def str_as_str_list(val: Union[str, Sequence[str]]) -> Sequence[str]:
]

MetricType = Literal["type1", "type2"]

SubnetMask = Literal[
"255.255.255.255",
"255.255.255.254",
"255.255.255.252",
"255.255.255.248",
"255.255.255.240",
"255.255.255.224",
"255.255.255.192",
"255.255.255.128",
"255.255.255.0",
"255.255.254.0",
"255.255.252.0",
"255.255.248.0",
"255.255.240.0",
"255.255.224.0",
"255.255.192.0",
"255.255.128.0",
"255.255.0.0",
"255.254.0.0",
"255.252.0.0",
"255.240.0.0",
"255.224.0.0",
"255.192.0.0",
"255.128.0.0",
"255.0.0.0",
"254.0.0.0",
"252.0.0.0",
"248.0.0.0",
"240.0.0.0",
"224.0.0.0",
"192.0.0.0",
"128.0.0.0",
"0.0.0.0",
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,11 @@
from pydantic import AliasPath, BaseModel, ConfigDict, Field

from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase, as_global, as_variable
from catalystwan.models.common import SubnetMask

ProxyTypeStatic = Literal["static"]
ProxyTypePac = Literal["pac"]
ProxyTypeNone = Literal["none"]
TeMgmtSubnetMask = Literal[
"255.255.255.255",
"255.255.255.254",
"255.255.255.252",
"255.255.255.248",
"255.255.255.240",
"255.255.255.224",
"255.255.255.192",
"255.255.255.128",
"255.255.255.0",
"255.255.254.0",
"255.255.252.0",
"255.255.248.0",
"255.255.240.0",
"255.255.224.0",
"255.255.192.0",
"255.255.128.0",
"255.255.0.0",
"255.254.0.0",
"255.252.0.0",
"255.240.0.0",
"255.224.0.0",
"255.192.0.0",
"255.128.0.0",
"255.0.0.0",
"254.0.0.0",
"252.0.0.0",
"248.0.0.0",
"240.0.0.0",
"224.0.0.0",
"192.0.0.0",
"128.0.0.0",
"0.0.0.0",
]


class ProxyConfigStatic(BaseModel):
Expand Down Expand Up @@ -135,7 +102,7 @@ class VirtualApplicationItem(BaseModel):
validation_alias="teMgmtIp",
description="Set the Agent IP Address",
)
te_mgmt_subnet_mask: Optional[Union[Variable, Global[TeMgmtSubnetMask]]] = Field(
te_mgmt_subnet_mask: Optional[Union[Variable, Global[SubnetMask]]] = Field(
default=None,
serialization_alias="teMgmtSubnetMask",
validation_alias="teMgmtSubnetMask",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,8 @@
from pydantic import AliasPath, BaseModel, ConfigDict, Field, field_validator, model_validator

from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase
from catalystwan.models.common import check_fields_exclusive

SubnetMask = Literal[
"255.255.255.255",
"255.255.255.254",
"255.255.255.252",
"255.255.255.248",
"255.255.255.240",
"255.255.255.224",
"255.255.255.192",
"255.255.255.128",
"255.255.255.0",
"255.255.254.0",
"255.255.252.0",
"255.255.248.0",
"255.255.240.0",
"255.255.224.0",
"255.255.192.0",
"255.255.128.0",
"255.255.0.0",
"255.254.0.0",
"255.252.0.0",
"255.240.0.0",
"255.224.0.0",
"255.192.0.0",
"255.128.0.0",
"255.0.0.0",
"254.0.0.0",
"252.0.0.0",
"248.0.0.0",
"240.0.0.0",
"224.0.0.0",
"192.0.0.0",
"128.0.0.0",
"0.0.0.0",
]
from catalystwan.models.common import SubnetMask, check_fields_exclusive

MAC_PATTERN_1 = re.compile(r"^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$")
MAC_PATTERN_2 = re.compile(r"^[0-9a-fA-F]{4}\.[0-9a-fA-F]{4}\.[0-9a-fA-F]{4}$")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from ipaddress import IPv4Address
from typing import List, Literal, Optional, Union

from pydantic import AliasPath, BaseModel, ConfigDict, Field

from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase
from catalystwan.models.common import SubnetMask

CountryCode = Literal[
"AE",
Expand Down Expand Up @@ -137,9 +139,11 @@
class MeStaticIpConfig(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="forbid")

me_ipv4_address: Union[Global[str], Variable]
netmask: Union[Global[str], Variable]
default_gateway: Union[Global[str], Variable] = Field(
me_ipv4_address: Union[Global[IPv4Address], Variable] = Field(
serialization_alias="meIpv4Address", validation_alias="meIpv4Address"
)
netmask: Union[Global[SubnetMask], Variable]
default_gateway: Union[Global[IPv4Address], Variable] = Field(
serialization_alias="defaultGateway", validation_alias="defaultGateway"
)

Expand All @@ -152,14 +156,16 @@ class MeIpConfig(BaseModel):
validation_alias="meDynamicIpEnabled",
default=Default[bool](value=True),
)
me_static_ip_config: Optional[MeStaticIpConfig] = None
me_static_ip_config: Optional[MeStaticIpConfig] = Field(
default=None, serialization_alias="meStaticIpCfg", validation_alias="meStaticIpCfg"
)


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

security_type: Global[SecurityType] = Field(serialization_alias="securityType", validation_alias="securityType")
radius_server_ip: Optional[Union[Global[str], Variable]] = Field(
radius_server_ip: Optional[Union[Global[IPv4Address], Variable]] = Field(
serialization_alias="radiusServerIp", validation_alias="radiusServerIp", default=None
)
radius_server_port: Optional[Union[Global[int], Variable, Default[int]]] = Field(
Expand Down
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 @@ -26,6 +26,7 @@
from catalystwan.models.configuration.feature_profile.sdwan.service.lan.ipsec import IpsecAddress, IpsecTunnelMode
from catalystwan.models.configuration.feature_profile.sdwan.service.ospfv3 import Ospfv3IPv4Parcel, Ospfv3IPv6Parcel
from catalystwan.models.configuration.feature_profile.sdwan.service.route_policy import RoutePolicyParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.wireless_lan import WirelessLanParcel
from catalystwan.models.configuration.feature_profile.sdwan.system import (
AAAParcel,
BannerParcel,
Expand Down Expand Up @@ -117,6 +118,7 @@ def test_update_method_with_valid_arguments(self, parcel, expected_path):
Ipv6AclParcel: "ipv6-acl",
Ipv4AclParcel: "ipv4-acl",
SwitchportParcel: "switchport",
WirelessLanParcel: "wirelesslan",
}

service_interface_parcels = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from typing import List

from catalystwan.api.configuration_groups.parcel import Global, Variable, as_global, as_variable
from catalystwan.models.configuration.feature_profile.sdwan.service.dhcp_server import (
LanVpnDhcpServerParcel,
SubnetMask,
)
from catalystwan.models.common import SubnetMask
from catalystwan.models.configuration.feature_profile.sdwan.service.dhcp_server import LanVpnDhcpServerParcel

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from typing import List, Optional, Union, get_args

from catalystwan.api.configuration_groups.parcel import Global, as_global
from catalystwan.models.common import MetricType, TLOCColor
from catalystwan.models.configuration.feature_profile.sdwan.service.dhcp_server import SubnetMask
from catalystwan.models.common import MetricType, SubnetMask, TLOCColor
from catalystwan.models.configuration.feature_profile.sdwan.service.lan.common import (
IkeCiphersuite,
IkeMode,
Expand All @@ -30,6 +29,12 @@
PortControl,
SwitchportMode,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.wireless_lan import (
CountryCode,
QosProfile,
RadioType,
SecurityType,
)
from catalystwan.models.configuration.feature_profile.sdwan.system.logging_parcel import (
AuthType,
CypherSuite,
Expand Down Expand Up @@ -71,6 +76,10 @@
PortControl,
HostMode,
ControlDirection,
CountryCode,
RadioType,
QosProfile,
SecurityType,
]

CastedTypes = Union[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.config_migration.converters.feature_template.wireless_lan import WirelessLanTemplateConverter
from catalystwan.utils.feature_template.find_template_values import find_template_values

from .aaa import AAATemplateConverter
Expand Down Expand Up @@ -59,6 +60,7 @@
OspfTemplateConverter,
Ospfv3TemplateConverter,
SwitchportTemplateConverter,
WirelessLanTemplateConverter,
]


Expand Down
Loading

0 comments on commit 84b3226

Please sign in to comment.