From afed9e751c9eb70ea696436e07a535fc7c15783d Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Thu, 22 Jan 2015 12:17:44 +0000 Subject: Refactor noop to enable logging of disabled operations Currently we only output the config file contents in noop mode, but it's very useful to see what would be done in terms of taking interfaces up and down, and especially what will be removed when --cleanup mode is specified So this refactors the operations skipped by noop into the base-class so we can conveniently log what they would do when --noop is selected. Change-Id: Ia9cfa9a05b2df02c165a2ff992765ab63e55ae6b --- os_net_config/impl_ifcfg.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'os_net_config/impl_ifcfg.py') diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index 0c23630..56a0e47 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -16,16 +16,12 @@ import glob import logging -import os import os_net_config from os_net_config import objects from os_net_config import utils -from oslo_concurrency import processutils - - logger = logging.getLogger(__name__) @@ -258,40 +254,33 @@ class IfcfgNetConfig(os_net_config.NetConfig): update_files[bridge_route_path] = route_data logger.info('No changes required for bridge: %s' % bridge_name) - if self.noop: - return update_files - if cleanup: for ifcfg_file in glob.iglob(cleanup_pattern()): if ifcfg_file not in all_file_names: 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) + msg = 'cleaning up interface: %s' % interface_name + self.execute(msg, '/sbin/ifdown', interface_name, + check_exit_code=False) + self.remove_config(ifcfg_file) for interface in restart_interfaces: - logger.info('running ifdown on interface: %s' % interface) - processutils.execute('/sbin/ifdown', interface, - check_exit_code=False) + msg = 'running ifdown on interface: %s' % interface + self.execute(msg, '/sbin/ifdown', interface, check_exit_code=False) for bridge in restart_bridges: - logger.info('running ifdown on bridge: %s' % bridge) - processutils.execute('/sbin/ifdown', bridge, - check_exit_code=False) + msg = 'running ifdown on bridge: %s' % bridge + self.execute(msg, '/sbin/ifdown', bridge, check_exit_code=False) for location, data in update_files.iteritems(): - logger.info('writing config file: %s' % location) - utils.write_config(location, data) + self.write_config(location, data) for bridge in restart_bridges: - logger.info('running ifup on bridge: %s' % bridge) - processutils.execute('/sbin/ifup', bridge) + msg = 'running ifup on bridge: %s' % bridge + self.execute(msg, '/sbin/ifup', bridge) for interface in restart_interfaces: - logger.info('running ifup on interface: %s' % interface) - processutils.execute('/sbin/ifup', interface) + msg = 'running ifup on interface: %s' % interface + self.execute(msg, '/sbin/ifup', interface) return update_files -- cgit 1.2.3-korg