Debian: apply network config with correct dependency

It was detected that on a system with 2 or more labeled interfaces
(those are ifupdown representation of "interfaces" that will only
configure the IP address on a base interface, e.g. interface vlan160
may have labeled interfaces vlan160:1 and vlan160:5) the order of
execution was preventing them to be applied because the execution
was happening before the base interface.

The execution was decided by the result of the find command, this
change applies a sort on the list to be sure that the execution is
respecting the base interface first, e.g:
i)  enp0s8 => enp0s8:1 => enp0s8.100 => enp0s8.100:1 => enp0s8.100:5
ii) vlan160 => vlan160:1 => vlan160:5

Also:
1) added a log message in case of ifup or ifdown failure
2) prevent the processing of labeled interfaces in
   verify_all_vlans_created()

Test Plan (Debian and CentOS):
PASS add interfaces and lock/unlock the controller
PASS edit interfaces and lock/unlock the controller
PASS remove interfaces and lock/unlock the controller

Closes-Bug: 1987918

Signed-off-by: Andre Fernando Zanella Kantek <AndreFernandoZanella.Kantek@windriver.com>
Change-Id: I7bc8d2bb25a74a5900b46936b59fc83b9251b53b
This commit is contained in:
Andre Fernando Zanella Kantek 2022-08-26 17:48:22 -03:00
parent d72a34ec9f
commit 4f44c7eb9c
2 changed files with 19 additions and 10 deletions

View File

@ -142,7 +142,12 @@ function update_interfaces {
# the network service.
verify_all_vlans_created
for cfg_path in $(find ${PUPPET_DIR} -name "${IFNAME_INCLUDE}"); do
# handle interfaces as a sorted list, this will guarantee that base
# interfaces are processed first
# e.g.
# enp0s8 => enp0s8:1 => enp0s8.100 => enp0s8.100:1 => enp0s8.100:5
# vlan160 => vlan160:1 => vlan160:5
for cfg_path in $(find ${PUPPET_DIR} -name "${IFNAME_INCLUDE}" | sort); do
cfg=$(basename ${cfg_path})
if is_vlan ${ETC_DIR}/${cfg}; then

View File

@ -38,7 +38,7 @@ function do_if_up {
iface=$( grep iface ${search_file} )
if_name=$( echo "${iface}" | awk '{print $2}' )
log_it "Bringing ${if_name} up"
/sbin/ifup ${if_name}
/sbin/ifup ${if_name} || log_it "Failed bringing ${if_name} up"
}
#
@ -63,7 +63,7 @@ function do_if_down {
iface=$( grep iface ${search_file} )
if_name=$( echo "${iface}" | awk '{print $2}' )
log_it "Bringing ${if_name} down"
/sbin/ifdown ${if_name}
/sbin/ifdown ${if_name} || log_it "Failed bringing ${if_name} down"
}
#
@ -151,14 +151,18 @@ function is_vlan_device_present_on_kernel {
function verify_all_vlans_created {
for cfg_path in $(find ${ETC_DIR} -name "${IFNAME_INCLUDE}"); do
cfg=$(basename ${cfg_path})
if is_vlan ${ETC_DIR}/${cfg}; then
is_vlan_device_present_on_kernel ${cfg_path}
if [ $? -ne 0 ] ; then
log_it "${cfg} - not present on the kernel, bring up before proceeding"
do_if_up ${cfg_path}
is_vlan_device_present_on_kernel ${ETC_DIR}/${cfg}
# do not process labeled interfaces
if [[ $cfg != *":"* ]]; then
log_it "verify_all_vlans_created process $cfg"
if is_vlan ${ETC_DIR}/${cfg}; then
is_vlan_device_present_on_kernel ${cfg_path}
if [ $? -ne 0 ] ; then
log_it "${cfg} - failed to add VLAN interface on kernel"
log_it "${cfg} - not present on the kernel, bring up before proceeding"
do_if_up ${cfg_path}
is_vlan_device_present_on_kernel ${ETC_DIR}/${cfg}
if [ $? -ne 0 ] ; then
log_it "${cfg} - failed to add VLAN interface on kernel"
fi
fi
fi
fi