Skip to content

Commit

Permalink
Add Dell Enterprise SONiC 'image_management' module (#311)
Browse files Browse the repository at this point in the history
* Add Dell Enterprise SONiC 'image_management' module

* Add warning for ignored options
  • Loading branch information
ArunSaravananBalachandran authored Feb 26, 2024
1 parent 5d76569 commit 7f53777
Show file tree
Hide file tree
Showing 25 changed files with 1,580 additions and 0 deletions.
434 changes: 434 additions & 0 deletions plugins/modules/sonic_image_management.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
ansible_connection: httpapi
module_name: image_management
5 changes: 5 additions & 0 deletions tests/regression/roles/sonic_image_management/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
collections:
- dellemc.enterprise_sonic
dependencies:
- { role: common }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Test case - firmware cancel
dellemc.enterprise_sonic.sonic_image_management:
firmware:
command: 'cancel'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.status is defined
- result.status == 'SUCCESS'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'firmware_cancel'
test_case_input:
firmware:
command: 'cancel'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - firmware get-result
dellemc.enterprise_sonic.sonic_image_management:
firmware:
command: 'get-list'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'firmware_get_list'
test_case_input:
firmware:
command: 'get-list'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - firmware get-status
dellemc.enterprise_sonic.sonic_image_management:
firmware:
command: 'get-status'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'firmware_get_status'
test_case_input:
firmware:
command: 'get-status'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Test case - firmware install
dellemc.enterprise_sonic.sonic_image_management:
firmware:
command: 'install'
path: 'file://tmp/test.bin'
register: result
ignore_errors: yes

- ansible.builtin.set_fact:
result_msg: "{{ result.msg | from_yaml }}"
when: result.msg is defined

- ansible.builtin.assert:
that:
- result.failed == true
- result.msg is defined
- result_msg['code'] == 400
- result_msg['ietf-restconf:errors']['error'][0]['error-type'] == 'application'
- result_msg['ietf-restconf:errors']['error'][0]['error-tag'] == 'invalid-value'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'firmware_install'
test_case_input:
firmware:
command: 'install'
path: 'file://tmp/test.bin'
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Test case - image cancel
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'cancel'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.status is defined
- result.status == 'SUCCESS'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_cancel'
test_case_input:
image:
command: 'cancel'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Test case - image get-list
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'get-list'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
- result.info.available is defined
- result.info.current is defined and result.info.current in result.info.available
- result.info.next is defined and result.info.next in result.info.available
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_get_list'
test_case_input:
image:
command: 'get-list'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - image get-status
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'get-status'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_get_status'
test_case_input:
image:
command: 'get-status'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Test case - image install
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'install'
path: 'file://tmp/test.bin'
register: result
ignore_errors: yes

- ansible.builtin.set_fact:
result_msg: "{{ result.msg | from_yaml }}"
when: result.msg is defined

- ansible.builtin.assert:
that:
- result.failed == true
- result.msg is defined
- result_msg['code'] == 400
- result_msg['ietf-restconf:errors']['error'][0]['error-type'] == 'application'
- result_msg['ietf-restconf:errors']['error'][0]['error-tag'] == 'invalid-value'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_install'
test_case_input:
image:
command: 'install'
path: 'file://tmp/test.bin'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- ansible.builtin.set_fact:
ansible_facts:
test_reports: "{{ ansible_facts['test_reports'] | default({}) | combine({module_name: {test_case_name: {
'status': 'Passed' if (assert_result.failed == false) else 'Failed',
'module_stderr': result.module_stderr | default(result.msg | default('No Error')),
'configs': test_case_input | default('Not defined'),
'result_info': result.info | default('N/A'),
'result_status': result.status | default('N/A'),
}}}, recursive=True) }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Test case - image remove - current image
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'remove'
name: '{{ current_image_name }}'
register: result
ignore_errors: yes

- ansible.builtin.set_fact:
result_msg: "{{ result.msg | from_yaml }}"
when: result.msg is defined

- ansible.builtin.assert:
that:
- result.failed == true
- result.msg is defined
- result_msg['code'] == 400
- result_msg['ietf-restconf:errors']['error'][0]['error-type'] == 'application'
- result_msg['ietf-restconf:errors']['error'][0]['error-tag'] == 'invalid-value'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_remove'
test_case_input:
image:
command: 'remove'
name: '{{ current_image_name }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Test case - image set-default - current image
dellemc.enterprise_sonic.sonic_image_management:
image:
command: 'set-default'
name: '{{ current_image_name }}'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.status is defined
- result.status == 'SUCCESS'
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'image_set_default'
test_case_input:
image:
command: 'set-default'
name: '{{ current_image_name }}'
28 changes: 28 additions & 0 deletions tests/regression/roles/sonic_image_management/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- ansible.builtin.debug:
msg: "sonic_image_management Test started ..."

- name: Preparations for image_management
ansible.builtin.include_tasks: preparation_tests.yml

- ansible.builtin.include_tasks: image_install.yml
- ansible.builtin.include_tasks: image_cancel.yml
- ansible.builtin.include_tasks: image_remove.yml
- ansible.builtin.include_tasks: image_set_default.yml
- ansible.builtin.include_tasks: image_get_list.yml
- ansible.builtin.include_tasks: image_get_status.yml

- ansible.builtin.include_tasks: patch_install.yml
- ansible.builtin.include_tasks: patch_rollback.yml
- ansible.builtin.include_tasks: patch_get_history.yml
- ansible.builtin.include_tasks: patch_get_list.yml
- ansible.builtin.include_tasks: patch_get_status.yml

- ansible.builtin.include_tasks: firmware_install.yml
- ansible.builtin.include_tasks: firmware_cancel.yml
- ansible.builtin.include_tasks: firmware_get_list.yml
- ansible.builtin.include_tasks: firmware_get_status.yml

- name: Display all variables/facts known for a host
ansible.builtin.debug:
var: hostvars[inventory_hostname].ansible_facts.test_reports
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - patch get-history
dellemc.enterprise_sonic.sonic_image_management:
patch:
command: 'get-history'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'patch_get_history'
test_case_input:
patch:
command: 'get-history'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - patch get-list
dellemc.enterprise_sonic.sonic_image_management:
patch:
command: 'get-list'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'patch_get_list'
test_case_input:
patch:
command: 'get-list'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Test case - patch get-status
dellemc.enterprise_sonic.sonic_image_management:
patch:
command: 'get-status'
register: result
ignore_errors: yes

- ansible.builtin.assert:
that:
- result.failed == false
- result.info is defined
register: assert_result
ignore_errors: yes

- ansible.builtin.include_tasks: image_management.test.facts.report.yml
vars:
test_case_name: 'patch_get_status'
test_case_input:
patch:
command: 'get-status'
Loading

0 comments on commit 7f53777

Please sign in to comment.