aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/tests
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config/tests')
-rw-r--r--os_net_config/tests/test_cli.py25
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py37
-rw-r--r--os_net_config/tests/test_objects.py11
3 files changed, 73 insertions, 0 deletions
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,))
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 73271e8..f8864c4 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -357,6 +357,34 @@ DHCLIENTARGS=--foobar
"""
self.assertEqual(em1_config, self.get_interface_config('em1'))
+ def test_interface_single_dns_server(self):
+ interface1 = objects.Interface('em1', dns_servers=['1.2.3.4'])
+ self.provider.add_interface(interface1)
+ em1_config = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+BOOTPROTO=none
+DNS1=1.2.3.4
+"""
+ self.assertEqual(em1_config, self.get_interface_config('em1'))
+
+ def test_interface_dns_servers(self):
+ interface1 = objects.Interface('em1', dns_servers=['1.2.3.4',
+ '5.6.7.8'])
+ self.provider.add_interface(interface1)
+ em1_config = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+BOOTPROTO=none
+DNS1=1.2.3.4
+DNS2=5.6.7.8
+"""
+ self.assertEqual(em1_config, self.get_interface_config('em1'))
+
class TestIfcfgNetConfigApply(base.TestCase):
@@ -515,6 +543,15 @@ class TestIfcfgNetConfigApply(base.TestCase):
self.assertIn('em1', self.ifup_interface_names)
self.assertIn('em2', self.ifup_interface_names)
+ def test_restart_interface_counts(self):
+ interface = objects.Interface('em1')
+ self.provider.add_interface(interface)
+ interface2 = objects.Interface('em2')
+ self.provider.add_interface(interface2)
+ self.provider.apply()
+ self.assertEqual(1, self.ifup_interface_names.count("em1"))
+ self.assertEqual(1, self.ifup_interface_names.count("em2"))
+
def test_vlan_apply(self):
vlan = objects.Vlan('em1', 5)
self.provider.add_vlan(vlan)
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index c824ba8..8488370 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -119,6 +119,17 @@ class TestInterface(base.TestCase):
interface1 = objects.object_from_json(json.loads(data))
self.assertEqual("--foobar", interface1.dhclient_args)
+ def test_from_json_dns_servers(self):
+ data = """{
+"type": "interface",
+"name": "em1",
+"use_dhcp": true,
+"dns_servers": ["1.2.3.4"]
+}
+"""
+ interface1 = objects.object_from_json(json.loads(data))
+ self.assertEqual(["1.2.3.4"], interface1.dns_servers)
+
def test_from_json_dhcp_nic1(self):
def dummy_numbered_nics(nic_mapping=None):
return {"nic1": "em3"}