Fix calico bring-up failure in optimized restore

On certain system, the networking service can be restarted.
On systems were it is possible it should be restored that way.
Otherwise, fallback to the original method of restoring
networking by using ifup/ifdown manually.

It was seen that if restarting networking service is possible
but is not done,  Calico cni will fail to be created when Kubernetes
is brought up later in the playbook.

This only impacts certain systems.

TEST PLAN
PASS: Run optimized restore with --registry-images (AIO-SX)
  * Run on affected and unaffected systems
PASS: Run optimized restore without --registry-images (AIO-SX)
  * Run on affected and unaffected systems

Closes-Bug: 2000184
Signed-off-by: Joshua Kraitberg <joshua.kraitberg@windriver.com>
Change-Id: I97b9fc2bbbe47ed93edbdae3f4b02b6243181677
This commit is contained in:
Joshua Kraitberg
2022-12-20 20:26:07 -05:00
parent b202752c4d
commit 24c75495b3

View File

@@ -21,39 +21,54 @@
- name: Restore network configuration files
command: "tar -C / -xpf {{ platform_backup_fqpn }} --overwrite {{ network_scripts_location.lstrip('/') }}"
- name: Get IPv4 default gateways
shell: >
ip -4 route show default
| grep -oE 'dev [0-9a-z]+'
| awk '{print "--exclude=" $2}'
register: ipv4_route
# Ideally, networking is restored by restarting networking service.
# But, this is not guaranteed to work on all systems depending on configuration.
- name: Restore original networking using service
systemd:
name: networking
state: restarted
register: networking
failed_when: false
# There can be multiple default routes
- name: Get IPv6 default gateways
shell: >
ip -6 route show default
| grep -oE 'dev [0-9a-z]+'
| awk '{print "--exclude=" $2}'
register: ipv6_route
# If networking service could not be restarted do it this way instead.
# This restarts networking in a way that ignores failures that would have
# occurred while attempting to restart the service.
- block:
- name: Get IPv4 default gateways
shell: >
ip -4 route show default
| grep -oE 'dev [0-9a-z]+'
| awk '{print "--exclude=" $2}'
register: ipv4_route
- name: Extract gateway interfaces
set_fact:
interfaces: "{{
ipv4_route.stdout_lines + ipv6_route.stdout_lines
| map('trim') | reject('equalto', '')
| unique | list
}}"
# There can be multiple default routes
- name: Get IPv6 default gateways
shell: >
ip -6 route show default
| grep -oE 'dev [0-9a-z]+'
| awk '{print "--exclude=" $2}'
register: ipv6_route
# Ignore errors is used here to avoid any issues
# with networking interfaces that could not be produced
# during regular usage and testing.
# Interfaces will be brought up normally after unlocking.
- name: Bring up original networking
shell:
cmd: |
ifdown -a --exclude=lo {{ ' '.join(interfaces) }}
ifup $(ls ifcfg-* | sed 's/ifcfg-//') --ignore-errors
chdir: /etc/network/interfaces.d/
- name: Extract gateway interfaces
set_fact:
interfaces: "{{
ipv4_route.stdout_lines + ipv6_route.stdout_lines
| map('trim') | reject('equalto', '')
| unique | list
}}"
# Ignore errors is used here to avoid any issues
# with networking interfaces that could not be produced
# during regular usage and testing.
# Interfaces will be brought up normally after unlocking.
- name: Bring up original networking
shell:
cmd: |
ifdown -a --exclude=lo {{ ' '.join(interfaces) }}
ifup $(ls ifcfg-* | sed 's/ifcfg-//') --ignore-errors
chdir: /etc/network/interfaces.d/
when: not networking.changed
- name: Bring up temporary addresses
block: