diff options
author | 2015-01-21 17:24:08 +0000 | |
---|---|---|
committer | 2015-02-24 09:20:41 +0000 | |
commit | a4ad189558a414c6029b4dfbc8e459339ebe534d (patch) | |
tree | 0c39889bc89c461803f03b4cb9ae89e8bd4c0033 /os_net_config/tests | |
parent | 6945fe5afdc12574fe00ad440319b7873f818e84 (diff) |
Add a persist_mapping option to the mapping file
This adds the option to permanently rewrite the configuration so the
aliases are used instead of the system name. This is useful where
you have a variety of hardware and you want to have consistent device
naming accross all platforms - this allows you to essentially rename
the interfaces permanently so they match the abstracted nicN names.
Note, this needs to be run with --cleanup or the old (now conflicting)
configs will still be in place, and it may require a reboot before
the changes are fully applied.
Change-Id: I5af146e764b72c4beaa41c549fabff0af8802152
Diffstat (limited to 'os_net_config/tests')
-rw-r--r-- | os_net_config/tests/base.py | 3 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/os_net_config/tests/base.py b/os_net_config/tests/base.py index 30f9d97..d5adc66 100644 --- a/os_net_config/tests/base.py +++ b/os_net_config/tests/base.py @@ -36,9 +36,10 @@ class TestCase(testtools.TestCase): super(TestCase, self).setUp() self.stubs = stubout.StubOutForTesting() + self.stubbed_numbered_nics = {} def dummy_numbered_nics(nic_mapping=None): - return {} + return self.stubbed_numbered_nics if self.stub_numbered_nics: self.stubs.Set(objects, '_numbered_nics', dummy_numbered_nics) diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index c1026d9..46371db 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -36,6 +36,8 @@ IPADDR=192.168.1.2 NETMASK=255.255.255.0 """ +_V4_IFCFG_MAPPED = _V4_IFCFG.replace('em1', 'nic1') + "HWADDR=a1:b2:c3:d4:e5\n" + _V6_IFCFG = _BASE_IFCFG + """IPV6INIT=yes IPV6_AUTOCONF=no IPV6ADDR=2001:abc:a:: @@ -141,6 +143,23 @@ class TestIfcfgNetConfig(base.TestCase): self.assertEqual(_V4_IFCFG, self.get_interface_config()) self.assertEqual('', self.get_route_config()) + def test_add_interface_map_persisted(self): + def test_interface_mac(name): + macs = {'em1': 'a1:b2:c3:d4:e5'} + return macs[name] + self.stubs.Set(utils, 'interface_mac', test_interface_mac) + + nic_mapping = {'nic1': 'em1'} + self.stubbed_numbered_nics = nic_mapping + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('nic1', addresses=[v4_addr], + nic_mapping=nic_mapping, + persist_mapping=True) + self.assertEqual('a1:b2:c3:d4:e5', interface.hwaddr) + self.provider.add_interface(interface) + self.assertEqual(_V4_IFCFG_MAPPED, self.get_interface_config('nic1')) + self.assertEqual('', self.get_route_config('nic1')) + def test_add_interface_with_v6(self): v6_addr = objects.Address('2001:abc:a::/64') interface = objects.Interface('em1', addresses=[v6_addr]) |