Refuse to replace pre-existing interface configs.

We now ignore network interfaces which already have a configuration file
on disk.

Change-Id: I8d7c91a40be92c82d947577dc6155c54756426c9
This commit is contained in:
Chris Jones 2015-07-17 11:28:20 +00:00
parent 913803bae6
commit cc401d456b
15 changed files with 58 additions and 3 deletions

View File

@ -27,6 +27,13 @@ post_up = " post-up route add -net {net} netmask {mask} gw {gw} || true\n"
pre_down = " pre-down route del -net {net} netmask {mask} gw {gw} || true\n"
def _exists_rh_interface(name):
file_to_check = '/etc/sysconfig/network-scripts/ifcfg-{name}'.format(
name=name
)
return os.path.exists(file_to_check)
def _write_rh_interface(name, interface):
files_to_write = dict()
results = """# Automatically generated, do not edit
@ -95,7 +102,9 @@ def write_redhat_interfaces(interfaces, sys_interfaces):
_write_rh_interface(interface_name, interface))
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
# TODO(mordred) We only want to do this if a file doesn't already exist
if _exists_rh_interface(iname):
# This interface already has a config file, move on
continue
if mac in interfaces:
# We have a config drive config, move on
continue
@ -103,6 +112,11 @@ def write_redhat_interfaces(interfaces, sys_interfaces):
return files_to_write
def _exists_debian_interface(name):
file_to_check = '/etc/network/interfaces.d/{name}'.format(name=name)
return os.path.exists(file_to_check)
def write_debian_interfaces(interfaces, sys_interfaces):
eni_path = '/etc/network/interfaces'
eni_d_path = eni_path + '.d'
@ -138,8 +152,9 @@ def write_debian_interfaces(interfaces, sys_interfaces):
files_to_write[iface_path] = result
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
# TODO(mordred) We only want to do this if the interface doesn't
# already exist
if _exists_debian_interface(iname):
# This interface already has a config file, move on
continue
if mac in interfaces:
# We have a config drive config, move on
continue

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:05:7b:12

View File

@ -0,0 +1 @@
1

View File

@ -44,6 +44,21 @@
],
"ip_address": "10.208.169.118",
"id": "network1"
},
{
"network_id": "22222222-2222-2222-2222-222222222222",
"type": "ipv4",
"netmask": "255.255.255.0",
"link": "tap234ab34c-f1",
"routes": [
{
"netmask": "0.0.0.0",
"network": "0.0.0.0",
"gateway": "192.0.2.1"
}
],
"ip_address": "192.0.2.2",
"id": "network2"
}
],
"links": [
@ -60,6 +75,13 @@
"type": null,
"id": "tape501e1cd-10",
"vif_id": "e501e1cd-10d0-4e63-b0c2-6542989ccbb2"
},
{
"ethernet_mac_address": "BC:76:4E:05:7B:12",
"mtu": 1500,
"type": null,
"id": "tap234ab34c-f1",
"vif_id": "acdb875a-87da-76cb-984c-acd9a75dbca7"
}
]
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:05:7b:12

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:05:7b:12

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
bc:76:4e:05:7b:12

View File

@ -0,0 +1 @@
1

View File

@ -105,6 +105,11 @@ class TestGlean(base.BaseTestCase):
path = os.path.join(
sample_data_path, sample_prefix,
path[1:])
if path in ['/etc/sysconfig/network-scripts/ifcfg-eth2',
'/etc/network/interfaces.d/eth2']:
# Pretend this file exists, we need to test skipping
# pre-existing config files
return True
return real_path_exists(path)
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
@ -147,6 +152,7 @@ class TestGlean(base.BaseTestCase):
write_blocks.append((write_dest, write_content))
for dest, content in write_blocks:
self.assertNotIn("eth2", dest)
self.assertIn(dest, self.file_handle_mocks)
write_handle = self.file_handle_mocks[dest].write
write_handle.assert_called_once_with(content)