summaryrefslogtreecommitdiffstats
path: root/os_net_config
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config')
-rw-r--r--os_net_config/cli.py11
-rw-r--r--os_net_config/tests/test_cli.py25
2 files changed, 36 insertions, 0 deletions
diff --git a/os_net_config/cli.py b/os_net_config/cli.py
index c2491a2..c0ac5c4 100644
--- a/os_net_config/cli.py
+++ b/os_net_config/cli.py
@@ -48,6 +48,13 @@ def parse_opts(argv):
parser.add_argument('-r', '--root-dir', metavar='ROOT_DIR',
help="""The root directory of the filesystem.""",
default='')
+ parser.add_argument('--detailed-exit-codes',
+ action='store_true',
+ help="""Enable detailed exit codes. """
+ """If enabled an exit code of '2' means """
+ """that files were modified."""
+ """Disabled by default.""",
+ default=False)
parser.add_argument(
'-d', '--debug',
dest="debug",
@@ -183,6 +190,10 @@ def main(argv=sys.argv):
print("File: %s\n" % location)
print(data)
print("----")
+
+ if opts.detailed_exit_codes and len(files_changed) > 0:
+ return 2
+
return 0
diff --git a/os_net_config/tests/test_cli.py b/os_net_config/tests/test_cli.py
index 310a527..98477fc 100644
--- a/os_net_config/tests/test_cli.py
+++ b/os_net_config/tests/test_cli.py
@@ -17,7 +17,9 @@
import os.path
import sys
+import os_net_config
from os_net_config import cli
+from os_net_config import impl_ifcfg
from os_net_config.tests import base
import six
@@ -121,3 +123,26 @@ class TestCli(base.TestCase):
'-c %s' % (provider, bond_yaml))
self.assertEqual('', stderr)
self.assertIn('File: /rootfs/', stdout_yaml)
+
+ def test_interface_noop_detailed_exit_codes(self):
+ interface_yaml = os.path.join(SAMPLE_BASE, 'interface.yaml')
+ stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
+ '-c %s --detailed-exit-codes'
+ % interface_yaml, exitcodes=(2,))
+
+ def test_interface_noop_detailed_exit_codes_no_changes(self):
+ interface_yaml = os.path.join(SAMPLE_BASE, 'interface.yaml')
+
+ class TestImpl(os_net_config.NetConfig):
+
+ def add_interface(self, interface):
+ pass
+
+ def apply(self, cleanup=False, activate=True):
+ # this fake implementation returns no changes
+ return {}
+
+ self.stubs.Set(impl_ifcfg, 'IfcfgNetConfig', TestImpl)
+ stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
+ '-c %s --detailed-exit-codes'
+ % interface_yaml, exitcodes=(0,))