diff options
author | Dan Prince <dprince@redhat.com> | 2014-08-15 09:53:58 -0400 |
---|---|---|
committer | Dan Prince <dprince@redhat.com> | 2014-08-15 09:53:58 -0400 |
commit | 2d3af95651223ca142e99c9c2bbe284481e3f33d (patch) | |
tree | 61cadb5f6c8263d7c4a09ad120947bde76a0be4a /os_net_config | |
parent | 79c82ffcf8aee74a607ea269ef6baa67c85369d6 (diff) |
ifcfg: Exclude ifcfg-lo from cleanup
This interface should always exist... we don't want to clean
it up.
Diffstat (limited to 'os_net_config')
-rw-r--r-- | os_net_config/impl_ifcfg.py | 12 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 14 |
2 files changed, 20 insertions, 6 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index aa69cb4..f603054 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -238,11 +238,13 @@ class IfcfgNetConfig(os_net_config.NetConfig): if cleanup: for ifcfg_file in glob.iglob(cleanup_pattern()): if ifcfg_file not in all_file_names: - interface_name = ifcfg_file[37:] - logger.info('cleaning up interface: %s' % interface_name) - processutils.execute('/sbin/ifdown', interface_name, - check_exit_code=False) - os.remove(ifcfg_file) + interface_name = ifcfg_file[len(cleanup_pattern()) - 1:] + if interface_name != 'lo': + logger.info('cleaning up interface: %s' % + interface_name) + processutils.execute('/sbin/ifdown', interface_name, + check_exit_code=False) + os.remove(ifcfg_file) for interface in restart_interfaces: logger.info('running ifdown on interface: %s' % interface) diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index a5c621c..9038987 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -221,7 +221,7 @@ class TestIfcfgNetConfigApply(base.TestCase): self.temp_ifcfg_file = tempfile.NamedTemporaryFile() self.temp_route_file = tempfile.NamedTemporaryFile() self.temp_bridge_file = tempfile.NamedTemporaryFile() - self.temp_cleanup_file = tempfile.NamedTemporaryFile() + self.temp_cleanup_file = tempfile.NamedTemporaryFile(delete=False) def test_ifcfg_path(name): return self.temp_ifcfg_file.name @@ -294,3 +294,15 @@ class TestIfcfgNetConfigApply(base.TestCase): def test_cleanup(self): self.provider.apply(cleanup=True) self.assertTrue(not os.path.exists(self.temp_cleanup_file.name)) + + def test_cleanup_not_loopback(self): + tmp_lo_file = '%s-lo' % self.temp_cleanup_file.name + utils.write_config(tmp_lo_file, 'foo') + + def test_cleanup_pattern(): + return '%s-*' % self.temp_cleanup_file.name + self.stubs.Set(impl_ifcfg, 'cleanup_pattern', test_cleanup_pattern) + + self.provider.apply(cleanup=True) + self.assertTrue(os.path.exists(tmp_lo_file)) + os.remove(tmp_lo_file) |