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

Commit

Permalink
dev release prep (#536)
Browse files Browse the repository at this point in the history
* clear cookies on login, bump minor (#532)

* [Fix] validation software timeout (#534)

* clear cookies on login, bump minor

* fix validation value

---------

Co-authored-by: sbasan <[email protected]>

* fix log message level for request exceptions

* rename rollback info fields

* add rollback progress

---------

Co-authored-by: cicharka <[email protected]>
  • Loading branch information
sbasan and cicharka authored Mar 22, 2024
1 parent 43cd647 commit 357ee63
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion catalystwan/endpoints/configuration_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def check_download_timeout(cls, download_timeout_str: str):
@validator("activate_timeout")
def check_activate_timeout(cls, activate_timeout_str: str):
activate_timeout = int(activate_timeout_str)
if activate_timeout < 60 or activate_timeout > 180:
if activate_timeout < 30 or activate_timeout > 180:
raise ValueError("activate timeout should be in range 30-180")
return activate_timeout_str

Expand Down
12 changes: 8 additions & 4 deletions catalystwan/models/configuration/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,15 @@ class UX2Config(BaseModel):


class UX2ConfigRollback(BaseModel):
config_groups_ids: List[UUID] = Field(default_factory=list)
feature_profiles_ids: List[Tuple[UUID, ProfileType]] = Field(default_factory=list)
config_group_ids: List[UUID] = Field(
default_factory=list, serialization_alias="ConfigGroupIds", validation_alias="ConfigGroupIds"
)
feature_profile_ids: List[Tuple[UUID, ProfileType]] = Field(
default_factory=list, serialization_alias="FeatureProfileIds", validation_alias="FeatureProfileIds"
)

def add_config_group(self, config_group_id: UUID) -> None:
self.config_groups_ids.append(config_group_id)
self.config_group_ids.append(config_group_id)

def add_feature_profile(self, feature_profile_id: UUID, profile_type: ProfileType) -> None:
self.feature_profiles_ids.append((feature_profile_id, profile_type))
self.feature_profile_ids.append((feature_profile_id, profile_type))
5 changes: 3 additions & 2 deletions catalystwan/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def login(self) -> ManagerSession:
ManagerSession: (self)
"""

self.cookies.clear_session_cookies()
self.auth = vManageAuth(self.base_url, self.username, self.password, verify=False)
self.auth.logger = self.logger

Expand Down Expand Up @@ -325,7 +326,7 @@ def request(self, method, url, *args, **kwargs) -> ManagerResponse:
if self.state == ManagerSessionState.RESTART_IMMINENT and isinstance(exception, ConnectionError):
self.state = ManagerSessionState.WAIT_SERVER_READY_AFTER_RESTART
return self.request(method, url, *args, **kwargs)
self.logger.error(exception)
self.logger.debug(exception)
raise ManagerRequestException(request=exception.request, response=exception.response)

if self.enable_relogin and response.jsessionid_expired and self.state == ManagerSessionState.OPERATIVE:
Expand All @@ -339,7 +340,7 @@ def request(self, method, url, *args, **kwargs) -> ManagerResponse:
try:
response.raise_for_status()
except HTTPError as error:
self.logger.error(error)
self.logger.debug(error)
error_info = response.get_error_info()
raise ManagerHTTPError(error_info=error_info, request=error.request, response=error.response)
return response
Expand Down
10 changes: 7 additions & 3 deletions catalystwan/utils/config_migration/reverters/config_reverter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Callable
from venv import logger

from catalystwan.exceptions import CatalystwanException
Expand All @@ -9,15 +10,18 @@ class UX2ConfigReverter:
def __init__(self, session) -> None:
self._session = session

def rollback(self, rollback_config: UX2ConfigRollback) -> bool:
def rollback(self, rollback_config: UX2ConfigRollback, progress: Callable[[str, int, int], None]) -> bool:
try:
for cg_id in rollback_config.config_groups_ids:
for i, cg_id in enumerate(rollback_config.config_group_ids):
self._session.endpoints.configuration_group.delete_config_group(cg_id)
for feature_profile_id, type_ in rollback_config.feature_profiles_ids:
progress("Removing Configuration Groups", i + 1, len(rollback_config.config_group_ids))
for i, feature_profile_entry in enumerate(rollback_config.feature_profile_ids):
feature_profile_id, type_ = feature_profile_entry
api = FeatureProfileAPIFactory.get_api(type_, self._session)
if type_ == "policy-object":
continue
api.delete_profile(feature_profile_id) # type: ignore
progress("Removing Feature Profiles", i + 1, len(rollback_config.feature_profile_ids))
except CatalystwanException as e:
logger.error(f"Error occured during config revert: {e}")
return False
Expand Down
8 changes: 6 additions & 2 deletions catalystwan/workflows/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ def push_ux2_config(
return rollback


def rollback_ux2_config(session: ManagerSession, rollback_config: UX2ConfigRollback) -> bool:
def rollback_ux2_config(
session: ManagerSession,
rollback_config: UX2ConfigRollback,
progress: Callable[[str, int, int], None] = log_progress,
) -> bool:
config_reverter = UX2ConfigReverter(session)
status = config_reverter.rollback(rollback_config)
status = config_reverter.rollback(rollback_config, progress)
return status
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "catalystwan"
version = "0.32.0dev1"
version = "0.31.2dev0"
description = "Cisco Catalyst WAN SDK for Python"
authors = ["kagorski <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 357ee63

Please sign in to comment.