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
4 changes: 4 additions & 0 deletions netplan_cli/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import logging
import os
import sys

from . import utils
from netplan import NetplanException, NetplanValidationException, NetplanParserException
Expand Down Expand Up @@ -59,7 +60,10 @@ def main(self):
except NetplanParserException as e:
message = f'{e.filename}:{e.line}:{e.column}: {e}'
logging.warning(f'Command failed: {message}')
sys.exit(1)
except NetplanValidationException as e:
logging.warning(f'Command failed: {e.filename}: {e}')
sys.exit(1)
except NetplanException as e:
logging.warning(f'Command failed: {e}')
sys.exit(1)
18 changes: 14 additions & 4 deletions tests/cli/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def test_raises_exception_main_function(self):
old_argv = sys.argv
args = ['get', '--root-dir', self.tmproot]
sys.argv = [old_argv[0]] + args
Netplan().main()
with self.assertRaises(SystemExit) as e:
Netplan().main()
self.assertEqual(1, e.exception.code)
sys.argv = old_argv

args = log.call_args.args
Expand All @@ -164,7 +166,9 @@ def test_raises_exception_main_function_permission_denied(self):
old_argv = sys.argv
args = ['get', '--root-dir', self.tmproot]
sys.argv = [old_argv[0]] + args
Netplan().main()
with self.assertRaises(SystemExit) as e:
Netplan().main()
self.assertEqual(1, e.exception.code)
sys.argv = old_argv

args = log.call_args.args
Expand All @@ -181,8 +185,11 @@ def test_get_validation_error_exception(self):
old_argv = sys.argv
args = ['get', '--root-dir', self.tmproot]
sys.argv = [old_argv[0]] + args
Netplan().main()
with self.assertRaises(SystemExit) as e:
Netplan().main()
self.assertEqual(1, e.exception.code)
sys.argv = old_argv

args = log.call_args.args
self.assertIn('etc/netplan/test.yaml: Error in network definition', args[0])

Expand All @@ -200,7 +207,10 @@ def test_set_generic_validation_error_exception(self):
old_argv = sys.argv
args = ['get', '--root-dir', self.tmproot]
sys.argv = [old_argv[0]] + args
Netplan().main()
with self.assertRaises(SystemExit) as e:
Netplan().main()
self.assertEqual(1, e.exception.code)
sys.argv = old_argv

args = log.call_args.args
self.assertIn("VRF routes table mismatch", args[0])
6 changes: 6 additions & 0 deletions tools/run_asan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ mkdir -p ${BUILDDIR}/fakeroot/{etc/netplan,run}

for yaml in examples/*.yaml
do
## Ignore OpenVSwitch-related files for this test
## As ovs is an optional dependency, it may not be available
if [[ "${yaml}" == *"openvswitch"* ]]; then
echo "Skipping OpenVSwitch file ${yaml}"
continue
fi
filepath=${BUILDDIR}/fakeroot/etc/netplan/${yaml##*/}
filename=$(basename ${filepath})
cp ${yaml} ${BUILDDIR}/fakeroot/etc/netplan/
Expand Down
Loading