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

Commit

Permalink
Add Interface GRE model. Add unittests. Add integration tests. Change…
Browse files Browse the repository at this point in the history
… feature profile integration test structure. Add more Castable literals to the normalizer. Change name factory method to parcel_factory. Change VPN model type to lan/vpn.
  • Loading branch information
jpkrajewski committed Mar 21, 2024
1 parent 72dc539 commit 5b0b70f
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 175 deletions.
14 changes: 9 additions & 5 deletions catalystwan/api/feature_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from catalystwan.endpoints.configuration.feature_profile.sdwan.system import SystemFeatureProfile
from catalystwan.models.configuration.feature_profile.sdwan.other import AnyOtherParcel
from catalystwan.models.configuration.feature_profile.sdwan.policy_object.security.url import URLParcel
from catalystwan.models.configuration.feature_profile.sdwan.service import AnyServiceParcel, AnyTopLevelServiceParcel
from catalystwan.models.configuration.feature_profile.sdwan.service import AnyLanVpnInterfaceParcel, AnyServiceParcel
from catalystwan.typed_list import DataSequence

if TYPE_CHECKING:
Expand Down Expand Up @@ -232,13 +232,17 @@ def delete_profile(self, profile_id: UUID) -> None:
"""
self.endpoint.delete_sdwan_service_feature_profile(profile_id)

def create_parcel(self, profile_id: UUID, payload: AnyServiceParcel) -> ParcelCreationResponse:
def create_parcel(
self, profile_uuid: UUID, payload: AnyServiceParcel, vpn_uuid: Optional[UUID] = None
) -> ParcelCreationResponse:
"""
Create Service Parcel for selected profile_id based on payload type
"""
if type(payload) in get_args(AnyTopLevelServiceParcel)[0].__args__:
return self.endpoint.create_top_level_service_parcel(profile_id, payload._get_parcel_type(), payload)
return self.endpoint.create_lan_vpn_service_parcel(profile_id, payload)
if type(payload) in get_args(AnyLanVpnInterfaceParcel)[0].__args__:
return self.endpoint.create_lan_vpn_interface_parcel(
profile_uuid, vpn_uuid, payload._get_parcel_type(), payload
)
return self.endpoint.create_service_parcel(profile_uuid, payload._get_parcel_type(), payload)


class SystemFeatureProfileAPI:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
AnyLanVpnInterfaceParcel,
AnyTopLevelServiceParcel,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.lan.vpn import LanVpnParcel
from catalystwan.typed_list import DataSequence


Expand All @@ -42,16 +41,11 @@ def delete_sdwan_service_feature_profile(self, profile_uuid: UUID) -> None:

@versions(supported_versions=(">=20.9"), raises=False)
@post("/v1/feature-profile/sdwan/service/{profile_uuid}/{parcel_type}")
def create_top_level_service_parcel(
def create_service_parcel(
self, profile_uuid: UUID, parcel_type: str, payload: AnyTopLevelServiceParcel
) -> ParcelCreationResponse:
...

@versions(supported_versions=(">=20.9"), raises=False)
@post("/v1/feature-profile/sdwan/service/{profile_uuid}/lan/vpn/")
def create_lan_vpn_service_parcel(self, profile_uuid: UUID, payload: LanVpnParcel) -> ParcelCreationResponse:
...

@versions(supported_versions=(">=20.9"), raises=False)
@post("/v1/feature-profile/sdwan/service/{profile_uuid}/lan/vpn/{vpn_uuid}/interface/{parcel_type}")
def create_lan_vpn_interface_parcel(
Expand Down
16 changes: 16 additions & 0 deletions catalystwan/integration_tests/feature_profile/sdwan/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import unittest
from typing import cast

from catalystwan.session import create_manager_session


class TestFeatureProfileModels(unittest.TestCase):
def setUp(self) -> None:
# TODO: Add those params to PyTest
self.session = create_manager_session(
url=cast(str, os.environ.get("TEST_VMANAGE_URL", "localhost")),
port=cast(int, int(os.environ.get("TEST_VMANAGE_PORT", 443))), # type: ignore
username=cast(str, os.environ.get("TEST_VMANAGE_USERNAME", "admin")),
password=cast(str, os.environ.get("TEST_VMANAGE_PASSWORD", "admin")),
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import os
import unittest
from typing import cast

from catalystwan.api.configuration_groups.parcel import Global, as_global
from catalystwan.integration_tests.feature_profile.sdwan.base import TestFeatureProfileModels
from catalystwan.models.configuration.feature_profile.sdwan.other import ThousandEyesParcel, UcseParcel
from catalystwan.models.configuration.feature_profile.sdwan.other.ucse import AccessPort, Imc, LomType, SharedLom
from catalystwan.session import create_manager_session


class TestSystemOtherProfileModels(unittest.TestCase):
class TestSystemOtherProfileModels(TestFeatureProfileModels):
def setUp(self) -> None:
self.session = create_manager_session(
url=cast(str, os.environ.get("TEST_VMANAGE_URL")),
port=cast(int, int(os.environ.get("TEST_VMANAGE_PORT"))), # type: ignore
username=cast(str, os.environ.get("TEST_VMANAGE_USERNAME")),
password=cast(str, os.environ.get("TEST_VMANAGE_PASSWORD")),
)
self.profile_id = self.session.api.sdwan_feature_profiles.other.create_profile("TestProfile", "Description").id
super().setUp()
self.api = self.session.api.sdwan_feature_profiles.other
self.profile_id = self.api.create_profile("TestProfile", "Description").id

def test_when_default_values_thousandeyes_parcel_expect_successful_post(self):
# Arrange
Expand All @@ -25,7 +17,7 @@ def test_when_default_values_thousandeyes_parcel_expect_successful_post(self):
parcel_description="ThousandEyes Parcel",
)
# Act
parcel_id = self.session.api.sdwan_feature_profiles.other.create_parcel(self.profile_id, te_parcel).id
parcel_id = self.api.create_parcel(te_parcel, self.profile_id).id
# Assert
assert parcel_id

Expand All @@ -45,10 +37,10 @@ def test_when_default_values_ucse_parcel_expect_successful_post(self):
),
)
# Act
parcel_id = self.session.api.sdwan_feature_profiles.other.create_parcel(self.profile_id, ucse_parcel).id
parcel_id = self.api.create_parcel(ucse_parcel, self.profile_id).id
# Assert
assert parcel_id

def tearDown(self) -> None:
self.session.api.sdwan_feature_profiles.other.delete_profile(self.profile_id)
self.api.delete_profile(self.profile_id)
self.session.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from ipaddress import IPv4Address

from catalystwan.api.configuration_groups.parcel import Global, as_global
from catalystwan.integration_tests.feature_profile.sdwan.base import TestFeatureProfileModels
from catalystwan.models.configuration.feature_profile.sdwan.service.dhcp_server import (
AddressPool,
LanVpnDhcpServerParcel,
SubnetMask,
)
from catalystwan.models.configuration.feature_profile.sdwan.service.lan.gre import BasicGre, InterfaceGreParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.lan.vpn import LanVpnParcel


class TestServiceFeatureProfileModels(TestFeatureProfileModels):
def setUp(self) -> None:
super().setUp()
self.api = self.session.api.sdwan_feature_profiles.service
self.profile_uuid = self.api.create_profile("TestProfileService", "Description").id

def test_when_default_values_dhcp_server_parcel_expect_successful_post(self):
# Arrange
dhcp_server_parcel = LanVpnDhcpServerParcel(
parcel_name="DhcpServerDefault",
parcel_description="Dhcp Server Parcel",
address_pool=AddressPool(
network_address=Global[IPv4Address](value=IPv4Address("10.0.0.2")),
subnet_mask=Global[SubnetMask](value="255.255.255.255"),
),
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, dhcp_server_parcel).id
# Assert
assert parcel_id

def test_when_default_values_service_vpn_parcel_expect_successful_post(self):
# Arrange
vpn_parcel = LanVpnParcel(
parcel_name="TestVpnParcel",
parcel_description="Test Vpn Parcel",
vpn_id=Global[int](value=2),
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, vpn_parcel).id
# Assert
assert parcel_id

def tearDown(self) -> None:
self.api.delete_profile(self.profile_uuid)
self.session.close()


class TestServiceFeatureProfileVPNInterfaceModels(TestFeatureProfileModels):
def setUp(self) -> None:
super().setUp()
self.api = self.session.api.sdwan_feature_profiles.service
self.profile_uuid = self.api.create_profile("TestProfileService", "Description").id
self.vpn_parcel_uuid = self.api.create_parcel(
self.profile_uuid,
LanVpnParcel(
parcel_name="TestVpnParcel", parcel_description="Test Vpn Parcel", vpn_id=Global[int](value=2)
),
).id

def test_when_default_values_gre_parcel_expect_successful_post(self):
# Arrange
gre_parcel = InterfaceGreParcel(
parcel_name="TestGreParcel",
parcel_description="Test Gre Parcel",
basic=BasicGre(if_name=as_global("gre1"), tunnel_destination=as_global(IPv4Address("4.4.4.4"))),
)
# Act
parcel_id = self.api.create_parcel(self.profile_uuid, gre_parcel, self.vpn_parcel_uuid).id
# Assert
assert parcel_id

def tearDown(self) -> None:
self.api.delete_profile(self.profile_uuid)
self.session.close()
Loading

0 comments on commit 5b0b70f

Please sign in to comment.