Skip to content

Commit 8f3ba91

Browse files
authored
[fast/warm reboot] improve new image installation code (#877)
* [fast/warm reboot] improve new image installation code - Allow new_sonic_image being defined as empty string. It causes skipping image installation. - Rename new_image_location to a generic name. - Display defined new image url. Signed-off-by: Ying Xie <[email protected]> * [fast/warm reboot] allow DUT to stay in the warm/fast reboot target release This feature is needed in order to test ugprade path. Where we might upgrade from one version to another, and more. We want the system to stay in target release for next steps. Signed-off-by: Ying Xie <[email protected]> * Address review comments, test issues and some minor touch-ups Signed-off-by: Ying Xie <[email protected]> * [fast/warm reboot] add knob to clean up old iamges on DUT before warm/fast reboot When new image is specified for fast/warm reboot. The new image will be installed. However, if the specified image is already installed on the target DUT, then sonic_install will fail and fast/warm reboot will reboot into current image. Add a knob to cleanup old images so that the installing of new image will have a better chance to succeed. Signed-off-by: Ying Xie <[email protected]> * address review issue
1 parent 19bc309 commit 8f3ba91

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

ansible/roles/test/tasks/advanced-reboot.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,29 @@
106106
dest: /tmp/ports.json
107107
delegate_to: "{{ ptf_host }}"
108108

109+
- debug: msg="Defined new sonic image url is {{ new_sonic_image }}"
110+
when: new_sonic_image is defined
111+
112+
- set_fact:
113+
stay_in_target_image: "{{ stay_in_target_image | default('false') | bool }}"
114+
cleanup_old_sonic_images: "{{ cleanup_old_sonic_images | default('false') | bool }}"
115+
109116
- block:
110117

111118
- name: Save image version
112119
shell: 'sonic_installer list | grep Current | cut -f2 -d " "'
113120
register: current_sonic_image
114121
become: true
122+
when: not stay_in_target_image
123+
124+
- name: Generate temp file name on target device
125+
shell: mktemp
126+
register: tempfile
115127

116128
- set_fact:
117-
new_image_location: '/tmp/new_sonic_image.bin'
129+
new_image_location: '{{ tempfile.stdout }}'
130+
131+
- debug: msg='Setting image file name to {{ new_image_location }}'
118132

119133
- name: Download SONiC image.
120134
local_action: get_url url={{ new_sonic_image }} dest={{ new_image_location }}
@@ -124,14 +138,24 @@
124138
src: "{{ new_image_location }}"
125139
dest: "{{ new_image_location }}"
126140

127-
- name: Install a new SONiC image if requested
128-
shell: sonic_installer install -y {{ new_image_location }}
141+
- name: Cleanup sonic images that is not current and/or next
142+
shell: sonic_installer cleanup -y
129143
become: true
144+
when: cleanup_old_sonic_images
145+
146+
- name: 'Setup restoring initial image {{ current_sonic_image }}'
147+
shell: /bin/true
148+
connection: local
130149
notify:
131-
- restore current image
132-
- reboot sonic
150+
- restore current image
151+
- reboot sonic
152+
when: not stay_in_target_image
133153

134-
when: new_sonic_image is defined
154+
- name: Installing new SONiC image
155+
shell: sonic_installer install -y {{ new_image_location }}
156+
become: true
157+
158+
when: new_sonic_image | default('') | length > 0
135159

136160
- include: ptf_runner.yml
137161
vars:

0 commit comments

Comments
 (0)