aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/tests/test_cli.py
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2014-08-20 21:46:46 -0400
committerDan Prince <dprince@redhat.com>2014-08-20 21:46:46 -0400
commit416943cc4e1ec7e4fc0e86640f24f0133a8b2f4e (patch)
tree67698cc6a037c5bc3339dab31bf7e4226d875074 /os_net_config/tests/test_cli.py
parentb3e74611befb157dc4bf992f23aaba346e655a86 (diff)
Add support for parsing YAML
Adds new YAML examples. Also adds some new CLI test cases which compare --noop stdout (from the CLI) for the json and yaml examples to verify they generate the same things.
Diffstat (limited to 'os_net_config/tests/test_cli.py')
-rw-r--r--os_net_config/tests/test_cli.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/os_net_config/tests/test_cli.py b/os_net_config/tests/test_cli.py
new file mode 100644
index 0000000..505301c
--- /dev/null
+++ b/os_net_config/tests/test_cli.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2014 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import os.path
+import sys
+
+from os_net_config import cli
+from os_net_config.tests import base
+import six
+
+
+SAMPLE_BASE = os.path.join('.', 'etc', 'os-net-config', 'samples')
+
+
+class TestCli(base.TestCase):
+
+ def run_cli(self, argstr, exitcodes=(0,)):
+ orig = sys.stdout
+ orig_stderr = sys.stderr
+ try:
+ sys.stdout = six.StringIO()
+ sys.stderr = six.StringIO()
+ cli.main(argstr.split())
+ except SystemExit:
+ exc_type, exc_value, exc_traceback = sys.exc_info()
+ self.assertIn(exc_value.code, exitcodes)
+ finally:
+ stdout = sys.stdout.getvalue()
+ sys.stdout.close()
+ sys.stdout = orig
+ stderr = sys.stderr.getvalue()
+ sys.stderr.close()
+ sys.stderr = orig_stderr
+ return (stdout, stderr)
+
+ def test_bond_noop_output(self):
+ bond_yaml = os.path.join(SAMPLE_BASE, 'bond.yaml')
+ bond_json = os.path.join(SAMPLE_BASE, 'bond.json')
+ stdout_yaml, stderr = self.run_cli('ARG0 -d --noop -c %s' % bond_yaml)
+ stdout_json, stderr = self.run_cli('ARG0 -d --noop -c %s' % bond_json)
+ self.assertEqual(stdout_yaml, stdout_json)
+
+ def test_bridge_noop_output(self):
+ bridge_yaml = os.path.join(SAMPLE_BASE, 'bridge_dhcp.yaml')
+ bridge_json = os.path.join(SAMPLE_BASE, 'bridge_dhcp.json')
+ stdout_yaml, stderr = self.run_cli('ARG0 -d --noop -c %s' %
+ bridge_yaml)
+ stdout_json, stderr = self.run_cli('ARG0 -d --noop -c %s' %
+ bridge_json)
+ self.assertEqual(stdout_yaml, stdout_json)
+
+ def test_vlan_noop_output(self):
+ vlan_yaml = os.path.join(SAMPLE_BASE, 'bridge_vlan.yaml')
+ vlan_json = os.path.join(SAMPLE_BASE, 'bridge_vlan.json')
+ stdout_yaml, stderr = self.run_cli('ARG0 -d --noop -c %s' % vlan_yaml)
+ stdout_json, stderr = self.run_cli('ARG0 -d --noop -c %s' % vlan_json)
+ self.assertEqual(stdout_yaml, stdout_json)