From e8a2a587293e84a173a7b91f1fd1ade5b9798ecc Mon Sep 17 00:00:00 2001 From: Jakub Krajewski Date: Mon, 12 Aug 2024 13:46:52 +0200 Subject: [PATCH] implement copy protocol --- catalystwan/session.py | 8 ++++++++ catalystwan/workflows/tenant_migration.py | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/catalystwan/session.py b/catalystwan/session.py index c3aa626e..a73e1d6f 100644 --- a/catalystwan/session.py +++ b/catalystwan/session.py @@ -553,5 +553,13 @@ def validate_responses(self) -> bool: def validate_responses(self, value: bool): self._validate_responses = value + def __copy__(self) -> ManagerSession: + return ManagerSession( + base_url=self.base_url, + auth=self._auth, + subdomain=self.subdomain, + logger=self.logger, + ) + def __str__(self) -> str: return f"ManagerSession(session_type={self.session_type}, auth={self._auth})" diff --git a/catalystwan/workflows/tenant_migration.py b/catalystwan/workflows/tenant_migration.py index ded38096..27fdb259 100644 --- a/catalystwan/workflows/tenant_migration.py +++ b/catalystwan/workflows/tenant_migration.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +from copy import copy from datetime import datetime from pathlib import Path from typing import Dict, List @@ -127,9 +128,9 @@ def migration_preconditions_check( logger.info("Checking if migrated devices can reach target validator...") conn_check = False if origin_session.session_type == SessionType.PROVIDER: - origin_session.subdomain = tenant.subdomain - origin_session.logout() - with origin_session.login() as provider_as_tenant_session: + as_tenant = copy(origin_session) + as_tenant.subdomain = tenant.subdomain + with as_tenant.login() as provider_as_tenant_session: conn_check = check_control_connectivity_from_edge_devices(provider_as_tenant_session, validator) else: conn_check = check_control_connectivity_from_edge_devices(origin_session, validator)