Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions python/vyos/configsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import re
import sys
import weakref
import subprocess
from tempfile import NamedTemporaryFile
from typing import TypeAlias
Expand Down Expand Up @@ -199,10 +200,15 @@ def __init__(self, session_id, app=APP, shared=False):

self.shared = shared

if not self.shared and self._vyconf_session:
self._finalizer = weakref.finalize(
self, self.finalize_vyconf, self._vyconf_session
)

def __del__(self):
if self.shared:
return
if self._vyconf_session is None:
if not vyconf_backend():
try:
output = (
subprocess.check_output(
Expand All @@ -223,12 +229,13 @@ def __del__(self):
'Could not tear down session {0}: {1}'.format(self.__session_id, e),
file=sys.stderr,
)
else:
if self._vyconf_session.session_changed():
Warn('Exiting with uncommitted changes')
self._vyconf_session.discard()
self._vyconf_session.exit_config_mode()
self._vyconf_session.teardown()

def finalize_vyconf(self, session: VyconfSession):
if session.session_changed():
Warn('Exiting with uncommitted changes')
session.discard()
session.exit_config_mode()
session.teardown()

def __run_command(self, cmd_list):
p = subprocess.Popen(
Expand Down
7 changes: 0 additions & 7 deletions python/vyos/configsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,6 @@ def __init__(self, session_env=None):
# cf. T7374
self._level = []

def __del__(self):
try:
if not self._vyconf_session.in_session():
self._vyconf_session.teardown()
except AttributeError:
pass

def get_level(self):
return self._level

Expand Down
Loading
Loading