Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 2 additions & 43 deletions ansible/roles/test/tasks/advanced-reboot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,49 +113,8 @@
stay_in_target_image: "{{ stay_in_target_image | default('false') | bool }}"
cleanup_old_sonic_images: "{{ cleanup_old_sonic_images | default('false') | bool }}"

- block:

- name: Save image version
shell: 'sonic_installer list | grep Current | cut -f2 -d " "'
register: current_sonic_image
become: true
when: not stay_in_target_image

- name: Generate temp file name on target device
shell: mktemp
register: tempfile

- set_fact:
new_image_location: '{{ tempfile.stdout }}'

- debug: msg='Setting image file name to {{ new_image_location }}'

- name: Download SONiC image.
local_action: get_url url={{ new_sonic_image }} dest={{ new_image_location }}

- name: Upload SONiC image to device.
copy:
src: "{{ new_image_location }}"
dest: "{{ new_image_location }}"

- name: Cleanup sonic images that is not current and/or next
shell: sonic_installer cleanup -y
become: true
when: cleanup_old_sonic_images

- name: 'Setup restoring initial image {{ current_sonic_image }}'
shell: /bin/true
connection: local
notify:
- restore current image
- reboot sonic
when: not stay_in_target_image

- name: Installing new SONiC image
shell: sonic_installer install -y {{ new_image_location }}
become: true

when: new_sonic_image | default('') | length > 0
- include: advanced_reboot/reboot-image-handle.yml
when: new_sonic_image is defined

- include: ptf_runner.yml
vars:
Expand Down
49 changes: 49 additions & 0 deletions ansible/roles/test/tasks/advanced_reboot/reboot-image-handle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- block:
- fail: msg="Please set new_sonic_image variable"
when: new_sonic_image is not defined

- fail: msg="Please set cleanup_old_sonic_images variable"
when: cleanup_old_sonic_images is not defined

- fail: msg="Please set stay_in_target_image variable"
when: stay_in_target_image is not defined

- name: Save image version
shell: 'sonic_installer list | grep Current | cut -f2 -d " "'
register: current_sonic_image
become: true
when: not stay_in_target_image

- name: Generate temp file name on target device
shell: mktemp
register: tempfile

- set_fact:
new_image_location: '{{ tempfile.stdout }}'

- debug: msg='Setting image file name to {{ new_image_location }}'

- name: Download SONiC image.
local_action: get_url url={{ new_sonic_image }} dest={{ new_image_location }}

- name: Upload SONiC image to device.
copy:
src: "{{ new_image_location }}"
dest: "{{ new_image_location }}"

- name: Cleanup sonic images that is not current and/or next
shell: sonic_installer cleanup -y
become: true
when: cleanup_old_sonic_images

- name: 'Setup restoring initial image {{ current_sonic_image }}'
shell: /bin/true
connection: local
notify:
- restore current image
- reboot sonic
when: not stay_in_target_image

- name: Installing new SONiC image
shell: sonic_installer install -y {{ new_image_location }}
become: true