diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-11-19 06:52:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-19 06:52:47 +0100 |
commit | 0cec72de1716e5dcad5074be8c5de03464577364 (patch) | |
tree | 5f5ee1753edb918b42fc57ebdc2e04e5bf56dd8d /src/op_mode | |
parent | 95abda42a4ef4a949b897a4aa5eaf52e6c2842a8 (diff) | |
parent | 58057480e22712dc6d04396f8805d3db338bddfa (diff) | |
download | vyos-1x-0cec72de1716e5dcad5074be8c5de03464577364.tar.gz vyos-1x-0cec72de1716e5dcad5074be8c5de03464577364.zip |
Merge pull request #1665 from jestabro/op-mode-value-error
IPsec: T4828: raise op-mode error on incorrect value
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/ipsec.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/op_mode/ipsec.py b/src/op_mode/ipsec.py index aaa0cec5a..83e4241d7 100755 --- a/src/op_mode/ipsec.py +++ b/src/op_mode/ipsec.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os import re import sys @@ -138,6 +139,8 @@ def _get_formatted_output_sas(sas): def get_peer_connections(peer, tunnel, return_all = False): search = rf'^[\s]*({peer}-(tunnel-[\d]+|vti)).*' matches = [] + if not os.path.exists(SWANCTL_CONF): + raise vyos.opmode.UnconfiguredSubsystem("IPsec not initialized") with open(SWANCTL_CONF, 'r') as f: for line in f.readlines(): result = re.match(search, line) @@ -149,27 +152,19 @@ def get_peer_connections(peer, tunnel, return_all = False): def reset_peer(peer: str, tunnel:str): - if not peer: - print('Invalid peer, aborting') - return - conns = get_peer_connections(peer, tunnel, return_all = (not tunnel or tunnel == 'all')) if not conns: - print('Tunnel(s) not found, aborting') - return + raise vyos.opmode.IncorrectValue('Peer or tunnel(s) not found, aborting') - result = True for conn in conns: try: call(f'sudo /usr/sbin/ipsec down {conn}{{*}}', timeout = 10) call(f'sudo /usr/sbin/ipsec up {conn}', timeout = 10) except TimeoutExpired as e: - print(f'Timed out while resetting {conn}') - result = False - + raise vyos.opmode.InternalError(f'Timed out while resetting {conn}') - print('Peer reset result: ' + ('success' if result else 'failed')) + print('Peer reset result: success') def show_sa(raw: bool): |