From a6c3f2a2c853ca489cceff959a52d7f75bf4ffe0 Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Wed, 18 Oct 2017 16:17:42 -0400 Subject: Avoid overwriting VPP startup script Currently we overwrite the entire VPP startup script if the content changes, this can cause content from other sources to be lost. This patch appends startup CLIs lines to startup script. Change-Id: Ifa3b18aa6370c79ad6ad3ce983f1648ff0d1d79d Signed-off-by: Feng Pan (cherry picked from commit 91096196953f9619ab8435713a39f795a473f876) --- os_net_config/utils.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/os_net_config/utils.py b/os_net_config/utils.py index 95f17c6..f60a89d 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -479,7 +479,7 @@ def update_vpp_mapping(vpp_interfaces): :param vpp_interfaces: List of VPP interface objects """ - vpp_start_cli = "" + cli_list = [] for vpp_int in vpp_interfaces: if not vpp_int.pci_dev: @@ -505,10 +505,11 @@ def update_vpp_mapping(vpp_interfaces): % (vpp_int.name, vpp_int.pci_dev)) # Generate content of startup script for VPP + cli_list.append('set interface state %s up' % vpp_name) for address in vpp_int.addresses: - vpp_start_cli += 'set interface state %s up\n' % vpp_name - vpp_start_cli += 'set interface ip address %s %s/%s\n' \ - % (vpp_name, address.ip, address.prefixlen) + cli_list.append('set interface ip address %s %s/%s\n' + % (vpp_name, address.ip, + address.prefixlen)) logger.info('Updating mapping for vpp interface %s:' 'pci_dev: %s mac address: %s uio driver: %s' @@ -518,10 +519,16 @@ def update_vpp_mapping(vpp_interfaces): vpp_int.uio_driver) write_hiera(HIERADATA_FILE, {vpp_int.name: vpp_name}) - # Enable VPP service to make the VPP interface configuration - # persistent. - processutils.execute('systemctl', 'enable', 'vpp') + vpp_start_cli = get_file_data(_VPP_EXEC_FILE) + for cli_line in cli_list: + if not re.search(r'^\s*%s\s*$' % cli_line, + vpp_start_cli, re.MULTILINE): + vpp_start_cli += cli_line + '\n' if diff(_VPP_EXEC_FILE, vpp_start_cli): write_config(_VPP_EXEC_FILE, vpp_start_cli) restart_vpp(vpp_interfaces) + + # Enable VPP service to make the VPP interface configuration + # persistent. + processutils.execute('systemctl', 'enable', 'vpp') -- cgit 1.2.3-korg