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

Commit

Permalink
fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Apr 9, 2024
1 parent f25b1ae commit a5ac6a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion catalystwan/endpoints/configuration_dashboard_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Validation(BaseModel):
action: Optional[str] = Field(default=None, serialization_alias="action", validation_alias="action")
start_time: Optional[int] = Field(default=None, serialization_alias="startTime", validation_alias="startTime")
request_status: Optional[str] = Field(
sdefault=None, erialization_alias="requestStatus", validation_alias="requestStatus"
default=None, serialization_alias="requestStatus", validation_alias="requestStatus"
)
status: OperationStatus = Field(default=None, serialization_alias="status", validation_alias="status")
order: Optional[int] = Field(default=None, serialization_alias="order", validation_alias="order")
Expand Down
2 changes: 1 addition & 1 deletion catalystwan/endpoints/configuration_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class StatsCollectionInterval(BaseModel):
le=180,
serialization_alias="operationInterval",
validation_alias="operationInterval",
desctiption="collecion interval in minutes",
description="collecion interval in minutes",
)


Expand Down
3 changes: 2 additions & 1 deletion catalystwan/endpoints/monitoring_device_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Tier(BaseModel):


class DeviceData(BaseModel):
model_config = ConfigDict(populate_by_name=True)
# Field "model_sku" has conflict with protected namespace "model_"
model_config = ConfigDict(populate_by_name=True, protected_namespaces=())
board_serial: Optional[str] = Field(
default=None, serialization_alias="board-serial", validation_alias="board-serial"
)
Expand Down
22 changes: 11 additions & 11 deletions catalystwan/endpoints/tenant_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@

# mypy: disable-error-code="empty-body"
from pathlib import Path
from typing import List, Union
from typing import Any
from urllib.parse import parse_qs, urlsplit

from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, model_validator

from catalystwan.endpoints import APIEndpoints, CustomPayloadType, PreparedPayload, get, post, versions, view
from catalystwan.models.tenant import TenantExport
from catalystwan.utils.session_type import ProviderView, SingleTenantView


class MigrationTokenQueryParams(BaseModel):
model_config = ConfigDict(populate_by_name=True)
migration_id: Union[List[str], str] = Field(serialization_alias="migrationId", validation_alias="migrationId")
model_config = ConfigDict(populate_by_name=True, extra="allow")
migration_id: str = Field(serialization_alias="migrationId", validation_alias="migrationId")

@field_validator("migration_id")
@model_validator(mode="before")
@classmethod
def single_migration_id_required(cls, value: Union[List[str], str]):
if isinstance(value, list):
return value[0]
return value
def single_migration_id_required(cls, values: Any):
migration_id = values.get("migrationId")
if isinstance(migration_id, list) and len(migration_id) == 1:
values["migrationId"] = migration_id[0]
return values


class ExportInfo(BaseModel):
Expand All @@ -40,8 +41,7 @@ def migration_token_query(self) -> str:

@property
def migration_token_query_params(self) -> MigrationTokenQueryParams:
query = self.migration_token_query
return MigrationTokenQueryParams(**parse_qs(query))
return MigrationTokenQueryParams.model_validate(parse_qs(self.migration_token_query))


class MigrationInfo(BaseModel):
Expand Down
23 changes: 9 additions & 14 deletions catalystwan/tests/test_tenant_migration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
from pathlib import Path
from unittest.mock import MagicMock, patch
from uuid import uuid4

from packaging.version import Version # type: ignore

Expand Down Expand Up @@ -46,19 +47,16 @@ def test_download(self):

def test_import_tenant(self):
self.session.api_version = Version("20.12")
migration_key = "Cisco12345"
migration_id = "dcbed267-eb0d-4dcd-9c12-2536e8562f75"
migration_key = "mkey1"
migration_id = str(uuid4())
with tempfile.TemporaryDirectory() as tmpdir:
import_file = Path(tmpdir) / "tenant.tar.gz"
with open(import_file, "wb") as f:
f.write(b"\xFEtest_data")
self.session.endpoints.tenant_migration.import_tenant_data = MagicMock(
return_value=ImportInfo(
processId="123",
migrationTokenURL=(
"/dataservice/tenantmigration/migrationToken?"
"migrationId=dcbed267-eb0d-4dcd-9c12-2536e8562f75"
),
process_id="123",
migration_token_url=("/dataservice/tenantmigration/migrationToken?" f"migrationId={migration_id}"),
)
)
task = self.api.import_tenant(import_file, migration_key)
Expand All @@ -67,19 +65,16 @@ def test_import_tenant(self):

def test_import_tenant_with_key(self):
self.session.api_version = Version("20.13")
migration_key = "Cisco12345"
migration_id = "dcbed267-eb0d-4dcd-9c12-2536e8562f75"
migration_key = "mkey2"
migration_id = str(uuid4())
with tempfile.TemporaryDirectory() as tmpdir:
import_file = Path(tmpdir) / "tenant.tar.gz"
with open(import_file, "wb") as f:
f.write(b"\xFEtest_data")
self.session.endpoints.tenant_migration.import_tenant_data_with_key = MagicMock(
return_value=ImportInfo(
processId="123",
migrationTokenURL=(
"/dataservice/tenantmigration/migrationToken?"
"migrationId=dcbed267-eb0d-4dcd-9c12-2536e8562f75"
),
process_id="123",
migration_token_url=("/dataservice/tenantmigration/migrationToken?" f"migrationId={migration_id}"),
)
)
task = self.api.import_tenant(import_file, migration_key)
Expand Down

0 comments on commit a5ac6a6

Please sign in to comment.